将std :: experimental :: optional<支持参考?

将std :: experimental :: optional<支持参考?

问题描述:

目前, boost :: optional<> 支持引用,但libstdc ++上我系统上的 std :: experimental :: optional<> 尚不支持.这是否反映了它可能成为标准的原因?

At the moment, boost::optional<> supports references but the std::experimental::optional<> on my system from libstdc++ does not. Is this reflective of what might make it into the standard?

我知道,可选建议书的作者将可选参考文献作为单独的建议书分离出来,以便主要的可选建议书有更大的机会被接受.关于可选引用的建议是否被拒绝或停止了工作?

I know that the optional proposal author spun off optional references as a separate proposal so that the main optional proposal would have a better chance of being accepted. Was the proposal for optional references rejected or did work on it stop?

这是否反映了它可能成为标准的原因?

Is this reflective of what might make it into the standard?

从工作草案中摘录( [20.5.2/1] ):

From the working draft ([20.5.2/1]):

需要为引用类型实例化可选模板的程序格式不正确.

A program that necessitates the instantiation of template optional for a reference type [...] is ill-formed.

我想这是对您的问题的答复.

I guess this replies to your question.

请注意,您仍然可以使用 std :: reference_wrapper 来解决该问题,如@bobah在评论中所述.

Note that you can still work around it by using std::reference_wrapper, as mentioned by @bobah in the comments.