(A toy, minimal not-working example)
The next code won't compile with cpp20/17:
template<typename TSomeTemplate>
struct A
{
static constexpr size_t B = 1;
template<typename T, typename... Ts>
static constexpr size_t C = 4;
template<typename T>
static constexpr size_t C<T> = B;
};
int main()
{
A<int>::C<int>;
return 0;
}
With the error of "Expression did not evaluate to constant" regarding the last line in the struct. However, it does compile with full specialization, or without referencing B:
template<typename TSomeTemplate>
struct Works
{
static constexpr size_t B = 1;
template<typename T, typename... Ts>
static constexpr size_t C = 4;
template<>
static constexpr size_t C<int> = B;
};
template<typename TSomeTemplate>
struct AlsoWorks
{
static constexpr size_t B = 1;
template<typename T, typename... Ts>
static constexpr size_t C = 4;
template<typename T>
static constexpr size_t C<T> = 2;
};
Why is it so? How can I make the first struct work?
size_t C<T> = B;
is for? – Highpitched