Skip to content

Latest commit

 

History

History
57 lines (42 loc) · 1.51 KB

extent.md

File metadata and controls

57 lines (42 loc) · 1.51 KB

extent

  • type_traits[meta header]
  • std[meta namespace]
  • class template[meta id-type]
  • cpp11[meta cpp]
namespace std {
  template <class T, unsigned int I = 0>
  struct extent {
    static constexpr std::size_t value = …;
  };

  template <class T, unsigned I = 0>
  constexpr std::size_t extent_v = extent<T, I>::value; // C++17
}

概要

配列型のI番目の次元の要素数を取得する。

効果

  • Tが配列型であり、配列の次元数がIより大きい場合、I次元目の要素数をメンバ定数valueとして定義する。
  • Tが配列型ではない、もしくは配列の次元数がI以下の場合、値0をメンバ定数valueとして定義する。

#include <type_traits>

static_assert(std::extent<int[3][2], 0>::value == 3, "0th element count is 3");
static_assert(std::extent<int[3][2], 1>::value == 2, "1th element count is 2");

static_assert(std::extent<int[3][2], 2>::value == 0, "out of range");
static_assert(std::extent<int>::value == 0, "int isn't array type");

int main() {}
  • std::extent[color ff0000]

出力

バージョン

言語

  • C++11

処理系

参照