Can someone explain this syntax for declaring a template function

I do not understand the following template declaration in the boost :: python library (line 47 from ... / boost _1_51 / boost / python / detail / msvc_typeinfo.hpp, to be precise):

template< typename T > T&(* is_ref_tester1(type<T>) )(type<T>) { return 0; } 

where type is template <class T> struct type {};

Seems functionally equivalent to:

 template<typename T> struct func_type_getter { typedef T&(*func_type)(type<T>); }; template< typename T > typename func_type_getter<T>::func_type is_ref_tester1(type<T>) { return 0; } 

Are these equivalents, is it just a shortened version, or can someone explain the differences?

+4
source share
1 answer

Yes, these two equivalents. Here's how a single line liner reads:

 template< typename T > T&(* is_ref_tester1(type<T>) )(type<T>) { return 0; } ^ ^ ^ ^ | | | | | | | 3. it return type is a pointer to a function taking a type<T> | | | | | 2. it a function taking a type<T> | | | 1. this is the declared identifier | 4. this is the return type of the function whose pointer is returned 
+3
source

Source: https://habr.com/ru/post/1500559/


All Articles