mardi 3 juillet 2018

Match partially or completely type parameter pack

I want to check if the type parameter pack are matching partially or completely with another parameter pack.

So far, I'm trying this:

template<typename... Arguments>
struct VariadicArguments
{
    template<typename... AnotherArguments>
    struct IsSame: std::bool_constant<sizeof...(AnotherArguments)==0> {};
};

template<typename Arg, typename... Arguments>
struct VariadicArguments<Arg, Arguments...>
{
    template<typename... Args>
    struct IsSame: std::false_type{};

    template<typename AnotherArg, typename... AnotherArguments>
    struct IsSame<AnotherArg, AnotherArguments...>:
        std::bool_constant<
            std::is_same<Arg, AnotherArg>::value &&
            VariadicArguments<Arguments...>::IsSame<AnotherArguments...>::value> { };

    template<>
    struct IsSame<> : std::true_type{};
};

template<>
struct VariadicArguments<>
{
    template<typename... Args>
    struct IsSame : std::false_type {};

    template<>
    struct IsSame<> : std::true_type {};
};

I predicted that

VariadicArguments<int, float, double>::IsSame<int, float>::value // true
VariadicArguments<int, float, double>::IsSame<int, double>::value // false
VariadicArguments<int, float, double>::IsSame<int, float, double>::value // true
VariadicArguments<int, float, double>::IsSame<>::value // true

But I'm getting some compile-time errors

1>signal.hpp(25): error C2210: '_Val': pack expansions cannot be used as arguments to non-packed parameters in alias templates

1>signal.hpp(25): note: see reference to class template instantiation 'VariadicArguments::IsSame' being compiled 1>d:\dell\source\repos\mimg\mimg-base\signal.hpp(29): note: see reference to class template instantiation 'VariadicArguments' being compiled

1>signal.hpp(25): error C3770: 'unknown-type': is not a valid base class

1>signal.hpp(25): warning C4346: 'VariadicArguments::IsSame': dependent name is not a type 1>d:\dell\source\repos\mimg\mimg-base\signal.hpp(25): note: prefix with 'typename' to indicate a type

1>signal.hpp(25): error C2143: syntax error: missing ',' before '::'

1>signal.hpp(25): error C2039: 'value': is not a member of '`global namespace''

1>signal.hpp(25): error C2143: syntax error: missing ',' before '>'

1>signal.hpp(41): error C3769: 'VariadicArguments': a nested class cannot have the same name as the immediately enclosing class

1>signal.hpp(57): error C2953: 'VariadicArguments<>::VariadicArguments': class template has already been defined

1>signal.hpp(16): note: see declaration of 'VariadicArguments<>::VariadicArguments'

1>signal.hpp(67): error C3412: 'VariadicArguments<>': cannot specialize template in current scope

Aucun commentaire:

Enregistrer un commentaire