你能以某种方式将boost::optional
左值作为参考传递给改变值的函数吗?像这样的东西(http://coliru.stacked-crooked.com/a/f77d3b095af3d66b):
#include <iostream>
#include <boost/optional.hpp>
void foo(int& x)
{
x = 3;
}
int main() {
boost::optional<int> y;
foo(*y);
std::cout << *y << std::endl;
}
不出所料,这不起作用。
该函数需要使用标准类型作为输出参数tho(例如int& x
)。我希望我能正确解释这一点。我在询问我的意图的一般可能性。