名前空間
変種
操作

std::tuple::tuple

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

 
 
ユーティリティライブラリ
支援を入力します (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::tuple
メンバ関数
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.
tuple::tuple
tuple::operator=
tuple::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_tuple
tie
forward_as_tuple
None
operator=
operator!=
operator<
operator<=
operator>
operator>=
std::swap
get
ヘルパークラス
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
tuple_element
uses_allocator
ignore
 
Defined in header <tuple>
constexpr tuple();
(1) (C + + 11以来)
explicit tuple( const Types&... args );
(2) (C + + 11以来)
template< class... UTypes >
explicit tuple( UTypes&&... args );
(3) (C + + 11以来)
template< class... UTypes >
tuple( const tuple<UTypes...>& other );
(4) (C + + 11以来)
template <class... UTypes>
tuple( tuple<UTypes...>&& other );
(5) (C + + 11以来)
template< class U1, class U2 >
tuple( const pair<U1,U2>& p );
(6) (C + + 11以来)
template< class U1, class U2 >
tuple( pair<U1,U2>&& p );
(7) (C + + 11以来)
tuple( const tuple& other ) = default;
(8) (C + + 11以来)
tuple( tuple&& other ) = default;
(9) (C + + 11以来)
template< class Alloc >
tuple( std::allocator_arg_t, const Alloc& a );
(10) (C + + 11以来)
template< class Alloc >
tuple( std::allocator_arg_t, const Alloc& a, const Types&... args );
(11) (C + + 11以来)
template< class Alloc, class... UTypes >
tuple( std::allocator_arg_t, const Alloc& a, UTypes&&... args );
(12) (C + + 11以来)
template <class Alloc, class... UTypes>
tuple( std::allocator_arg_t, const Alloc& a, const tuple<UTypes...>& other );
(13) (C + + 11以来)
template< class Alloc, class... UTypes >
tuple( std::allocator_arg_t, const Alloc& a, tuple<UTypes...>&& other );
(14) (C + + 11以来)
template< class Alloc, class U1, class U2 >
tuple( std::allocator_arg_t, const Alloc& a, const pair<U1, U2>& p );
(15) (C + + 11以来)
template< class Alloc, class U1, class U2 >
tuple( std::allocator_arg_t, const Alloc& a, pair<U1, U2>&& p );
(16) (C + + 11以来)
template< class Alloc >
tuple( std::allocator_arg_t, const Alloc& a, const tuple& other );
(17) (C + + 11以来)
template< class Alloc >
tuple( std::allocator_arg_t, const Alloc& a, tuple&& other );
(18) (C + + 11以来)
新しいタプルを構築し.
Original:
Constructs a new tuple.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
デフォルトのコンストラクタです。すべての要素を値が初期化.
Original:
Default constructor. Value-initializes all elements.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
対応するパラメータを持つタプルの各要素を初期化します.
Original:
Initializes each element of the tuple with the corresponding parameter.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
std::forward<Utypes>(args)内の対応する値を持つタプルの各要素を初期化します.
Original:
Initializes each element of the tuple with the corresponding value in std::forward<Utypes>(args).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
i内のすべてのsizeof...(UTypes)は、std::get<i>(other)とタプルのi番目の要素を初期化.
Original:
For all i in sizeof...(UTypes), initializes ith element of the tuple with std::get<i>(other).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
i内のすべてのsizeof...(UTypes)は、std::forward<Ui>(std::get<i>(other))とタプルのi番目の要素を初期化.
Original:
For all i in sizeof...(UTypes), initializes ith element of the tuple with std::forward<Ui>(std::get<i>(other)).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
p.firstp.secondから2つ目の要素から構成された第1の要素と2要素のタプルを構築します
Original:
Constructs a 2-element tuple with the first element constructed from p.first and the second element from p.second
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
std::forward<U1>(p.first)std::forward<U2>(p.second)から2つ目の要素から構成された第1の要素と2要素のタプルを構築します
Original:
Constructs a 2-element tuple with the first element constructed from std::forward<U1>(p.first) and the second element from std::forward<U2>(p.second)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
コピーコンストラクタをコンパイラが生成した。 otherの対応する要素を持つタプルの各要素を初期化します
Original:
Compiler-generated copy constructor. Initializes each element of the tuple with the corresponding element of other
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
9)
ムーブコンストラクタをコンパイラが生成した。 std::forward<Ui>(std::get<i>(other))持つタプルの各i番目の要素を初期化します.
Original:
Compiler-generated move constructor. Initializes each ith element of the tuple with std::forward<Ui>(std::get<i>(other)).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
10から18まで)1-9と同じですが、各要素を除いては、アロケータオブジェクトastd::uses_allocator<Ui, Alloc>::valuetrueされている各要素のコンストラクタに追加の引数として渡されている使用するアロケータ建設、によって作成されます.
Original:
10 - 18) Identical to 1-9 except each element is created by uses-allocator construction, that is, the Allocator object a is passed as an additional argument to the constructor of each element for which std::uses_allocator<Ui, Alloc>::value is true.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] パラメータ

