Better way to disable argument-based template parameter deduction for functions?

前端 未结 1 1292
春和景丽
春和景丽 2021-02-20 00:37

Here is what I want to do:

template  void f(DisableDeduction obj) {std::cout << obj;}
// Here DisableDeduction aliases          


        
相关标签:
1条回答
  • 2021-02-20 01:01

    You can do it by putting T in non deducible context (to the left of ::), and use std::common_type from <type_traits>.

    example:

    template <typename T> void f(typename std::common_type<T>::type obj) {std::cout << obj;}
    
    0 讨论(0)
提交回复
热议问题