It seems to me that, in modern C++ standard library, nearest what you want is std::tuple
.
If the problem is that std::tuple
store values of the listed types (so, I suppose, can be a problem instantiate an object of that type) it's easy write a instantiable object that wraps a std::tuple
using
without instantiate the std::tuple
itself.
I mean... given a wrapper like this
template <typename ... Ts>
struct wrapTuple
{
using type = std::tuple<Ts...>;
template <std::size_t N>
using element = std::tuple_element_t<N, type>;
static constexpr auto length { std::tuple_size_v<type> };
};
you can write the following lines without instantiate the wrapper
using int_types = wrapTuple<int, long, short, char>;
std::cout << int_types::length << ' '
<< typeid(int_types::element<2u>).name() << std::endl;
but you can also instantiate it without instantiate the std::tuple
int_types it;
std::cout << it.length << ' '
<< typeid(decltype(it)::element<2u>).name() << std::endl;
std::tuple
won't do becauseint_types
objects are created at some point? It's implied by your remark, just want to clarify that point. – Hypoglossalstd::tuple
which you never need to instantiate?tuple_size
andtuple_element
let you query the type list at compile time. – Ninfaningal