是否可以评价std::optional::value_or(expr)
以一种懒惰的方式论证,所以expr
仅在没有值的情况下才计算?
如果没有,什么是合适的替代品?
#include <optional>
template <typename F>
struct Lazy
{
F f;
operator decltype(f())() const
{
return f();
}
};
template <typename F>
Lazy(F f) -> Lazy<F>;
int main()
{
std::optional<int> o;
int i = o.value_or(Lazy{[]{return 0;}});
}
DEMO http://coliru.stacked-crooked.com/a/68660776247975dc
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)