Optional References: Absence in std::optional
Unlike Boost's optional class, which supports reference types, the Standard Library's std::optional lacks this functionality. This omission has prompted inquiries into the reasoning behind this decision.
Lack of Specialization
When std::optional was initially proposed as std::experimental::optional in libc , the committee members voiced concerns regarding optional references. Subsequently, in the third revision of the proposal (n3527), the authors opted to make optional references an auxiliary proposal to enhance the likelihood of optional values being approved and incorporated into C 14.
Future Prospects
While optional references did not make it into C 14 for other reasons, the committee did not reject them outright. They remain open to the possibility of including optional references in future C standards if a formal proposal is presented.
Alternative Solutions
In the meantime, developers can consider alternative solutions such as custom object wrappers or using the boost::optional library, which provides the functionality for reference types.
The above is the detailed content of Why Doesn\'t `std::optional` Support Reference Types?. For more information, please follow other related articles on the PHP Chinese website!