Relative Content

Tag Archive for c++c++20

Need to call trivial destructor in standard compliant containers

I’m implementing my own version of standard-compliant containers. I read the following. It states that elements should be destroyed using the allocator destroy. Does it suggest a container must call the destructor of elements, even if it is trivial? My interpretation is we should first have the need to call the destructor. If so, we must use the allocator destroy. Otherwise, we don’t need to call allocator destroy either. Under this interpretation, we can skip calling allocator destroy for elements with a trivial destructor. This can lead to optimization in sequence containers.