Is it possible to define a lambda in C++ with default generic argument?
int main(){
auto lambda = [](auto i = 0){return i;};
std::cout<<lambda()<<"\n"; // this does not compile
std::cout<<lambda(4)<<"\n"; // this does compile
auto lambda2 = [](int i = 0){return i;};
std::cout<<lambda2()<<"\n"; // this is also OK
}
I wonder if it's possible to reproduce something like this functor, and why not
struct Lambda{
template<typename T=int>
auto operator()(T i=1){ return i;}
};
Aucun commentaire:
Enregistrer un commentaire