hide function template, declare specializations

后端 未结 4 1100
眼角桃花
眼角桃花 2021-01-22 17:46

This is a followup to C++ templates: prevent instantiation of base template

I use templates to achieve function overloading without the mess of implicit type conversions

4条回答
  •  灰色年华
    2021-01-22 18:32

    The best way is to implement that basic template with something invalid (not illegal) C++ code. For example,

    template T f(T v) { return v.Default_Implementation_Not_Available; }

    This error will be compile time; and it's generated only when you instantiate any version other than 'long' & 'bool'. If you don't instantiate 'int' version, compilation will go fine.

提交回复
热议问题