Check if a type is passed in variadic template parameter pack

后端 未结 2 1382
耶瑟儿~
耶瑟儿~ 2020-12-16 01:55

I\'ve heard somewhere, that using new C++1z syntax, it is really easy to check if a type is passed in variadic template parameter pack - apparently you can do this with code

2条回答
  •  悲&欢浪女
    2020-12-16 02:39

    If you are bound to C++11 you cannot use std::disjunction nor fold-expressions. However, it is rather straightforward to roll your own any_is_same:

    template 
    struct any_is_same {
        static const bool value = std::is_same::value || 
                                  any_is_same::value; 
    };
    
    template 
    struct any_is_same : std::is_same {};
    
    
    int main(){
        std::cout << any_is_same::value << "\n";
        std::cout << any_is_same::value << "\n";
    }
    

    Live Demo

提交回复
热议问题