问题标签 [boost-optional]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
91 浏览

c++ - 如何在 C++11 中用 boost::optional 重写?

如何在 C++11 中重写以下代码以使用boost::optionalor ?boost::none

0 投票
3 回答
55 浏览

c++ - 如何在 C++14 中保留左值引用的同时衰减右值引用类型?

我有以下 C++14 lambda

https://godbolt.org/z/aexxTY

首先注意 boost::optional 可以包含左值引用,但不能包含右值引用。

是否可以使用上述通用 lambda 将右值作为副本处理。我想要的是聪明的东西

有开箱即用的东西吗?

0 投票
2 回答
599 浏览

c++ - boost::optional vs boost::make_optional

我想更好地理解使用默认构造函数创建boost::optional对象之间的区别:

或使用make_optional版本:

环顾四周,我刚刚明白make_optional版本 PastaType 不能是引用类型,但我想更好地弄清楚何时使用其中一种。

谢谢!

0 投票
1 回答
148 浏览

c++ - boost::make_optional 类型说明

0 投票
1 回答
53 浏览

c++ - Remove duplication in equivalent const and non-const members when returning optional reference by value

This answer explains how to remove duplication in equivalent const and non-const member functions which return by reference. It doesn't help, however, in the case where your function returns an optional reference to another type. Is there a solution for this case? E.g.,

0 投票
1 回答
209 浏览

c++ - 当 std::optional 和 boost::optional 的值是变体时的区别

在嵌入式编程中,内存分配是我们想要避免的事情。所以使用像状态设计模式这样的设计模式很麻烦。如果我们知道我们将拥有多少个状态,那么我们可以使用放置新操作。但在本文中,函数式方法避免了所有内存操作。唯一的缺点是它仅适用于具有 C++17 可用性的用户。我尝试在 c++11 中使用 boost::variant 和 boost::optional,但是在这个最小示例中缺少转换运算符(这里使用带有 c++17 的 MSVC 编译但不使用最新的 std):

错误信息:

但是如果我用 std::optional 替换 boost::optional 它编译得很好:编译示例 有人可以解释它们之间的区别是什么,我怎样才能让它也与 boost 一起工作?

0 投票
0 回答
28 浏览

c++ - 如何在 CLion 调试器中查看 boost::optional ?

CLion 中的内置 GDB 将 boost::optional 显示为 char 数组。我怎样才能教它把内容显示为真实的类型?

clion gdb 调试器中的 boost 可选