I am looking for naming conventions for typedef of lengthy collections definitions. We have some c++ code which used auto
to get away with style murder, but we need to make this code compiling on a non c++11 compiler. We are looking to establish a convention for typedef
of collections, which can become quite lengthy
For instance
typedef std::map<enum MyFirstEnum,enum MySecondEnum> map_enum2_by_enum1_t
typedef map_enum2_by_enum1_t::value_type vtype_map_enum2_by_enum1_t
typedef map_enum2_by_enum1_t::iterator map_iterator_enum2_by_enum1_t
There are so many nuances (iterator
before t
than at beginning, using type rather than t, ditching the prefix map
, etc...) that half of the time you select one nuance, half of the time you select the other.
At the end no typedef look like the other.
If there's no "big picture" name that better describes the mapping, then I'd suggest
Enum2_By_Enum1
orEnum1_To_Enum2
: both imply an associative container without themap
bit, which is a bit too Hungarian for my taste, with all the same flaws (e.g. if you move to sayunordered_map
will you change it - if you remember - or leave it being misleading?).I can't imagine this being useful... I'd typically only
typedef
a map'svalue_type
inside a template when the concrete value type is unknown (e.g. the map or value type is one of the template parameters) and the map has no special or exclusive significance such that itsvalue_type
can reasonably betypedef
ed as the template'svalue_type
, and in that scenario the map will necessarily have some other higher-level name reflecting its role in the template instantiation.In conclusion, I'd omit this if at all possible and use
enum2
/MyFirstEnum
directly.There's no reason for this unless the
typedef
identifier is significantly shorter than what it aliases. Just use<mapname>::iterator
.If you think you've got specific examples of code that's improved by having these last two typedefs, please share it.