Is the absence of
std::array::array(const T& value);
an oversight? It seems mighty useful to me, and dynamic containers (
You may use std::index sequence
for that:
namespace detail
{
template
constexpr std::array
make_array(const T& value, std::index_sequence)
{
return {{(static_cast(Is), value)...}};
}
}
template
constexpr std::array make_array(const T& value)
{
return detail::make_array(value, std::make_index_sequence());
}
Demo
std::make_index_sequence
is C++14, but can be implemented in C++11.
static_cast
is to handle evil operator,
that T
might provide.