#include <array>
#include <type_traits>
template<int ... N>
struct seq
{
using type = seq<N...>;
static const std::size_t size = sizeof ... (N);
template<int I>
struct push_back : seq<N..., I> {};
};
template<int N>
struct genseq : genseq<N-1>::type::template push_back<N-1> {};
template<>
struct genseq<0> : seq<> {};
template<int N>
using genseq_t = typename genseq<N>::type;
template<typename T, int...N>
auto repeat(T value, seq<N...>) -> std::array<T, sizeof...(N)>
{
//unpack N, repeating `value` sizeof...(N) times
//note that (X, value) evaluates to value
return {(N, value)...};
}
struct A{
A(int){}
};
template<typename T, size_t N>
std::array<T, N> filled_array(T const& u)
{
//genseq_t<N> is seq<0,1,...N-1>
std::array<T, N> items = repeat(u, genseq_t<N>{} );
return items;
}
int main() {
auto x = filled_array<A, 5>(A(1));
}
I2luY2x1ZGUgPGFycmF5PgojaW5jbHVkZSA8dHlwZV90cmFpdHM+Cgp0ZW1wbGF0ZTxpbnQgLi4uIE4+CnN0cnVjdCBzZXEKewogICB1c2luZyB0eXBlID0gc2VxPE4uLi4+OwogICBzdGF0aWMgY29uc3Qgc3RkOjpzaXplX3Qgc2l6ZSA9IHNpemVvZiAuLi4gKE4pOwoKICAgdGVtcGxhdGU8aW50IEk+CiAgIHN0cnVjdCBwdXNoX2JhY2sgOiBzZXE8Ti4uLiwgST4ge307Cn07CiAgICAgICAgICAgICAgICAKdGVtcGxhdGU8aW50IE4+CnN0cnVjdCBnZW5zZXEgOiBnZW5zZXE8Ti0xPjo6dHlwZTo6dGVtcGxhdGUgcHVzaF9iYWNrPE4tMT4ge307Cgp0ZW1wbGF0ZTw+CnN0cnVjdCBnZW5zZXE8MD4gOiBzZXE8PiB7fTsKCnRlbXBsYXRlPGludCBOPgp1c2luZyBnZW5zZXFfdCA9IHR5cGVuYW1lIGdlbnNlcTxOPjo6dHlwZTsKCnRlbXBsYXRlPHR5cGVuYW1lIFQsIGludC4uLk4+CmF1dG8gcmVwZWF0KFQgdmFsdWUsIHNlcTxOLi4uPikgLT4gc3RkOjphcnJheTxULCBza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