I was reviewing some code and came upon a line similar to:
std::tr1::function<bool (int, int)>(//etc...
The syntax for the template type, bool (int, int)
was unfamiliar to me. Based on Googling, in the case of std::tr1::function
it seems this syntax is used to define a function's return type and parameters. That makes sense, but why does that syntax work? As far as I know, C++ templates can only specify types?
I tried to instantiate an instance of the type in code as:
bool (int, int) test;
As I expected, the statement failed to compile. At the very least, the syntax would need to be something like: bool (test)(int, int);
Is bool (int, int)
treated as a C++ type? Any tips on reconciling this in my mind?
Thanks, Adam
It is called a function type.
You can't create instances of it, but you can create pointers to them and typedefs.
This question has some insight: What is a function type used for?