I write a simple C++14 program which can be correctly compiled by gcc, but cannot be compiled by nvcc. The minimal reproducible code is shown below:
#include<cstdio>
template <int K>
struct Struct {
int a;
};
template <int K, int... Ks, typename F>
void apply(F func, int KK) {
if (KK == K) {
Struct<K> i{K};
func(i);
return;
}
apply<Ks...>(func, KK);
}
template <typename F>
void apply(F func, int KK) {}
int main() {
auto fun = [](auto i) { printf("enter %d\n", i.a); };
apply<1, 2, 3>(fun, 1);
}
The compilation error is shown below:
error: no instance of overloaded function "apply" matches the argument list
argument types are: (lambda [](auto)->auto, int)
detected during:
instantiation of "void apply<K,Ks...,F>(F, int) [with K=3, Ks=<>, F=lambda [](auto)->auto]"
(15): here
instantiation of "void apply<K,Ks...,F>(F, int) [with K=2, Ks=<3>, F=lambda [](auto)->auto]"
(15): here
instantiation of "void apply<K,Ks...,F>(F, int) [with K=1, Ks=<2, 3>, F=lambda [](auto)->auto]"
(23): here