我正在尝试编译类似的东西:
struct Obj { int i = 100; };
boost::optional<Obj> f(const bool _b)
{
if (_b) return Obj(); else return boost::none;
}
int main()
{
bool run = true;
while (boost::optional<Obj> retVal = f(true) && run)
{
std::cout << retVal.i;
}
return 0;
}
是否有可能实现它 - 将有效对象存储在变量中并将其分解为布尔值?