名前空間
変種
操作

std::make_pair

提供: cppreference.com
< cpp‎ | utility‎ | pair

 
 
ユーティリティライブラリ
支援を入力します (basic types, RTTI, type traits)
動的なメモリ管理
エラー処理
プログラムユーティリティ
可変個引数関数
日付と時刻
関数オブジェクト
initializer_list(C++11)
bitset
hash(C++11)
関係演算子
Original:
Relational operators
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
rel_ops::operator!=
rel_ops::operator>
rel_ops::operator<=
rel_ops::operator>=
ペアとタプル
Original:
Pairs and tuples
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair
tuple(C++11)
piecewise_construct_t(C++11)
piecewise_construct(C++11)
フォワード、スワップ、および移動
Original:
Swap, forward and move
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
swap
forward(C++11)
move(C++11)
move_if_noexcept(C++11)
declval(C++11)
 
std::pair
メンバ関数
Original:
Member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
pair::pair
pair::operator=
pair::swap
非メンバ関数
Original:
Non-member functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
make_pair
operator=
operator!=
operator<
operator<=
operator>
operator>=
std::swap
get(C++11)
ヘルパークラス
Original:
Helper classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
tuple_size(C++11)
tuple_element(C++11)
 
Defined in header <utility>
template< class T1, class T2 >

std::pair<T1,T2> make_pair( T1 t, T2 u );
template< class T1, class T2 >

std::pair<V1,V2> make_pair( T1&& t, T2&& u );
(C++11以前)

(C++11およびそれ以降)
引数のタイプからターゲット·タイプを推測、std::pairオブジェクトを作成.
Original:
Creates a std::pair object, deducing the target type from the types of arguments.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
推定タイプstd::decay<T1>::typestd::decay<T2>::type(値によって渡される関数の引数に適用される通常の型変換)は、いくつかのタイプのためのstd::decaystd::reference_wrapper<X>X結果のアプリケーションでない限り、推定されたタイプがあり、その場合にX&ですされています。 (C++11およびそれ以降)
Original:
The deduced types are std::decay<T1>::type and std::decay<T2>::type (the usual type transformations applied to arguments of functions passed by value) unless application of std::decay results in std::reference_wrapper<X> for some type X, in which case the deduced type is is X&. (C++11およびそれ以降)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

t, u -
値からペアを構築する
Original:
the values to construct the pair from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

与えられた値を含むstd::pairオブジェクト.
Original:
an std::pair object containing the given values.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]

#include <iostream>
#include <utility>
#include <functional>
 
int main()
{
    int n = 1;
    int a[5] = {1,2,3,4,5};
 
    // build a pair from two ints
    auto p1 = std::make_pair(n, a[1]);
    std::cout << "The value of p1 is "
              << "(" << p1.first << ", " << p1.second << ")\n";
 
    // build a pair from a reference to int and an array (decayed to pointer)
    auto p2 = std::make_pair(std::ref(n), a);
    n = 7;
    std::cout << "The value of p2 is "
              << "(" << p2.first << ", " << *(p2.second+1) << ")\n";
}

Output:

The value of p1 is (1, 2)
The value of p2 is (7, 2)