c++11 - C++ when are typedefs in standard library containers not what you would expect? -



c++11 - C++ when are typedefs in standard library containers not what you would expect? -

for standard library container types typedefs within container not naively think?

in code, under conditions on type t , container container_type next static checks not evaluate true:

typedef double t; typedef std::vector<t> container_type; std::is_same<typename container_type::value_type, t>::value; std::is_same<typename container_type::reference, t&>::value; std::is_same<typename container_type::const_reference, t const&>::value; std::is_same<typename container_type::pointer, t*>::value; std::is_same<typename container_type::const_pointer, t const*>::value;

i know of std::vector<bool>::reference not bool& (and same const version thereof).

are there others?

for container containing objects of type t, standard (c++11 23.2.1/4) requires that:

container_type::value_type t container_type::reference lvalue of t, i.e. t& container_type::const_reference const lvalue of t, i.e. const t&

pointer , const_pointer not part of of container requirements, convenience typedefs in standard containers, taken container's allocator.

so, reply question:

value_type, reference , const_reference must expect, otherwise container not satisfy container requirements. notice means (as e.g. herb sutter points out), std::vector<bool> not container in standard sense.

pointer , const_pointer typedefs allocator types, when have container allocator a, differ t* , t const* whenever std::allocator_traits<a>::pointer , std::allocator_traits<a>::const_pointer differ them.

and straight address question of standard containers satisfy these container requirements:

std::array<t> does, per 23.3.2.1/3 (with exceptions don't impact typedefs in question) std::deque<t> does, per 23.3.3.1/2 std::forward_list<t> does, per 23.3.4.1/2 (with exceptions don't impact typedefs in question) std::list<t> does, per 23.3.5.1/2 std::vector<t> (for t other bool), per 23.3.6.1/2 (with exceptions don't impact typedefs in question) std::set<t> does, per 23.4.6.1/2 std::multiset<t> does, per 23.4.7.1/2 std::unrdered_set<t> does, per 23.5.6.1/2 std::unordered_multiset<t> does, per 23.5.7.1/2 std::basic_string<t> contains typedefs in question (to right types) per 21.4./5, though standard not explicitly require satisfy container requirements. note value_type depends on character traits, std::basic_string<t, mytraits> can have value_type other t.

std::[unorderd_][multi]map don't qualify because take more 1 mandatory template parameter , utilize them synthesise value_type.

std::valarray<t> not qualify because provides value_type typedef , none of others.

c++ c++11 stl

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -