Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of function as a function argument

How do I properly define a default return value of a function that is an argument of another function?

Let's say I have a function like this:

bool x( ... , std::function<bool( ... )> func ) { ... ; return func( ... ); }

I would like x to return true if it's called without the last argument.

like image 387
Anton Avatar asked Sep 10 '26 17:09

Anton


1 Answers

You can specify a lambda as the default value of func, e.g.

bool x( ... , std::function<bool( ... )> func = []( ... ) { return true; } ) { ... ; return func( ... ); }
like image 79
songyuanyao Avatar answered Sep 13 '26 08:09

songyuanyao