Nvcc fails to preprocess c++11 functional code (std::function, std::bind etc.). The code is just some host-only templates included in .cu files. It is compiled successfully by g++ alone, however compilation fails after nvcc preprocessing.
Sample code:
#include <iostream>
#include <functional>
void foo(int a, int b, int c)
{
std::cout << a << " " << b << " " << c << std::endl;
}
void bar(std::function<void(int, int)> fun)
{
fun(1, 2);
}
int main()
{
bar(std::bind(&foo, 1, std::placeholders::_1, std::placeholders::_2));
return 0;
}
Compile:
g+±6 -std=c++14 foo.cpp -o foo # Successful
or
nvcc -std=c++14 foo.cu -o foo # Failed
My environment:
Cuda compilation tools, release 9.1, V9.1.85
I couldn’t find any topic covering the issue. Is it known already? Are there any workarounds?