Parameter pack aware std::is_base_of()

Posted by T. Carter on Stack Overflow See other posts from Stack Overflow or by T. Carter
Published on 2012-11-26T10:24:17Z Indexed on 2012/11/26 11:04 UTC
Read the original article Hit count: 135

Is there a possibility to have a static assertion whether a type provided as template argument implements all of the types listed in the parameter pack ie. a parameter pack aware std::is_base_of()?

template <typename Type, typename... Requirements>
class CommonBase
{
    static_assert(is_base_of<Requirements..., Type>::value, "Invalid.");
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            parameter pack aware version of std::is_base_of()
public:
    template <typename T> T* as()
    {
        static_assert(std::is_base_of<Requirements..., T>::value, "Invalid.");
        return reinterpret_cast<T*>(this);
    }
};

© Stack Overflow or respective owner

Related posts about c++

Related posts about templates