Search code examples
c++c++11stdarray

Get size of std::array without an instance


Given this struct:

struct Foo {
  std::array<int, 8> bar;
};

How can I get the number of elements of the bar array if I don't have an instance of Foo?


Solution

  • You may use std::tuple_size:

    std::tuple_size<decltype(Foo::bar)>::value