[英]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. 如果没有最后一个参数调用它,我希望
x
返回true
。
您可以将lambda指定为func
的默认值,例如
bool x( ... , std::function<bool( ... )> func = []( ... ) { return true; } ) { ... ; return func( ... ); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.