Best alternative to a typedef for a function template?

前端 未结 5 1571
你的背包
你的背包 2021-02-07 03:59

What I\'d like to do is something like this:

template 
DataType myFunc(DataType in)
{
   ...
}

typedef myFunc myFunc_i;

myFunc         


        
5条回答
  •  鱼传尺愫
    2021-02-07 04:46

    Some may disagree, some may jerk their knees against this, but consider this option:

    #define myFunc_i myFunc
    

    As far as macros go, this one is quite safe; the only danger is that someone could redefine or undefine it later.

    Aside from that, it has all the advantages of auto const myFunc = myFunc;. If you want auto but don't want to use C++0x features yet, this is a more portable way to achieve the same effect.

提交回复
热议问题