tuple Class

고정 길이의 시퀀스의 요소를 배치합니다.

template<class T1, class T2, ..., class TN>
class tuple {
public:
    tuple();
    explicit tuple(P1, P2, ..., PN);              // 0 < N
    tuple(const tuple&);
    template <class U1, class U2, ..., class UN>
        tuple(const tuple<U1, U2, ..., UN>&);
    template <class U1, class U2>
        tuple(const pair<U1, U2>&);               // N == 2
    void swap(tuple& right);
    tuple& operator=(const tuple&);
    template <class U1, class U2, ..., class UN>
        tuple& operator=(const tuple<U1, U2, ..., UN>&);
    template <class U1, class U2>
        tuple& operator=(const pair<U1, U2>&);    // N == 2
    };

매개 변수

  • TN
    N 번째 튜플 요소의 형식입니다.

설명

N 개체 형식의 저장 개체를 설명 하는 템플릿 클래스 T1, T2,..., TN, 각각, 어디 0 <= N <= Nmax.튜플 인스턴스의 범위 tuple<T1, T2, ..., TN> 수 N 템플릿 인수.템플릿 인수의 인덱스 Ti 이며 해당 저장 된 값은 해당 형식의 i - 1.따라서 우리가이 설명서에서 n 1에서 종류 번호 동안 해당 인덱스 0에서 N-1 사이의 값입니다.

예제

// tuple.cpp
// compile with: /EHsc

#include <vector>
#include <iomanip>
#include <iostream>
#include <tuple>
#include <string>

using namespace std;

typedef tuple <int, double, string> ids;

void print_ids(const ids& i)
{
   cout << "( "
        << get<0>(i) << ", " 
        << get<1>(i) << ", " 
        << get<2>(i) << " )." << endl;
}

int main( )
{
   // Using the constructor to declare and initialize a tuple
   ids p1(10, 1.1e-2, "one");

   // Compare using the helper function to declare and initialize a tuple
   ids p2;
   p2 = make_tuple(10, 2.22e-1, "two");

   // Making a copy of a tuple
   ids p3(p1);

   cout.precision(3);
   cout << "The tuple p1 is: ( ";
   print_ids(p1);
   cout << "The tuple p2 is: ( ";
   print_ids(p2);
   cout << "The tuple p3 is: ( ";
   print_ids(p3);

   vector<ids> v;

   v.push_back(p1);
   v.push_back(p2);
   v.push_back(make_tuple(3, 3.3e-2, "three"));

   cout << "The tuples in the vector are" << endl;
   for(vector<ids>::const_iterator i = v.begin(); i != v.end(); ++i)
   {
      print_ids(*i);
   }
}
  
  
  
  
  
  

요구 사항

헤더: <tuple>

네임 스페이스: std

참고 항목

참조

<tuple>

make_tuple Function