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

前端 未结 1 1289
春和景丽
春和景丽 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 .

    example:

    template  void f(typename std::common_type::type obj) {std::cout << obj;}
    

    0 讨论(0)
提交回复
热议问题