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.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3