Why do we have std::string::npos but no std::vector::npos?
问题 I would like to use -1 to indicate a size that has not yet been computed: std::vector<std::size_t> sizes(nResults, -1); and I was wondering why isn't there a more expressive way: std::vector<std::size_t> sizes(nResults, std::vector<std::size_t>::npos); 回答1: From cppreference: std::size_t is the unsigned integer type of the result of the sizeof operator as well as the sizeof operator and the alignof operator (since C++11).... ...std::size_t can store the maximum size of a theoretically