Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 1.54 KB

File metadata and controls

62 lines (46 loc) · 1.54 KB

tuple_size

  • array[meta header]
  • std[meta namespace]
  • class template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template <class T> class tuple_size; // 先行宣言

  // C++11
  template <class T, std::size_t N>
  struct tuple_size<array<T, N>> {
    static constexpr std::size_t value = N;
  };

  // C++14
  template <class T, std::size_t N>
  struct tuple_size<array<T, N>>
    : integral_constant<std::size_t, N> {};
}
  • integral_constant[link /reference/type_traits/integral_constant.md]

概要

tuple_sizeは、タプルとして見なせる型の要素数を取得するためのクラスである。

要素数は、integral_constantの機能を利用してコンパイル時の定数値として取得できる。

<array>ヘッダでは、arrayクラスに関する特殊化を定義する。

#include <array>

int main()
{
  static_assert(std::tuple_size<std::array<int, 3>>::value == 3, "");
}
  • std::tuple_size[color ff0000]

出力

バージョン

言語

  • C++11

処理系

  • Clang: ??
  • GCC: 4.7.0 [mark verified]
  • ICC: ??
  • Visual C++: 2008 (std::tr1) [mark verified], 2010 [mark verified], 2012 [mark verified]

参照