diff options
Diffstat (limited to 'fn_alias.cc')
-rw-r--r-- | fn_alias.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/fn_alias.cc b/fn_alias.cc new file mode 100644 index 0000000..2d9fd1d --- /dev/null +++ b/fn_alias.cc @@ -0,0 +1,32 @@ +#include <cassert> +#include <cstdio> + +// Function alias. + +void say() { + std::puts("say"); +} + +inline constexpr auto say_alias = say; + +// Template function alias. +// +// One drawback is that template type deducation does not work through the +// function pointer. One would need to write some macro wrapper. + +template <typename T, typename U> +auto add(T t, U u) -> decltype(t + u) { + return t + u; +} + +template <typename U> +inline constexpr auto add_int = add<int, U>; + +// Test me. + +int main() { + say(); + say_alias(); + + assert(add(2, 3) == add_int<int>(3, 2)); +} |