
On September 8, 2014 12:50:56 AM EDT, Lorenzo Caminiti
I was thinking about the problem of disabling data member declarations a bit more. I have a couple of questions on C++14 template variables
1. Why is not possible to use enabled_if with template variables?
For example, I'd expect this declaration to be ignored by the compiler when B is 0 and the use of n<0> to fail at (b). Instead clang 3.4.2 errors at (a) saying I cannot use enable_if there when B is 0.
#include
template< bool B > typename std::enable_if::type n = B; // (a)
I'm not certain why this isn't legal. I'd have to tread the Standard and don't have it handy.
2. Why is not possible to use template variables for data members?
For example, this does not compile on clang 3.4.2 saying the member is declared as a template (implying that is illegal).
struct x { template< typename T > T m; };
What size is x? It varies according to T, and T can be anything at any time according to your declaration. A member function template is self-contained. Everything about it and it's local variables are determined by its use. A class template is completely specified when instantiated. The same is not true of a data member template. ___ Rob (Sent from my portable computation engine)