How to make a variadic is_same?

后端 未结 6 778
刺人心
刺人心 2020-12-05 02:07

How can I make a class template that returns whether any of its variadic types are equal to the first type. I want to be able to do this:

is_same

        
6条回答
  •  情深已故
    2020-12-05 03:08

    In C++17 you have an even nicer solution, using template variables and fold expressions:

    template
    inline constexpr bool are_all_same = (std::is_same_v && ...);
    

    And the usage is also simpler than all other examples:

    are_all_same
    

    No ::value, no parentheses!

提交回复
热议问题