Marko Borković
Marko Borković

Reputation: 1922

What is the meaning of (*) in template<typename T> using L = T(*)(T);?

I've been using this snippet of code for some testing and I understand what it does but it just occured to me I have no idea what (*) is supposed to do in this situation...

template<typename T>
using L  = T(*)(T);

I've tried removing it and the code runs perfectly fine without it. I think it might have something to do with pointers but I am not sure. I use the snippet to define parameters and return value of a passed lambda function

Upvotes: 3

Views: 145

Answers (1)

songyuanyao
songyuanyao

Reputation: 172934

Yes, it's a pointer type. T(*)(T) is a pointer to function T(T), which takes T and returns T.

Without it, i.e. T(T) is a function type. You said it works too, because in many cases it could decay to pointer to function as T(*)(T). For example, if you define T(T) as the function parameter type, which would be adjusted to T(*)(T).

An lvalue of function type T can be implicitly converted to a prvalue pointer to that function.

Upvotes: 5

Related Questions