関数ポインター関数によってテンプレート化されたテンプレートパラメーターとして、キャプチャーなしのラムダを渡すことができないようです。私はそれを間違った方法でやっていますか、それとも不可能ですか?
#include <iostream>
// Function templated by function pointer
template< void(*F)(int) >
void fun( int i )
{
F(i);
}
void f1( int i )
{
std::cout << i << std::endl;
}
int main()
{
void(*f2)( int ) = []( int i ) { std::cout << i << std::endl; };
fun<f1>( 42 ); // THIS WORKS
f2( 42 ); // THIS WORKS
fun<f2>( 42 ); // THIS DOES NOT WORK (COMPILE-TIME ERROR) !!!
return 0;
}