What is std::pair?

前端 未结 10 1734
面向向阳花
面向向阳花 2020-12-12 19:07

What is std::pair for, why would I use it, and what benefits does boost::compressed_pair bring?

10条回答
  •  天命终不由人
    2020-12-12 19:57

    It's nothing but a structure with two variables under the hood.

    I actually dislike using std::pair for function returns. The reader of the code would have to know what .first is and what .second is.

    The compromise I use sometimes is to immediately create constant references to .first and .second, while naming the references clearly.

提交回复
热议问题