tuple_size kelas

Melaporkan jumlah elemen yang berisi tuple .

Sintaks

// TEMPLATE STRUCT tuple_size
template <class Tuple>
   struct tuple_size;

// number of elements in array
template <class Elem, size_t Size>
   struct tuple_size<array<Elem, Size>>
      : integral_constant<size_t, Size>;

// size of pair
template <class T1, class T2>
   struct tuple_size<pair<T1, T2>>
      : integral_constant<size_t, 2>

// size of tuple
template <class... Types>
   struct tuple_size<tuple<Types...>>
      : integral_constant<size_t, sizeof...(Types)>;

// size of const tuple
template <class Tuple>
   struct tuple_size<const Tuple>;

// size of volatile tuple
template <class Tuple>
   struct tuple_size<volatile Tuple>;

// size of const volatile tuple
template <class Tuple>
   struct tuple_size<const volatile Tuple>;

template <class T> inline constexpr size_t tuple_size_v = tuple_size<T>::value;

Parameter

Tuple
Jenis tuple.

Elem
Jenis elemen array.

Size
Ukuran array.

T1
Jenis anggota pertama pasangan.

T2
Jenis anggota kedua pasangan.

Types
Jenis elemen tuple.

Keterangan

Templat kelas memiliki anggota value yang merupakan ekspresi konstanta integral yang nilainya adalah sejauh mana jenis Tupletuple .

Spesialisasi templat untuk array memiliki anggota value yang merupakan ekspresi konstanta integral yang nilainya adalah Size, yang merupakan ukuran array.

Spesialisasi templat untuk pasangan memiliki anggota value yang merupakan ekspresi konstanta integral yang nilainya adalah 2.

Contoh

#include <tuple>
#include <iostream>

using namespace std;

typedef tuple<int, double, int, double> MyTuple;
int main()
{
    MyTuple c0(0, 1.5, 2, 3.7);

    // display contents "0 1 2 3"
    cout << get<0>(c0);
    cout << " " << get<1>(c0);
    cout << " " << get<2>(c0);
    cout << " " << get<3>(c0) << endl;

    // display size "4"
    cout << " " << tuple_size<MyTuple>::value << endl;
}
0 1.5 2 3.7
4

Persyaratan

Header:<tuple>

Header:<array> (untuk spesialisasi array)

Header:<utility> (untuk spesialisasi pasangan)

kumpulan nama XML: std