How to call a templated function if it exists, and something else otherwise?

后端 未结 7 472
忘掉有多难
忘掉有多难 2021-01-30 10:58

I want to do something like

template 
void foo(const T& t) {
   IF bar(t) would compile
      bar(t);
   ELSE
      baz(t);
}
7条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-30 11:47

    Are you not able to use full specialisation here (or overloading) on foo. By say having the function template call bar but for certain types fully specialise it to call baz?

提交回复
热议问题