What is a template argument?

So, I came across this today about programming templates in C ++, can someone explain to me that A (*) (B) as an argument to the template?

template <class X, class Y, class A, class B> struct replace_type_impl<A(*)(B),X,Y,false> { typedef typename replace_type<A,X,Y>::type (*type)(typename replace_type<B,X,Y>::type); }; 
+4
source share
4 answers

Type A (*)(B) is a pointer type to a function that takes a single argument of type B and returns a value of type A

This is just a different type. Your code is an instance of a partial specialization of the replace_type_impl class replace_type_impl .

+8
source

This is the type of function pointer, for a unary function that takes B and returns A

This pattern replaces X with Y [*] wherever X appears as a pointer to the function A(*)(B) . It replaces it separately in the return type A and parameter of type B, and then combines them back into a new typedef named type , which is also a function pointer.

[*] or maybe replaces Y with X or maybe does something completely different - I don't know what replace_type does, but I think this is a fair assumption.

+4
source

This is a pointer to a function that returns A and takes B as its only argument.

+1
source

A(*)(B)

This is a type; Pointer to a function that takes a value of B and returns the value of A by value.

+1
source

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


All Articles