Pointer to templated function
In a discussion in another forum about curried functions, I wondered
if this could be, technically speaking, considered currying in C++:
//-----------------------------------------------------------------
#include <iostream>
void function(int a, int b, int c)
{
std::cout << a << " " << b << " " << c << "\n";
}
template<int lastValue>
void curriedFunction(int a, int b)
{
function(a, b, lastValue);
}
int main()
{
void(*functionWith5)(int,int) = &curriedFunction<5>;
functionWith5(1, 2); // Is this a curried function call?
}
//-----------------------------------------------------------------
When I wrote that, I was actually kind of expecting it to not to work
(iow. to get some kind of syntax error). However, to a bit of my surprise,
it does work.
I had never before thought about how one could make a pointer to a
templated function instantiation. After all, you can't template a pointer.
I was a bit surprised that a regular bare-bones function pointer can be
made to point to a template function instantiation. I had a gut feeling
that you could possibly get an error because the internal type symbols for
a template function instantiation might be different to that of a "raw"
function. However, apparently not. (OTOH, thinking about it, why shouldn't
it work? How else are you supposed to take a pointer to a templated
function instantiation?)
Is this really legit, or is it just a fluke?