#include <iostream>
#include <array>
#if 1 // Not in C++11 // make_index_sequence
#include <cstdint>
template <std::size_t...> struct index_sequence {};
template <std::size_t N, std::size_t... Is>
struct make_index_sequence : make_index_sequence<N - 1, N - 1, Is...> {};
template <std::size_t... Is>
struct make_index_sequence<0u, Is...> : index_sequence<Is...> {};
#endif // make_index_sequence
namespace detail
{
template <typename T, std::size_t...Is>
constexpr std::array<T, sizeof...(Is)> make_array(T val, index_sequence<Is...>)
{
return {(static_cast<void>(Is), val)...};
}
}
template <std::size_t N, typename T>
constexpr std::array<T, N> make_array(T val)
{
return detail::make_array(val, make_index_sequence<N>());
}
int main()
{
constexpr auto a = make_array<5>(42);
for (auto e : a) {
std::cout << e << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YXJyYXk+CgojaWYgMSAvLyBOb3QgaW4gQysrMTEgLy8gbWFrZV9pbmRleF9zZXF1ZW5jZQojaW5jbHVkZSA8Y3N0ZGludD4KCnRlbXBsYXRlIDxzdGQ6OnNpemVfdC4uLj4gc3RydWN0IGluZGV4X3NlcXVlbmNlIHt9OwoKdGVtcGxhdGUgPHN0ZDo6c2l6ZV90IE4sIHN0ZDo6c2l6ZV90Li4uIElzPgpzdHJ1Y3QgbWFrZV9pbmRleF9zZXF1ZW5jZSA6IG1ha2VfaW5kZXhfc2VxdWVuY2U8TiAtIDEsIE4gLSAxLCBJcy4uLj4ge307Cgp0ZW1wbGF0ZSA8c3RkOjpzaXplX3QuLi4gSXM+CnN0cnVjdCBtYWtlX2luZGV4X3NlcXVlbmNlPDB1LCBJcy4uLj4gOiBpbmRleF9zZXF1ZW5jZTxJcy4uLj4ge307CgojZW5kaWYgLy8gbWFrZV9pbmRleF9zZXF1ZW5jZQoKbmFtZXNwYWNlIGRldGFpbAp7CiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVCwgc3RkOjpzaXplX3QuLi5Jcz4KICAgIGNvbnN0ZXhwciBzdGQ6OmFycmF5PFQ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