【发布时间】:2016-03-24 04:23:35
【问题描述】:
我有以下 unordered_set:
class ArtifactImpl{...};
class ArtifactSetKeyOps
{
public:
std::size_t operator()(const ArtifactImpl& artifact) const noexcept;
bool operator()(const ArtifactImpl& lhs, const ArtifactImpl& rhs) const noexcept;
};
std::unordered_set<ArtifactImpl,
ArtifactSetKeyOps,ArtifactSetKeyOps> artifactSet_;
请注意,我的哈希和谓词模板参数有一个 noexcept 规范。
- unordered_set::find 可以抛出吗?
我知道 find 没有标记为 noexcept,但实际上 find 不应该执行分配...
- 是否可以从带有 noexcept 标记的函数调用 find ?
例如:
const ArtifactImpl& foo() noexcept
{
auto pos = artifactSet_.find(key);
//etc...
}
尽管上面的 foo() 违反了 find 的 noexcept 规范,但我想知道该规范是否实际上适用于如果提供自己的 noexcept 哈希和比较。
【问题讨论】:
标签: c++ c++11 unordered-set