lundi 3 août 2020

type traits conjunction in C++11

I need to check variadic arguments in td::enable_if:

With C++17 I would write:

template <typename A, typename ...B>
class Foo : public A, public B...
{

public:

    template <typename = std::enable_if_t<std::is_default_constructible_v<A> &&
        (std::is_default_constructible_v<B> && ...)>>
    Foo()
    {}
    
    Foo(A &&a, B && ... b)
       : A(std::forward<A>(a)),
       B(std::forward<B>(b))...
    {}

};

But C++11 doesn't have a feature of expanding parameter pack this way. Neither it provides std::conjunction.

What is a simple way to implement conjunction with C++11? I suppose SFINAE with recursion would suffice, but I cannot wrap my hand around it...

Aucun commentaire:

Enregistrer un commentaire