我正在尝试编译类似下面这样的东西:
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;
}有没有可能做到这一点--将一个有效的对象存储在一个变量中,并将其分解为一个布尔值?
发布于 2020-03-18 22:31:51
您可以将while更改为for,如下所示:
for (boost::optional<Obj> retVal = f(true), retVal && run; retVal = f(true))
{
std::cout << retVal.i;
}https://stackoverflow.com/questions/60741618
复制相似问题