boost::C++ 中的可选替代方案标准库
我试图让我的程序在不使用 boost
的情况下运行,但找不到一些有用模式的替代方案。也就是说,我在标准库中找不到类似的模式。是否有 boost::Optional
的标准替代方案(C++11 或其他地方)?
I'm trying to get my program working without boost
usage, but can't find an alternative of some useful patterns. Namely, I can't find boost::optional
-likewise pattern in the standard library. Is there some standard alternative for boost::optional
(C++11 or somewhere else)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
简短的回答:不。
详细的回答:根据升压规范自行推出。文档相当详尽,代码也不是那么复杂,但这仍然需要高于平均水平的 C++ 技能。
更新这个答案:不幸的是,C++14 没有附带
std::Optional
。当前提案(修订版 5)是 N3793 预计将作为单独的技术规范发布或成为 C++17 的一部分。Short answer: No.
Long answer: Roll your own according to the boost spec. The documentation is quite exhaustive and the code isn't that complex, but this still requires above average C++ skills.
To update this answer: C++14 unfortunately did not ship with
std::optional
. The current proposal (Revision 5) is N3793 and it is expected to be shipped as a separate technical specification or to become part of C++17.目前有C++14 提案< /a>(或 C++17)。所以答案(可能)还没有:)。
There is currently a proposal for C++14 (or C++17). So the answer is (probably) not yet :).
就像 pmr 解释的一样,现在不可能,直到 C++17 出来才可能。
但是,您应该能够在 github 上使用这个 单标头库 作为 boost 的替代品-或标准可选。它没有依赖项(除了支持 c++11/c++14 的编译器)。
Like pmr explained, it is not possible right now, and will not be until C++17 is out.
However, you should be able to use this single header library on github as a drop in replacement of boost- or std optional. It has no dependencies (except a c++11/c++14 capable compiler).