Boost logo

Boost :

Subject: Re: [boost] [static_if] Is there interest in a `static if` emulation library?
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2014-09-08 05:27:04


On September 8, 2014 12:50:56 AM EDT, Lorenzo Caminiti <lorcaminiti_at_[hidden]> wrote:
>
>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 <type_traits>
>
>template< bool B >
>typename std::enable_if<B, bool>::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)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk