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

后端 未结 7 471
忘掉有多难
忘掉有多难 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条回答
  •  -上瘾入骨i
    2021-01-30 11:22

    If you're willing to limit yourself to Visual C++, you can use the __if_exists and __if_not_exists statements.

    Handy in a pinch, but platform specific.

提交回复
热议问题