Subject: Re: [boost] devector feedback request
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2015-07-30 11:01:48
On Sun, Jul 26, 2015 at 11:53 AM, Benedek Thaler <thalerbenedek_at_[hidden]>
> On Sun, Jul 26, 2015 at 5:54 PM, Glen Fernandes <glen.fernandes_at_[hidden]>
> > Some feedback:
> Thanks for the feedback!
> > 1. For a given type T whose constructor can throw, and you have a loop
> > constructing n objects of type T via
> > std::allocator_traits<T>::construct - should you not be handling that
> > potential construction failure? (i.e. Destroying those elements that
> > were constructed before the constructor that throws, before
> > re-throwing)
> > [snip]
> > (My apologies if you already do this, and I missed it).
> There are two such constructors:
> explicit devector(size_type n, const Allocator& allocator = Allocator())
> devector(size_type n, const T& value, const Allocator& allocator =
> The first one has a `construction_guard` which takes care cleanup on
> failure. The second one calls `opt_copy` at the end, which also has the
> same kind of guard if needed.
> The failure scenario for both constructor (and for other metods) is tested:
> Did I missed something?
An alternate approach, if you can require C++11, is to use "delegating
See libc++'s dynarray implementation for an example of this.
default constructor at line 138, other constructor at line 231)
* Call the default constructor first. That can be noexcept.
* Insert the elements, one by one, maintaining the class invariants.
* If one of the insertions throws, then the destructor will be called, and
it can do the cleanup.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk