共用方式為


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
   );

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

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

Concepts

<utility> Members

make_pair (STL Samples)