From 621cd3a0ab49ecfaf1815d202fccaf2f228de2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Fri, 1 Jan 2021 23:44:56 +0100 Subject: [PATCH] Avoid using inheriting constructors and initializer_list::cbegin/cend to be nicer with older compilers --- include/boost/container/devector.hpp | 18 +++++++++++++++--- test/test_util.hpp | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/boost/container/devector.hpp b/include/boost/container/devector.hpp index 84d48e4..3d60ce4 100644 --- a/include/boost/container/devector.hpp +++ b/include/boost/container/devector.hpp @@ -351,9 +351,11 @@ class devector const size_type n = boost::container::iterator_distance(first, last); m_.buffer = n ? allocate(n) : pointer(); m_.front_idx = 0u; + //this->allocate(n) will take care of overflows m_.set_back_idx(n); m_.set_capacity(n); - construct_from_range(first, last); + //construct_from_range releases memory on failure + this->construct_from_range(first, last); BOOST_ASSERT(invariants_ok()); } @@ -464,8 +466,18 @@ class devector * **Equivalent to**: `devector(il.begin(), il.end())` or `devector(il.begin(), il.end(), allocator)`. */ devector(const std::initializer_list& il, const allocator_type& allocator = allocator_type()) - : devector(il.begin(), il.end(), allocator) - {} + : m_(allocator, pointer(), 0u, 0u, 0u) + { + const size_type n = il.size(); + m_.buffer = n ? allocate(n) : pointer(); + m_.front_idx = 0u; + //this->allocate(n) will take care of overflows + m_.set_back_idx(n); + m_.set_capacity(n); + //construct_from_range releases memory on failure + this->construct_from_range(il.begin(), il.end()); + BOOST_ASSERT(invariants_ok()); + } #endif /** diff --git a/test/test_util.hpp b/test/test_util.hpp index f2db77b..0c9d2c9 100644 --- a/test/test_util.hpp +++ b/test/test_util.hpp @@ -73,7 +73,7 @@ void print_range(std::ostream& out, Iterator b, Iterator e) template void print_range(std::ostream& out, const Range& range) { - print_range(out, range.cbegin(), range.cend()); + print_range(out, range.begin(), range.end()); } template