What is the best way of renaming (alias/forward) a function in C++?

牧云@^-^@ 提交于 2019-11-28 19:24:33

Is it truly general?

Yes.

Is this the simplest way?

Yes (sadly).

Is this the optimal way? (e.g. can be inlined, no unnecessary copies)

Yes.

What if the original function had some SFINAE features? (e.g. template<class A, class B, class C, class = std::enable_if< ... >::type>), will decltype transfer the SFINAE in all cases?

Yes, if the expression inside decltype yields an error (i.e., fun doesn't exist, perhaps due to SFINAE on fun), this will trigger SFINAE for gun aswell, removing it from the overload set.

What if the original function returned references? Isn't the decltype going to remove the references type?. (e.g. double& fun(double& x){return x;}).

No, why would it?

Same can be said about member functions, although this has to be done modifying the class I guess.

This isn't a question. What can be said about member functions? All of the above applies equally.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!