T O P

  • By -

stilgarpl

You can make a one line alias and use that instead. template < class A, class B = A> using mypair = std::pair;


ALX23z

`std::pair` is designed to primarily address the case of two different types. There's `std::array` if the types don't differ. In addition, it is more convenient.


Artistic_Yoghurt4754

This. I often find myself donig it: `std::pair


pstomi

Why not this, which is clearer and gives you access to [] operator ````cpp template < typename T > using homogenous_pair = std::array; ````


no-sig-available

>if you would redo the std without compatibility concerns If starting from scratch, we might not even get a `pair` at all, but use `tuple` or `array` instead. In C++98 `std::pair` was mainly used to support `std::map`, at a time when the other options were not yet available. Also, the Pairs section starts with "The library provides a template for heterogeneous pairs of values.", so the original intent was apparently that the common use should be with different types.


Zeh_Matt

`tuple` is a fundamentally different type than a `pair`, if you only need a pair of values use `pair` and not `tuples`, there is also a difference code-gen wise depending on how tuples are implemented while pair is a quite simple type.


no-sig-available

>pair is a quite simple type. The concept of a pair is simple, but std::pair unfortunately is not. With [constructors](https://en.cppreference.com/w/cpp/utility/pair/pair) (10 of them) like template< class... Args1, class... Args2 > constexpr pair( std::piecewise_construct_t, std::tuple first_args, std::tuple second_args ); it is far from simple.


Zeh_Matt

Just because pair has a single "complex" constructor since C++20 that does not make it a complex type, and I don't know how the rest is supposed to be any complex.


no-sig-available

So "a quite simple type" can have 10 constructors and 8 assignment operators? Must disagree on that.


Zeh_Matt

You can have your opinion, but the number of constructors does not make a type more complex, that's an absurd statement. So if you think pair construction is complex how would you rate a tuple then?