引用类型的 std::optional 特化

2024-05-11C/C++开发问题
11

本文介绍了引用类型的 std::optional 特化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

为什么std::optional(目前libc++中的std::experimental::optional)没有引用类型的特化(与 boost::optional 相比)?

Why std::optional (std::experimental::optional in libc++ at the moment) does not have specialization for reference types (compared with boost::optional)?

我认为这将是非常有用的选择.

I think it would be very useful option.

STL中是否有一些对象引用可能已经存在的对象语义?

Is there some object with reference to maybe already existing object semantics in STL?

推荐答案

When n3406(提案的第 2 修订版)进行了讨论,一些委员会成员对可选的参考资料感到不舒服.在 n3527 (修订版 #3),作者决定将可选引用作为辅助建议,以增加获得批准的可选值并将其放入 C++14 的机会.虽然由于其他各种原因,可选没有完全进入 C++14,但委员会并没有拒绝可选引用,并且如果有人提出它,将来可以自由添加可选引用.

When n3406 (revision #2 of the proposal) was discussed, some committee members were uncomfortable with optional references. In n3527 (revision #3), the authors decided to make optional references an auxiliary proposal, to increase the chances of getting optional values approved and put into what became C++14. While optional didn't quite make it into C++14 for various other reasons, the committee did not reject optional references and is free to add optional references in the future should someone propose it.

这篇关于引用类型的 std::optional 特化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法访问 C++ std::set 中对象的非常量成员函数
Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)...
2024-08-14 C/C++开发问题
17

从 lambda 构造 std::function 参数
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)...
2024-08-14 C/C++开发问题
25

STL BigInt 类实现
STL BigInt class implementation(STL BigInt 类实现)...
2024-08-14 C/C++开发问题
3

使用 std::atomic 和 std::condition_variable 同步不可靠
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)...
2024-08-14 C/C++开发问题
17

在 STL 中将列表元素移动到末尾
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)...
2024-08-14 C/C++开发问题
9

为什么禁止对存储在 STL 容器中的类重载 operator&()?
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)...
2024-08-14 C/C++开发问题
6