What is std::pair?

前端 未结 10 1729
面向向阳花
面向向阳花 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 20:08

    What is std::pair for, why would I use it?

    It is just as simple two elements tuple. It was defined in first version of STL in times when compilers were not widely supporting templates and metaprogramming techniques which would be required to implement more sophisticated type of tuple like Boost.Tuple.

    It is useful in many situations. std::pair is used in standard associative containers. It can be used as a simple form of range std::pair - so one may define algorithms accepting single object representing range instead of two iterators separately. (It is a useful alternative in many situations.)

提交回复
热议问题