C ++ ptr_fun does not detect invalid parameterized functions

I tried using std :: ptr_fun to wrap my function, but when I try to wrap a function using the void parameter and bool return type i, you get an error:

code:

std::function<bool()> cr = std::not1(std::ptr_fun(&funct1)); 

function:

 bool funct1() { return false; } 

error:

  error: no matching function for call to 'ptr_fun(bool (*)())' 

but whenever I change the parameter to int, the problem seems to disappear.

how do i wrap a function using the void parameter ???

+4
source share
2 answers

Not 100% sure, but try using void* as parameter

+1
source

std::ptr_fun only works on unary functions: functions with one parameter.

bool funct1(); is not a unary function, it is a null function. There is no such thing as a void parameter. Syntax bool funct1(void); inherited from C is just a weird way of saying that there are no parameters at all.

+3
source

Source: https://habr.com/ru/post/1481618/


All Articles