blob: 358e8dda21e4851670dfb42ac2ac339002c3f769 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#if 0
set -xe
trap 'rm -f a.out' EXIT
g++ -std=c++17 fn_alias.cc && ./a.out
clang++ -std=c++17 fn_alias.cc && ./a.out
exit 0
#endif
#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));
}
|