Optional in C : Why No Specialization for Reference Types?
Despite the presence of specialization for reference types in libraries like Boost, the C standard library's std::optional does not provide such a feature. This decision has sparked inquiries about its rationale and potential alternative mechanisms.
Rationale Behind the Omission
During the discussion of n3406 (the proposal for optional), concerns were raised regarding the inclusion of optional references. Recognizing these objections, the authors of n3527 separated optional references into an auxiliary proposal to enhance the likelihood of acceptance for standard optional values. While optional was ultimately not included in C 14 due to unrelated factors, the committee's disapproval of optional references was not an issue.
Current Alternatives
Although std::optional does not offer specialization for reference types, the standard library lacks an equivalent construct providing the "reference to possibly existing object" semantics. This may leave developers seeking alternatives:
Future Considerations
While optional references are currently absent from the C standard library, the committee has not ruled out their future inclusion. Should a formal proposal be submitted, the decision will ultimately rest on the committee's evaluation of the merits of the proposed feature.
The above is the detailed content of Here are a few question-based title options, focusing on the core issue: * C std::optional: Why No Specialization for Reference Types? (Direct and to the point) * Reference Types in C std::option. For more information, please follow other related articles on the PHP Chinese website!