c++ - naming convention when typedef standard collections -


i looking naming conventions typedef of lengthy collections definitions. have c++ code used auto away style murder, need make code compiling on non c++11 compiler. looking establish convention typedef of collections, 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 many nuances (iterator before t @ beginning, using type rather t, ditching prefix map, etc...) half of time select 1 nuance, half of time select other. @ end no typedef other.

typedef std::map<enum myfirstenum,enum mysecondenum> map_enum2_by_enum1_t; 

if there's no "big picture" name better describes mapping, i'd suggest enum2_by_enum1 or enum1_to_enum2: both imply associative container without map bit, bit hungarian taste, same flaws (e.g. if move unordered_map change - if remember - or leave being misleading?).

typedef map_enum2_by_enum1_t::value_type             vtype_map_enum2_by_enum1_t; 

i can't imagine being useful... i'd typically typedef map's value_type inside template when concrete value type unknown (e.g. map or value type 1 of template parameters) , map has no special or exclusive significance such value_type can reasonably typedefed the template's value_type, , in scenario map have other higher-level name reflecting role in template instantiation.

in conclusion, i'd omit if @ possible , use enum2/myfirstenum directly.

typedef map_enum2_by_enum1_t::iterator               map_iterator_enum2_by_enum1_t; 

there's no reason unless typedef identifier shorter aliases. use <mapname>::iterator.

if think you've got specific examples of code that's improved having these last 2 typedefs, please share it.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -