0

Can anyone tell me what kind of template function _Fn() is? And what is the meaning of the -> here?

template <class _Ty0, class _Ty1>
struct _Common_type
{
  template<class _Uty0, class _Uty1>
  static auto _Fn(int) -> decay<decltype(false ? declval<_Uty0>() : declval<_Uty1>())>;

  template<class, class>
  static auto _Fn(_Wrap_int) -> _Nil;

  typedef decltype(_Fn<_Ty0, _Ty1>(0)) type;
};
Evg
  • 25,259
  • 5
  • 41
  • 83
Der Appit
  • 329
  • 1
  • 2
  • 4

1 Answers1

2

Consider this function:

void foo()
{}

We can also write it like this:

auto foo() -> void
{}

It's a trailing return type, introduced in C++11.

In the above example it's completely pointless, but in more complicated scenarios it's useful. Imaging your return type were not void, but something relating to the arguments (e.g. decltype(someArgument)). Some people just use this form all the time for "consistency" (even on main! Ew!).

Now follow this logic all the way out to your more complex function template declaration, and that's all you're seeing.

Indeed, it appears to me that this is what the author of your code has done, since it doesn't seem "necessary" in your exampe.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055