Let's take std::pair<T1, T2>
as an example. It has the following two constructors:
constexpr pair( const T1& x, const T2& y ); // #1
template< class U1, class U2 > constexpr pair( U1&& x, U2&& y ); // #2
It seems that #2 can handle all cases that #1 can handle (without worse performance), except for cases where an argument is a list-initializer. For example,
std::pair<int, int> p({0}, {0}); // ill-formed without #1
So my question is:
If #1 is only intended for list-initializer argument, since
x
andy
finally bind to temporary objects initialized from list-initializers, why not useconstexpr pair( T1&& x, T2&& y );
instead?Otherwise, what's the actual intention of #1?
std::for_each
is a good example because functor is often cheap to copy. – Muth