summaryrefslogblamecommitdiff
path: root/fn_alias.cc
blob: 2d9fd1daadcd51a20d5647afec18442acba0d6a8 (plain) (tree)































                                                                          
#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));
}