c++ - What happens if you specify an allocator where the value_types are different? -
say declare std::vector<std::string, std::allocator<char>>
. what's worse can happen? ran , didn't seem run memory errors.
it results in undefined behavior. allocator-aware containers vector
standard specifies in table 99:
requires: allocator_type::value_type
same x::value_type
.
(note same row specifies allocator_type
must be typedef template argument of container-specialization) , acccording [res.on.functions]/2:
in particular, effects undefined in next cases: […] — types used template arguments when instantiating template component, if operations on type not implement semantics of applicable requirements subclause (17.6.3.5, 23.2, 24.2, 26.2).
c++
No comments:
Post a Comment