Udostępnij za pośrednictwem


make_pair

A template helper function used to construct objects of type pair, where the component types are based on the data types passed as parameters.

template<class Type1, class Type2>
    pair<Type1, Type2> make_pair(
      Type1& _Val1,
      Type2& -Val2
);
template<class Type1, class Type2>
    pair<Type1, Type2> make_pair(
      Type1& _Val1,
      Type2&& -Val2
); 
template<class Type1, class Type2>
    pair<Type1, Type2> make_pair(
      Type1&& _Val1,
      Type2& -Val2
); 
template<class Type1, class Type2>
    pair<Type1, Type2> make_pair(
      Type1&& _Val1,
      Type2&& -Val2
);

Parameters

  • _Val1
    Value initializing the first element of pair.

  • _Val2
    Value initializing the second element of pair.

Return Value

The pair object constructed: pair<Type1, Type2>(_Val1, _Val2).

Remarks

make_pair converts object of type reference_wrapper Class to reference types and converts decaying arrays and functions to pointers.

In the returned pair object, Type1 is determined as follows:

  • If the input type Type1 is reference_wrapper<X>, the returned type Type1 is X&.

  • Otherwise, the returned type Type1 is decay<Type1>::type. If decay Class is not supported, the returned type Type1 is the same as the input type Type1.

The returned type Type2 is similarly determined from the input type Type2.

One advantage of make_pair is that the types of objects being stored are determined automatically by the compiler and do not need to be explicitly specified by the user.

The make_pair helper function also makes it possible to pass two values to a function that requires a pair as an input parameter.

Example

See pair for an example of how to use the helper function make_pair to declare and initialize a pair.

Requirements

Header: <utility>

Namespace: std

See Also

Reference

<utility>

Lvalues and Rvalues

make_pair (STL Samples)

Other Resources

<utility> Members