'/' is not equal to string :: npos, since npos is required to be negative, and none of the characters in the base execution character set can be negative. Therefore, it will look for the value 1 in the string (presumably anyway) represented by name . This is a rather unusual value for a string, so it is usually not found, which means that it will return std::string::npos , which will be converted to true .
Edit: as Johannes pointed out, although the value assigned by npos must be negative 1 (according to 21.3 / 6), which is assigned size_type, which must be unsigned, so the result will not be negative. Usually this has no real meaning: - '/' will be compared with npos using unsigned arithmetic, so the only way they could have the same value is if 1) '/' was encoded as -1 (not allowed as above) or char, has the same range as size_type.
In theory, the standard allows char to have the same range as other integral types. In fact, quite a lot of I / O depends on EOF having a value that could not have come from the file, which basically meets the requirement that char have a range that is less than int and not only less than or equal (as the standard requires )
This leaves one loophole, although this is usually quite terrible: char and short have the same range, size_type is the same as unsigned short, and int has a larger range than char / short, Providing a char and short value of the same range would not be so terrible, but limiting size_type to the same range as the short one would usually be - typically short - 16 bits, so it would limit the containers to 64K. This restriction was problematic 20 years ago under MS-DOS; it just won't be accepted in most markets today.
source share