I want to use lambda as template parameter, but it will not compile in c++17. For example the temp_bar<int, lambda1>
here does not work. It seems the non-type parameter is limited. Can anyone explain why this is not allowed? It will make life much easier to enable this.
template<typename T>
bool to_bool(T o)
{
return bool(o);
}
template <typename T, auto F=to_bool<T>>
class temp_bar
{
public:
temp_bar(T o)
: _data{o}
{
if(F(o))
std::cout << "OK\n";
}
private:
T _data;
};
int main()
{
temp_bar<int> bar1{1};
auto lambda1 = [](int o){return o==2;};
temp_bar<int, lambda1> bar2{2};
return 0;
}