Unfortunately, this solution is not perfect, because the comparison fails if either idx has type unsigned short or the index is greater than the maximum value of int. Because of these prob- lems, the standard did not define it that way. However, because both might happen very rarely, the solution works in most situations. To write portable code, however, you should always use string::size_type for any index of your string type. For a perfect solution, you’d need some over- loaded functions that consider the exact type of string::size_type. I still hope the standard will provide a better solution in the future (although with C++11 nothing changed).