(Re)named std::pair members

前端 未结 9 1769
挽巷
挽巷 2020-12-14 07:18

Instead of writing town->first I would like to write town->name. Inline named accessors (Renaming first and second of a map iterator and Name

9条回答
  •  悲&欢浪女
    2020-12-14 07:46

    I think you should really introduce new types here. I am totally on stl's side in terms of having a pair class, but this is the exact reason why java people argue they don't want to have a pair class and you should always introduce new types for your piar-like types.

    The good thing about the stl solution is that you can use the gerneric class pair, but you can introduce new types / classes whenever you really want members to be named in a different way than first/second. On top of that introducing new classes gives you the freedom of easily adding a thrid member if it should ever become necessary.

提交回复
热议问题