Is it possible to specialize this template declaration:
template <class TYPE, class... ARGS> TYPE Foo(ARGS... args) {
static_assert(false);
}
I tried a few things such as:
template <> int Foo<int>(float args) {
return 42;
}
...but I always hit the static assert when I try to use it as such:
auto value = Foo<int>(1.5f);
What's the correct syntax?
You're not allowed to write a template that is only valid as long as it isn't instantiated. That runs afoul of the following rule in the standard:
If no valid specialization can be generated for a template, and that template is not instantiated, the template is ill-formed, no diagnostic required.
On the other hand, it would be fine if you had something in the body such as
static_assert(sizeof(TYPE) != sizeof(int));
In such a case, the template is valid, and your code will compile since the explicit specialization will in fact be used instead of the primary template. See http://coliru.stacked-crooked.com/a/238b979fd10c62c0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With