Can C ++ 17 handle nested variable templates?

Consider the C ++ 17 code below, which checks a set of enum values ​​to see if this set contains a different enumeration value:

enum Flag { val1, val2, val3, val4, val5 };

template<Flag arg> struct Value {
    template<Flag... set> struct IsIn {
        static constexpr bool value =
            static_cast<bool>(((set == arg) || ...));
    };
};

This works as intended:

bool x = Value<val4>::IsIn<val1, val2, val5>::value;
// x == false

bool y = Value<val2>::IsIn<val3, val2>::value;
// y == true

However, I want to check if the entire set of values ​​is contained in another set, for example:

template<Flag... args> struct Values {
    template<Flag... set> struct AreIn {
        static constexpr bool value =
            static_cast<bool>((Value<args>::IsIn<set...>::value && ...));
    };
};

The above does not compile on GCC 7.3 or Clang 5.0; they both give rather cryptic answers that make little sense of the problem. Given that the extension of the parameter package in the list of template parameters is allowed (while the template supports the extension), it is difficult for me to determine why this is not legal C ++.

+6
source share
2 answers

++: .

Foo<Bar>::Baz<Quux>, Foo<Bar> , template Baz, . Clang , (, ) Expected ) - .

.

, , , , template :

template<Flag... args>
struct Values {
    template<Flag... set>
    struct AreIn {
        static constexpr bool value =
            static_cast<bool>((Value<args>::template IsIn<set...>::value && ...));
    };
};

, static_cast<bool>() .

+6

:

static_cast<bool>((Value<args>::IsIn<set...>::value && ... ))

static_cast<bool>((Value<args>::template IsIn<set...>::value && ... ))

? AreIn , Value<args> . , Values, IsIn, . template promises , , IsIn , <... > , set... ::value ( ), .

, , , , Values<val1, val2>, AreIn<val1, val2, val5>, ::value. - , , template .

+4

All Articles