After taking suggestions from the answers, I have written this new and improved function alias macro:
#define FUN_ALIAS_SPEC(SPECS, NEW_NAME, ...) \
template <typename... Args> \
SPECS auto NEW_NAME(Args &&... args) \
noexcept(noexcept(__VA_ARGS__(std::forward<Args>(args)...))) \
-> decltype(__VA_ARGS__(std::forward<Args>(args)...)) { \
return __VA_ARGS__(std::forward<Args>(args)...); \
}
#define FUN_ALIAS(NEW_NAME, ...) \
FUN_ALIAS_SPEC(inline, NEW_NAME, __VA_ARGS__)
Thanks to @Justin, this is now SFINAE friendly by putting the function call expression in decltype()
rather than using decltype(auto)
.
Thanks to @Rakete1111, this is now constexpr
friendly by allowing the user to put specifiers before the definition. This means that the alias can also be made into static
class member.
Thank you both for participating! I encourage future readers to upvote their answers instead of this one.