args -
タプルの各要素を初期化するために使用される値
Original:
values used to initialize each element of the tuple
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
other -
tupeの各要素を初期化するために使用する値のタプル
Original:
a tuple of values used to initialize each element of the tupe
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
p -
この2組の要素の両方を初期化するために使用される値のペア
Original:
pair of values used to initialize both elements of this 2-tuple
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
a -
使用するアロケータ建設で使用するアロケータ
Original:
allocator to use in uses-allocator construction
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 <string>
#include <vector>
#include <tuple>
#include <memory>
 
// helper function to print a tuple of any size
template<class Tuple, std::size_t N>
struct TuplePrinter {
    static void print(const Tuple& t) 
    {
        TuplePrinter<Tuple, N-1>::print(t);
        std::cout << ", " << std::get<N-1>(t);
    }
};
 
template<class Tuple>
struct TuplePrinter<Tuple, 1>{
    static void print(const Tuple& t) 
    {
        std::cout << std::get<0>(t);
    }
};
 
template<class... Args>
void print(const std::tuple<Args...>& t) 
{
    std::cout << "(";
    TuplePrinter<decltype(t), sizeof...(Args)>::print(t);
    std::cout << ")\n";
}
// end helper function
 
int main()
{
    std::tuple<int, std::string, double> t1;
    std::cout << "Value-initialized: "; print(t1);
    std::tuple<int, std::string, double> t2(42, "Test", -3.14);
    std::cout << "Initialized with values: "; print(t2);
    std::tuple<char, std::string, int> t3(t2);
    std::cout << "Implicitly converted: "; print(t3);
    std::tuple<int, double> t4(std::make_pair(42, 3.14));
    std::cout << "Constructed from a pair"; print(t4);
 
    // given Allocator my_alloc with a single-argument constructor my_alloc(int)
    // use my_alloc(1) to allocate 10 ints in a vector
    std::vector<int, my_alloc> v(10, 1, my_alloc(1));
    // use my_alloc(2) to allocate 10 ints in a vector in a tuple
    std::tuple<int, std::vector<int, my_alloc>, double> t5(std::allocator_arg,
                                                           my_alloc(2), 42, v,  -3.14);
}

Output:

Value-initialized: (0, , 0)
Initialized with values: (42, Test, -3.14)
Implicitly converted: (*, Test, -3)
Constructed from a pair(42, 3.14)

[編集] も参照してください

引数の型で定義された型のtupleオブジェクトを作成します
Original:
creates a tuple object of the type defined by the argument types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
左辺値参照またはアンパックのtupleは、個々のオブジェクトにタプルが作成されます
Original:
creates a tuple of lvalue references or unpacks a tuple into individual objects
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]
右辺値参照のtupleを作成します
Original:
creates a tuple of rvalue references
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート) [edit]