I am trying to assign a lambda to an std::function
, like so:
std::function<void>(thrust::device_vector<float>&) f;
f = [](thrust::device_vector<float> & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
And I get an error:
error: incomplete type is not allowed
error: type name is not allowed
I think it refers to thrust::device_vector<float>
. I tried typenaming and typedefining the parameter:
typedef typename thrust::device_vector<float> vector;
std::function<void>(vector&) f;
f = [](vector & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
To no avail. However, if I just use the lambda (without the std::function
) it works:
typedef typename thrust::device_vector<float> vector;
auto f = [](vector & veh)->void
{
thrust::transform( veh.begin(), veh.end(), veh.begin(), tanh_f() );
};
What am I missing? I am compiling using nvcc release 6.5, V6.5.12 and g++ (Debian 4.8.4-1) 4.8.4
You are using the wrong syntax.
Try std::function<void(thrust::device_vector<float>&)> f;
instead
std::function<void(thrust::device_vector<float>&)> f;
declares a variable with type std::function<void(thrust::device_vector<float>&)>
, which is a function object that takes thrust::device_vector<float>&
and return void
g++ give you the incomplete type error because std::function<void>
is not a valid template instantiation.
clang++ give you a better error message telling you that std::function<void>() f;
is an invalid variable declaration:
main.cpp:11:28: error: expected '(' for function-style cast or type construction
std::function<void>(int) f;
~~~^
1 error generated.