I'm initializing an std::array at compile time with an initializer list, and I would like to have a way to store the number of elements. std::array::size()
would return the size of the whole array and it's not what I'm looking for.
How could I improve the below code? Many thanks!
#include <array>
constexpr std::array<int, 5> a{{1, 2, 3}};
constexpr size_t element_count(const std::array<int, 5> &a) { return ???; }
int main() { static_assert(element_count(a) == 3); }
I'm compiling with g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
.