标准预期 问答列表

std::expected 的这种仅移动类型的行为是 MSVC bug 还是未定义的行为?

作者:dw218192 提问时间:11/13/2023

使用 Microsoft Visual Studio 的 MSVC 编译器进行编译时,我的 C++ 代码遇到了一个奇怪的问题,我正在尝试根据 C++ 标准确定它是编译器错误还是未定义的行为。 最小可...

为什么 std::expected 中没有单子运算?

作者:Desmond Gold 提问时间:2/9/2022

在 C++23 中,采用了 中的一元运算,后来又采用了 .为什么像 、 这样的一元运算没有包含在正文中?std::optionalstd::expectedand_thentransformor_el...

std::unexpected 构造函数约束

作者:NotMe 提问时间:3/18/2023

我正在阅读 cpp 23 标准,我偶然发现了.std::unexpected 节 expected.un.cons 定义 template<class Err = E> constexpr exp...

何时使用 std::expected 而不是异常

作者:Jan Schultke 提问时间:6/13/2023

何时应使用 std::expected,何时应使用异常?以这个函数为例: int parse_int(std::string_view str) { if (str.empty()) { thr...

如何处理不符合预期错误类型的异常?

作者:einpoklum 提问时间:9/25/2023

假设我想使用 C++23 中提供的新 std::expected<T、E> 机制,并带有一个函数: using E = /* domain-specific error type regarding...


共5条 当前第1页