I use std::inner_product to count length of common prefix in 2 strings:
std::inner_product
strings
string a = "abcdef", b = "abc"; size_t r = s