Is there a convenient way to wrap std::pair as a new type?

后端 未结 8 1193
梦谈多话
梦谈多话 2021-02-02 17:02

Often times I find myself using std::pair to define logical groupings of two related quantities as function arguments/return values. Some examples: row/col, tag/value, etc.

8条回答
  •  萌比男神i
    2021-02-02 17:55

    Don't use it.

    I hate std::pair exactly for this reason. You never know which is which, and since access to first and second are public you can't enforce contracts either.

    But after all, it's a matter of taste.

提交回复
热议问题