September 2017
Beginner to intermediate
384 pages
9h 18m
English
The <memory> header provides an obscure family of algorithms with names such as std::uninitialized_copy, std::uninitialized_default_construct, and std::destroy (for the full list, consult an online reference such as cppreference.com). Consider the following algorithm that uses explicit destructor calls to destroy the elements of a range:
template<class T> void destroy_at(T *p) { p->~T(); } template<class FwdIt> void destroy(FwdIt first, FwdIt last) { for ( ; first != last; ++first) { std::destroy_at(std::addressof(*first)); } }
Notice that std::addressof(x) is a convenient little helper function that returns the address of its parameter; it's exactly the same thing as &x except in the rare case that ...
Read now
Unlock full access