Why is the clear() function noexcept while the destructor not?

150 views Asked by At

I noticed that, in the allocator-aware containers interface, the standard requires that the clear() member function be noexcept while the destructor not. Furthermore, it appears a discrepancy in the case of some node-based containers, such as std::forward_list and std::set, since the clear() member function performs the same operation as the destructor. Is there any reason for this difference?

1

There are 1 answers

0
Mestkon On BEST ANSWER

Destructors are implicitly noexcept unless any of the member variable destructors or base class destructors have been marked with noexcept(false) or the destructor itself is explicitly marked with noexcept(false).