c++ - Efficient way to refer to the type-name of the iterator without typing the entire container definition? -
is there more efficient way refer typename of container's iterator typing
std::unordered_map<keyclass, valueclass>::iterator
every time need iterator?
of course, there is
typedef boost::unordered_map<keyclass, valueclass>::iterator classitr
but introducing typedef's every container not strike me readable code. beingness new c++, , assuming 1 has reference container want utilize - there along lines of
container<keyclass, valueclass> x; x::iterator_type
or other obvious shortcut missing?
this 1 of reasons why c++11 introduced new meaning of auto
keyword:
auto = vec.begin();
the compiler work out type of it
initializer in similar manner template type deduction.
pre-c++11, usual approach utilize typedef
s have suggested. can useful typedef
container , give relative that:
typedef std::unordered_map<key, value> map; map m; map::iterator = m.begin();
you can give more meaningful name typedef
describes kind of map
is. example, if had map names phone numbers, phone call phone_map
, iterator phone_map::iterator
.
auto
useful tool perfect forwarding
c++ boost containers boost-iterators
No comments:
Post a Comment