What is std::pair?

前端 未结 10 1727
面向向阳花
面向向阳花 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:46

    You sometimes need to return 2 values from a function, and it's often overkill to go and create a class just for that.

    std:pair comes in handy in those cases.

    I think boost:compressed_pair is able to optimize away the members of size 0. Which is mostly useful for heavy template machinery in libraries.

    If you do control the types directly, it's irrelevant.

提交回复
热议问题