Will std::experimental::optional<> support references?

三世轮回 提交于 2021-02-07 11:49:18

问题


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?


回答1:


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

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.

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



来源:https://stackoverflow.com/questions/37905409/will-stdexperimentaloptional-support-references

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!