template<typename, typename>
struct append_to_type_seq { };
template<typename T, typename... Ts, template<typename...> class TT>
struct append_to_type_seq<T, TT<Ts...>>
{
using type = TT<Ts..., T>;
};
template<typename T, unsigned int N, template<typename...> class TT>
struct repeat
{
using type = typename
append_to_type_seq<
T,
typename repeat<T, N-1, TT>::type
>::type;
};
template<typename T, template<typename...> class TT>
struct repeat<T, 0, TT>
{
using type = TT<>;
};
#include <type_traits>
#include <tuple>
template<typename... Ts>
struct X { };
int main()
{
repeat<double, 5, std::tuple>::type t = std::make_tuple(1., 2., 3., 4., 5.);
static_assert(
std::is_same<
decltype(t),
std::tuple<double, double, double, double, double>
>::value, "!");
repeat<double, 3, X>::type y;
static_assert(std::is_same<decltype(y), X<double, double, double>>::value, "!");
}
CiAgICB0ZW1wbGF0ZTx0eXBlbmFtZSwgdHlwZW5hbWU+CiAgICBzdHJ1Y3QgYXBwZW5kX3RvX3R5cGVfc2VxIHsgfTsKCiAgICB0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZS4uLiBUcywgdGVtcGxhdGU8dHlwZW5hbWUuLi4+IGNsYXNzIFRUPgogICAgc3RydWN0IGFwcGVuZF90b190eXBlX3NlcTxULCBUVDxUcy4uLj4+CiAgICB7CiAgICAgICAgdXNpbmcgdHlwZSA9IFRUPFRzLi4uLCBUPjsKICAgIH07CgogICAgdGVtcGxhdGU8dHlwZW5hbWUgVCwgdW5zaWduZWQgaW50IE4sIHRlbXBsYXRlPHR5cGVuYW1lLi4uPiBjbGFzcyBUVD4KICAgIHN0cnVjdCByZXBlYXQKICAgIHsKICAgICAgICB1c2luZyB0eXBlID0gdHlwZW5hbWUKICAgICAgICAgICAgYXBwZW5kX3RvX3R5cGVfc2VxPAogICAgICAgICAgICAgICAgVCwKICAgICAgICAgICAgICAgIHR5cGVuYW1lIHJlcGVhdDxULCBOLTEsIFRUPjo6dHlwZQogICAgICAgICAgICAgICAgPjo6dHlwZTsKICAgIH07CgogICAgdGVtcGxhdGU8dHlwZW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