Jeśli masz:
Kopiuj
outer<int, double, char[5]>
to T0 to typ int, T1 to double i T2 to char[5].
to jest wtedy w zasadzie taki szablon:
Kopiuj
template <int, double, char[5]>
struct inner {};
Największym problemem przy użyciu tego szablonu jest fakt, że ostatni parametr to char[5]. Nie wiem czy da się stworzyć taką wartość (modyfikowalny string w compile time).
Kopiuj
template <typename... T>
struct outer
{
template <T... args>
struct inner {};
};
outer<int, double, char[5]>::inner< 520, 123.0, "aaaa" > a;
Coś takiego się nie kompiluje.
Kopiuj
<source>:12:49: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
12 | outer<int, double, char[5]>::inner< 520, 123.0, "aaaa" > a;
| ^
<source>:12:49: error: pointer to subobject of string literal is not allowed in a template argument
Natomiast, gdybyś chciał faktycznie użyć literal stringa w miejscu parametru to da się ale trzeba użyć innego typu.
Kopiuj
template <typename... T>
struct outer
{
template <T... args>
struct inner {};
};
inline constexpr char s[] = "foob";
outer<int, double, const char(&)[5]>::inner<520, 123.0, s> a;
Możesz też opuścić wielkość arraya:
Kopiuj
inline constexpr char s[] = "foob";
outer<int, double, const char(&)[]>::inner<520, 123.0, s> a;
Też się kompiluje.
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0424r2.pdf