Why this construction doesn't work?
Visual Studio shows error C3201: the template parameter list for class template 'AA' does not match the template parameter list for template parameter 'C'. But it seems to be <int, char, bool>
in both cases.
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<typename... T>
struct outer
{
template <template<T... > typename C>
struct inner
{
template<T... X>
using type = C<X...>;
};
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
ADDED: Moreover, compiler can't infer types in specializations like
template<class T, template<T> class C, T X>
struct A<C<X>> { ... };
Are such tricks prohibited by standard or is it just compiler limitations?
I suspect this is allowed, and this is just the compiler screwing up. When I played with it to get a workaround working, I got a lot of internal compiler errors; that is usually a sign of it not being rejected on purpose, plus the error message makes no sense.
In c++20 I can produce this workaround.
template<int I, char C, bool B>
struct AA
{
static const int i = I;
static const char c = C;
static const bool b = B;
};
template<template<auto... > typename C, typename... Ts>
struct outer_base
{
struct inner
{
template<Ts... X>
using type = C<X...>;
};
};
template<typename... Ts>
struct outer
{
template <template<auto... > typename C>
using inner = typename outer_base<C, Ts...>::inner;
};
static_assert(outer<int, char, bool>::inner<AA>::type<5, 'a', true>::i == 5, "???");
which is a bit less constrained than you might like, as it doesn't require C
to match the types Ts...
exactly, just be compatible with them.