boost::C++ 中的可选替代方案标准库

发布于 2024-12-27 11:31:42 字数 136 浏览 4 评论 0原文

我试图让我的程序在不使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柒夜笙歌凉 2025-01-03 11:31:42

简短的回答:不。

详细的回答:根据升压规范自行推出。文档相当详尽,代码也不是那么复杂,但这仍然需要高于平均水平的 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.

天荒地未老 2025-01-03 11:31:42

There is currently a proposal for C++14 (or C++17). So the answer is (probably) not yet :).

李不 2025-01-03 11:31:42

就像 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文