Where can I look up the definition of size_type for vectors in the C++ STL?

前端 未结 7 1270
暗喜
暗喜 2021-01-12 21:15

It seems safe to cast the result of my vector\'s size() function to an unsigned int. How can I tell for sure, though? My documentation isn\'t cle

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 21:30

    I'm not sure how well this will work because I'm just thinking off the top of my head, but a compile-time assertion (such as BOOST_STATIC_ASSERT() or see Ways to ASSERT expressions at build time in C) might help. Something like:

    BOOST_STATIC_ASSERT( sizeof( unsigned int) >= sizeof( size_type));
    

提交回复
热议问题