3
#include <type_traits>

template< typename T >
using cond =
    std::conditional_t<
        std::is_void< T >::value ,
        std::true_type ,
        std::false_type
    >::value;

static_assert( cond< void > , "" );

int main() {}

Example clang 3.6

missing 'typename' prior to dependent type name 'std::conditional_t::value, std::true_type, std::false_type>::value'

Why is it missing a typename as it isn't a type at all?
If I add the typename it throws this at me:

error: typename specifier refers to non-type member 'value' in 'std::integral_constant<bool, true>'

Isn't it the same thing as in here? How do I resolve this?

Community
  • 1
  • 1
nonsensation
  • 3,627
  • 6
  • 28
  • 41
  • 3
    `using`, [in that form](http://en.cppreference.com/w/cpp/language/type_alias), expects a typename. Not a value. – Drew Dormann Mar 22 '15 at 17:23
  • what's the point in using `conditional_t` with `true_type` and `false_type`, if you can use `std::is_void< T >::value` directly ? – Piotr Skotnicki Mar 22 '15 at 17:27
  • Ahhh.. i was struggling for over an hour and then i realised that most online compilers use g++ < 5.0 and only since 5.0 template variables were supported (and th error messages didnt helped either). After that I forgot to use the right syntax... its so obvious, I even linked to the other question.. – nonsensation Mar 22 '15 at 17:29
  • @PiotrS. this was just an example, the condition could be anything (had template templates in my mind) – nonsensation Mar 22 '15 at 17:30

1 Answers1

3

You can only use template aliases to alias types. The right syntax for your variable template is

template< typename T >
constexpr bool cond = std::conditional_t< std::is_void< T >::value,
                      std::true_type,
                      std::false_type >::value;

While the error message your code gets is a bit confusing, adding the suggested typename results in this more helpful message with clang 3.6

error: typename specifier refers to non-type member 'value' in
       'std::integral_constant'

using cond = typename std::conditional_t< std::is_void< T >::value,
^~~~~                 std::true_type,
                      std::false_type >::value;

which explains the real problem.

Pradhan
  • 16,391
  • 3
  • 44
  • 59