Following this question , I decided to use std::size_t as size_type for each container with obvious readability considerations. I know that it is theoretically possible that std::container<T>::size_type not std::size_t , but I assume this does not apply to my current and future configurations.
However, to avoid evil bugs, I check that the types are the same when I use them. For instance:
BOOST_STATIC_ASSERT(boost::is_same< std::vector<double>::size_type , std::size_t >::value); std::vector<double> x; for(std::size_t i = 0; i < x.size(); ++i) { }
Another place in the code, I use std::vector<long int> , then also check:
BOOST_STATIC_ASSERT(boost::is_same< std::vector<long int>::size_type , std::size_t >::value);
And then, oh no! I use std::vector<std::list<std::string>*> and std::vector<std::list<double*>*> , then I check:
BOOST_STATIC_ASSERT(boost::is_same< std::vector<std::list<std::string>*>::size_type , std::size_t >::value); BOOST_STATIC_ASSERT(boost::is_same< std::vector<std::list<double*>*>::size_type , std::size_t >::value);
Well, I think you understand the problem. Ugly lines, hard to maintain code. It is a bad idea.
Then my question is: If I check std::vector<any_common_type>::size_type for std::size_t , is there any chance that std::vector<another_type>::size_type NOT std::size_t ? Is it enough to check some common types in a separate file to make sure that std::container::size_type always std::size_t in my compiler?
Note. I do not use C ++ 11 for compatibility reasons.