I have a variadic class vector that contains types. I want to access its elements in a metaprogram. The only way I have succeeded is to add methods to the vector class template as shown below, but I would like to receive the vector in another metafunction deducing the type elements it contains. How can I "export" or make available the template arguments the vector contains?
As of now, this is what I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
template<typename...TypeElements>
struct vector
{
template<size_t N>
struct get_at
{
using type = get_at_t<N, TypeElements...>;
};
template<typename Elem>
struct push_back
{
using type = vector<TypeElements..., Elem>;
};
template<typename Elem>
struct push_front
{
using type = vector<Elem, TypeElements...>;
};
};
I would like to do something like this:
1 2 3 4 5 6 7 8 9
template<typename Elem>
struct push_back
{
template<template<typename...ExistingElements> class Class>
struct apply
{
using type = vector<Elem, ExistingElements...>;
};
};
where I would call it like so:
1 2
using MyVector = vector<int, unsigned, char>;
using res = push_back<longdouble>::apply<MyVector>::type;
so that the compiler could deduce the template arguments of MyVector class.
Of course this does not compile.
How can I access the elements of a vector from outside the vector?