You might use a std::array internally and convert an array:
#include <array>
#include <utility>
template <typename T, std::size_t ... I>
constexpr std::array<T, sizeof...(I)>
make_sequence(std::integer_sequence<std::size_t, I...>, const T (&array)[sizeof...(I)]) {
return { array[I] ... };
}
template <typename T, std::size_t N>
constexpr std::array<T, N>
make_sequence(const T (&array)[N]) {
return make_sequence(std::make_index_sequence<N>(), array);
}
// Test
#include <cassert>
struct A {
constexpr A(const int (&arr)[5])
: arr_(make_sequence(arr))
{}
const std::array<int, 5> arr_;
};
int main()
{
int array[5] = { 0, 1, 2, 3, 4 };
A a(array);
assert(a.arr_[2] == 2);
return 0;
}
However, if you are free to modify the interface of class A, go with the answer of @ecatmur.
std::arrayworks the way it does.