【发布时间】:2018-10-22 12:07:43
【问题描述】:
我想知道是否可以使用 C++11 的noexcept operator 来定义 e 的 noextcept 说明符。 G。调用另一个类的方法的析构函数(例如 std::allocator::deallocate):
template <class DelegateAllocator = std::allocator<uint8_t>>
class MyAllocator final {
public:
using allocator_type = DelegateAllocator;
// ...
~MyAllocator() noexcept(noexcept(/* what to use */))) {
if (memory_ != nullptr) {
allocator_.deallocate(memory_, length_);
}
}
private:
allocator_type allocator_;
uint8_t* memory_;
// ...
};
问题: 根据委托类型的使用方法(例如 std::allocator)定义 noexcept 的最佳解决方案是什么? 当存在不同的重载时,必须做些什么——如果可能的话——使用委托类型的方法(例如,当不只提供一个时,我将如何使用特定的解除分配实现)?
【问题讨论】: