Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8906061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:33:15+00:00 2026-06-15T02:33:15+00:00

Is there a possibility to have a static assertion whether a type provided as

  • 0

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);
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:33:16+00:00Added an answer on June 15, 2026 at 2:33 am

    Update for C++17:
    With C++17’s fold expressions this becomes almost trivial:

    template <typename Type, typename... Requirements>
    class CommonBase
    {
        static_assert((std::is_base_of_v<Type, Requirements> && ...), "Invalid.");
    };
    

    Original Answer (C++11/14):
    You might use pack expansion and some static version of std::all_of:

    template <bool... b> struct static_all_of;
    
    //implementation: recurse, if the first argument is true
    template <bool... tail> 
    struct static_all_of<true, tail...> : static_all_of<tail...> {};
    
    //end recursion if first argument is false - 
    template <bool... tail> 
    struct static_all_of<false, tail...> : std::false_type {};
    
    // - or if no more arguments
    template <> struct static_all_of<> : std::true_type {};
    
    template <typename Type, typename... Requirements>
    class CommonBase
    {
        static_assert(static_all_of<std::is_base_of<Type, Requirements>::value...>::value, "Invalid.");
        //                                               pack expansion:      ^^^
    };
    
    struct Base {};
    struct Derived1 : Base {};
    struct Derived2 : Base {};
    struct NotDerived {};
    
    int main()
    {
      CommonBase <Base, Derived1, Derived2> ok;
      CommonBase <Base, Derived1, NotDerived, Derived2> error;
    }
    

    The pack expansion will expand to the list of values you get by inserting every type in Requirements... for the question mark in std::is_base_of<Type, ?>::value, i.e. for the first line in main it will expand to static_all_of<true, true>, for the second line it will be static_all_of<true, false, true>

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any possibility in the prefix-function of a given pattern to have something
I have a devexpress Grid with GridView and there is the possibility to add
Is there any way or possibility to update an apps code and have the
Is there a possibility to increase/decrease font size in all UI elements throughout the
I have the following code with private static members. All of these classes say
In C-derivative languages there is the possibility to have conditional code for debug and
I have some code that receives some XML and there is the possibility that
Is there possibility to compile windows service using only mingw c++ compiler and library?
Is there a possibility in eclipse to exclude the test sources of a maven
Is there any possibility to change the text-color of some parts in a textarea

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.