diff --git a/include/boost/container/detail/advanced_insert_int.hpp b/include/boost/container/detail/advanced_insert_int.hpp index 3cecc3f..0b09fdd 100644 --- a/include/boost/container/detail/advanced_insert_int.hpp +++ b/include/boost/container/detail/advanced_insert_int.hpp @@ -37,15 +37,15 @@ struct move_insert_range_proxy : a_(a), first_(first) {} - void uninitialized_copy_n_and_update(Iterator pos, size_type n) + void uninitialized_copy_n_and_update(Iterator p, size_type n) { this->first_ = ::boost::container::uninitialized_move_alloc_n_source - (this->a_, this->first_, n, pos); + (this->a_, this->first_, n, p); } - void copy_n_and_update(Iterator pos, size_type n) + void copy_n_and_update(Iterator p, size_type n) { - this->first_ = ::boost::container::move_n_source(this->first_, n, pos); + this->first_ = ::boost::container::move_n_source(this->first_, n, p); } A &a_; @@ -63,15 +63,15 @@ struct insert_range_proxy : a_(a), first_(first) {} - void uninitialized_copy_n_and_update(Iterator pos, size_type n) + void uninitialized_copy_n_and_update(Iterator p, size_type n) { this->first_ = ::boost::container::uninitialized_copy_or_move_alloc_n_source - (this->a_, this->first_, n, pos); + (this->a_, this->first_, n, p); } - void copy_n_and_update(Iterator pos, size_type n) + void copy_n_and_update(Iterator p, size_type n) { - this->first_ = ::boost::container::copy_or_move_n_source(this->first_, n, pos); + this->first_ = ::boost::container::copy_or_move_n_source(this->first_, n, p); } A &a_; @@ -90,7 +90,7 @@ struct insert_n_copies_proxy {} void uninitialized_copy_n_and_update(Iterator p, size_type n) - { std::uninitialized_fill_n(p, n, v_); } + { boost::container::uninitialized_fill_alloc_n(this->a_, v_, n, p); } void copy_n_and_update(Iterator p, size_type n) { std::fill_n(p, n, v_); } @@ -112,22 +112,7 @@ struct insert_default_constructed_n_proxy {} void uninitialized_copy_n_and_update(Iterator p, size_type n) - { - Iterator orig_p = p; - size_type n_left = n; - BOOST_TRY{ - for(; n_left--; ++p){ - alloc_traits::construct(this->a_, container_detail::to_raw_pointer(&*p)); - } - } - BOOST_CATCH(...){ - for(; orig_p != p; ++orig_p){ - alloc_traits::destroy(this->a_, container_detail::to_raw_pointer(&*orig_p++)); - } - BOOST_RETHROW - } - BOOST_CATCH_END - } + { boost::container::uninitialized_default_alloc_n(this->a_, n, p); } void copy_n_and_update(Iterator, size_type) { diff --git a/include/boost/container/detail/utilities.hpp b/include/boost/container/detail/utilities.hpp index d9905ce..23489db 100644 --- a/include/boost/container/detail/utilities.hpp +++ b/include/boost/container/detail/utilities.hpp @@ -136,11 +136,11 @@ struct ct_rounded_size //! Effects: //! \code -//! for (; first != last; ++result, ++first) -//! allocator_traits::construct(a, &*result, boost::move(*first)); +//! for (; f != l; ++r, ++f) +//! allocator_traits::construct(a, &*r, boost::move(*f)); //! \endcode //! -//! Returns: result +//! Returns: r template Effects: //! \code -//! for (; n--; ++result, ++first) -//! allocator_traits::construct(a, &*result, boost::move(*first)); +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r, boost::move(*f)); //! \endcode //! -//! Returns: result +//! Returns: r template ::differ //! Effects: //! \code -//! for (; n--; ++result, ++first) -//! allocator_traits::construct(a, &*result, boost::move(*first)); +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r, boost::move(*f)); //! \endcode //! -//! Returns: first (after incremented) +//! Returns: f (after incremented) template : //! Effects: //! \code -//! for (; first != last; ++result, ++first) -//! allocator_traits::construct(a, &*result, *first); +//! for (; f != l; ++r, ++f) +//! allocator_traits::construct(a, &*r, *f); //! \endcode //! -//! Returns: result +//! Returns: r template Effects: //! \code -//! for (; n--; ++result, ++first) -//! allocator_traits::construct(a, &*result, *first); +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r, *f); //! \endcode //! -//! Returns: result +//! Returns: r template ::differ //! Effects: //! \code -//! for (; n--; ++result, ++first) -//! allocator_traits::construct(a, &*result, *first); +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r, *f); //! \endcode //! -//! Returns: first (after incremented) +//! Returns: f (after incremented) template : //! Effects: //! \code -//! for (; first != last; ++result, ++first) -//! allocator_traits::construct(a, &*result, *first); +//! for (; f != l; ++r, ++f) +//! allocator_traits::construct(a, &*r, *f); //! \endcode //! -//! Returns: result +//! Returns: r template Effects: +//! \code +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r); +//! \endcode +//! +//! Returns: r +template + // F models ForwardIterator +F uninitialized_default_alloc_n(A &a, typename allocator_traits::difference_type n, F r) +{ + F back = r; + BOOST_TRY{ + while (n--) { + allocator_traits::construct(a, container_detail::to_raw_pointer(&*r)); + ++r; + } + } + BOOST_CATCH(...){ + for (; back != r; ++back){ + allocator_traits::destroy(a, container_detail::to_raw_pointer(&*back)); + } + BOOST_RETHROW; + } + BOOST_CATCH_END + return r; +} + + +////////////////////////////////////////////////////////////////////////////// +// +// uninitialized_fill_alloc_n +// +////////////////////////////////////////////////////////////////////////////// + +//! Effects: +//! \code +//! for (; n--; ++r, ++f) +//! allocator_traits::construct(a, &*r, v); +//! \endcode +//! +//! Returns: r +template + // F models ForwardIterator +F uninitialized_fill_alloc_n(A &a, const T &v, typename allocator_traits::difference_type n, F r) +{ + F back = r; + BOOST_TRY{ + while (n--) { + allocator_traits::construct(a, container_detail::to_raw_pointer(&*r), v); + ++r; + } + } + BOOST_CATCH(...){ + for (; back != r; ++back){ + allocator_traits::destroy(a, container_detail::to_raw_pointer(&*back)); + } + BOOST_RETHROW; + } + BOOST_CATCH_END + return r; +} + ////////////////////////////////////////////////////////////////////////////// // // copy_or_move @@ -631,7 +703,6 @@ inline I move_n_source(I f, typename std::iterator_traits::difference_type n, } //namespace container { } //namespace boost { - #include #endif //#ifndef BOOST_CONTAINER_DETAIL_UTILITIES_HPP