为什么 std::flat_set 和 std::flat_map 有一些 noexcept 函数而其他容器适配器没有?

问题描述 投票:0回答:0

我注意到

std::flat_set
std::flat_map
容器适配器提供了一些noexcept成员函数,具体有以下几个:

[[nodiscard]] bool empty() const noexcept;
size_type size() const noexcept;

然而,所有其他容器适配器都提供与 non-noexcept 相同的成员函数:

[[nodiscard]] bool empty() const;
size_type size() const;

一开始,我同意标准不在成员函数中引入noexcept specific,因为实际上并不能保证对应容器的成员函数也是noexcept。一个可能的解决方案是引入有条件的 noexcept,例如在许多

std::swap
专业中。

所以,我不明白为什么相同的成员函数在

std::flat_set
std::flat_map
中被声明为noexcept。

c++ stl adapter noexcept
© www.soinside.com 2019 - 2024. All rights reserved.