2011-08-26 18:25:51 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2012-03-22 18:46:55 +00:00
|
|
|
// (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
|
2011-08-26 18:25:51 +00:00
|
|
|
// Software License, Version 1.0. (See accompanying file
|
|
|
|
|
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
//
|
|
|
|
|
// See http://www.boost.org/libs/container for documentation.
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
#ifndef BOOST_CONTAINER_DETAIL_UTILITIES_HPP
|
|
|
|
|
#define BOOST_CONTAINER_DETAIL_UTILITIES_HPP
|
2011-08-26 18:25:51 +00:00
|
|
|
|
|
|
|
|
#include "config_begin.hpp"
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <boost/type_traits/is_fundamental.hpp>
|
|
|
|
|
#include <boost/type_traits/is_pointer.hpp>
|
|
|
|
|
#include <boost/type_traits/is_enum.hpp>
|
|
|
|
|
#include <boost/type_traits/is_member_pointer.hpp>
|
|
|
|
|
#include <boost/type_traits/is_class.hpp>
|
2013-02-19 21:35:46 +00:00
|
|
|
#include <boost/type_traits/has_trivial_destructor.hpp>
|
2012-11-24 21:08:18 +00:00
|
|
|
#include <boost/move/utility.hpp>
|
|
|
|
|
#include <boost/move/iterator.hpp>
|
2011-08-26 18:25:51 +00:00
|
|
|
#include <boost/container/detail/mpl.hpp>
|
|
|
|
|
#include <boost/container/detail/type_traits.hpp>
|
2012-03-22 18:46:55 +00:00
|
|
|
#include <boost/container/allocator_traits.hpp>
|
2012-11-24 21:08:18 +00:00
|
|
|
#include <boost/detail/no_exceptions_support.hpp>
|
2011-08-26 18:25:51 +00:00
|
|
|
#include <algorithm>
|
2012-11-24 21:08:18 +00:00
|
|
|
#include <iterator>
|
2011-08-26 18:25:51 +00:00
|
|
|
|
|
|
|
|
namespace boost {
|
|
|
|
|
namespace container {
|
2011-12-22 20:08:24 +00:00
|
|
|
namespace container_detail {
|
2011-08-26 18:25:51 +00:00
|
|
|
|
2012-03-22 18:46:55 +00:00
|
|
|
template <typename T>
|
|
|
|
|
inline T* addressof(T& obj)
|
|
|
|
|
{
|
|
|
|
|
return static_cast<T*>(
|
|
|
|
|
static_cast<void*>(
|
|
|
|
|
const_cast<char*>(
|
|
|
|
|
&reinterpret_cast<const char&>(obj)
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 18:25:51 +00:00
|
|
|
template<class T>
|
|
|
|
|
const T &max_value(const T &a, const T &b)
|
|
|
|
|
{ return a > b ? a : b; }
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
|
const T &min_value(const T &a, const T &b)
|
|
|
|
|
{ return a < b ? a : b; }
|
|
|
|
|
|
|
|
|
|
template <class SizeType>
|
|
|
|
|
SizeType
|
|
|
|
|
get_next_capacity(const SizeType max_size
|
|
|
|
|
,const SizeType capacity
|
|
|
|
|
,const SizeType n)
|
|
|
|
|
{
|
|
|
|
|
// if (n > max_size - capacity)
|
|
|
|
|
// throw std::length_error("get_next_capacity");
|
|
|
|
|
|
|
|
|
|
const SizeType m3 = max_size/3;
|
|
|
|
|
|
|
|
|
|
if (capacity < m3)
|
|
|
|
|
return capacity + max_value(3*(capacity+1)/5, n);
|
|
|
|
|
|
|
|
|
|
if (capacity < m3*2)
|
|
|
|
|
return capacity + max_value((capacity+1)/2, n);
|
|
|
|
|
|
|
|
|
|
return max_size;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
template <class T>
|
|
|
|
|
inline T* to_raw_pointer(T* p)
|
|
|
|
|
{ return p; }
|
2011-08-26 18:25:51 +00:00
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
template <class Pointer>
|
|
|
|
|
inline typename Pointer::element_type*
|
|
|
|
|
to_raw_pointer(const Pointer &p)
|
|
|
|
|
{ return boost::container::container_detail::to_raw_pointer(p.operator->()); }
|
2011-08-26 18:25:51 +00:00
|
|
|
|
|
|
|
|
//!To avoid ADL problems with swap
|
|
|
|
|
template <class T>
|
|
|
|
|
inline void do_swap(T& x, T& y)
|
|
|
|
|
{
|
|
|
|
|
using std::swap;
|
|
|
|
|
swap(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void swap_alloc(AllocatorType &, AllocatorType &, container_detail::false_type)
|
|
|
|
|
BOOST_CONTAINER_NOEXCEPT
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void swap_alloc(AllocatorType &l, AllocatorType &r, container_detail::true_type)
|
|
|
|
|
{ container_detail::do_swap(l, r); }
|
|
|
|
|
|
|
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void assign_alloc(AllocatorType &, const AllocatorType &, container_detail::false_type)
|
|
|
|
|
BOOST_CONTAINER_NOEXCEPT
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void assign_alloc(AllocatorType &l, const AllocatorType &r, container_detail::true_type)
|
|
|
|
|
{ l = r; }
|
|
|
|
|
|
|
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void move_alloc(AllocatorType &, AllocatorType &, container_detail::false_type)
|
|
|
|
|
BOOST_CONTAINER_NOEXCEPT
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
template<class AllocatorType>
|
|
|
|
|
inline void move_alloc(AllocatorType &l, AllocatorType &r, container_detail::true_type)
|
|
|
|
|
{ l = ::boost::move(r); }
|
|
|
|
|
|
2011-08-26 18:25:51 +00:00
|
|
|
//Rounds "orig_size" by excess to round_to bytes
|
|
|
|
|
template<class SizeType>
|
|
|
|
|
inline SizeType get_rounded_size(SizeType orig_size, SizeType round_to)
|
|
|
|
|
{
|
|
|
|
|
return ((orig_size-1)/round_to+1)*round_to;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <std::size_t OrigSize, std::size_t RoundTo>
|
|
|
|
|
struct ct_rounded_size
|
|
|
|
|
{
|
|
|
|
|
enum { value = ((OrigSize-1)/RoundTo+1)*RoundTo };
|
|
|
|
|
};
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
} //namespace container_detail {
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_move_alloc
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; f != l; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, boost::move(*f));
|
2011-12-22 20:08:24 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: r
|
2011-12-22 20:08:24 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_move_alloc(A &a, I f, I l, F r)
|
|
|
|
|
{
|
2012-11-24 21:08:18 +00:00
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), boost::move(*f));
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_move_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, boost::move(*f));
|
2012-11-24 21:08:18 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: r
|
2012-11-24 21:08:18 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_move_alloc_n(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), boost::move(*f));
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
2011-12-22 20:08:24 +00:00
|
|
|
}
|
2012-11-24 21:08:18 +00:00
|
|
|
BOOST_CATCH_END
|
2011-12-22 20:08:24 +00:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 21:08:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_move_alloc_n_source
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, boost::move(*f));
|
2012-11-24 21:08:18 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: f (after incremented)
|
2012-11-24 21:08:18 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
I uninitialized_move_alloc_n_source(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), boost::move(*f));
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_alloc
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; f != l; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, *f);
|
2011-12-22 20:08:24 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: r
|
2011-12-22 20:08:24 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_alloc(A &a, I f, I l, F r)
|
|
|
|
|
{
|
2012-11-24 21:08:18 +00:00
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), *f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
2011-12-22 20:08:24 +00:00
|
|
|
}
|
2012-11-24 21:08:18 +00:00
|
|
|
BOOST_CATCH_END
|
2011-12-22 20:08:24 +00:00
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 21:08:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, *f);
|
2012-11-24 21:08:18 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: r
|
2012-11-24 21:08:18 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_alloc_n(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), *f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_alloc_n_source
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, *f);
|
2012-11-24 21:08:18 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: f (after incremented)
|
2012-11-24 21:08:18 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
I uninitialized_copy_alloc_n_source(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), *f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_alloc
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
2013-02-14 19:43:13 +00:00
|
|
|
//! for (; f != l; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, *f);
|
2011-12-22 20:08:24 +00:00
|
|
|
//! \endcode
|
|
|
|
|
//!
|
2013-02-14 19:43:13 +00:00
|
|
|
//! <b>Returns</b>: r
|
2011-12-22 20:08:24 +00:00
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename F, // F models ForwardIterator
|
2012-05-20 10:02:49 +00:00
|
|
|
typename T>
|
2011-12-22 20:08:24 +00:00
|
|
|
void uninitialized_fill_alloc(A &a, F f, F l, const T &t)
|
|
|
|
|
{
|
2012-11-24 21:08:18 +00:00
|
|
|
F back = f;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*f), t);
|
|
|
|
|
++f;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != l; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
2011-12-22 20:08:24 +00:00
|
|
|
}
|
2012-11-24 21:08:18 +00:00
|
|
|
BOOST_CATCH_END
|
2011-12-22 20:08:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_or_move_alloc
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_or_move_alloc
|
|
|
|
|
(A &a, I f, I l, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_move_alloc(a, f, l, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_or_move_alloc
|
|
|
|
|
(A &a, I f, I l, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_copy_alloc(a, f, l, r);
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 21:08:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_or_move_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_or_move_alloc_n
|
|
|
|
|
(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_move_alloc_n(a, f, n, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_copy_or_move_alloc_n
|
|
|
|
|
(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_copy_alloc_n(a, f, n, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_copy_or_move_alloc_n_source
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
I uninitialized_copy_or_move_alloc_n_source
|
|
|
|
|
(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_move_alloc_n_source(a, f, n, r);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I // I models InputIterator
|
|
|
|
|
,typename F> // F models ForwardIterator
|
|
|
|
|
I uninitialized_copy_or_move_alloc_n_source
|
|
|
|
|
(A &a, I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
return ::boost::container::uninitialized_copy_alloc_n_source(a, f, n, r);
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-14 19:43:13 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_default_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
|
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r);
|
|
|
|
|
//! \endcode
|
|
|
|
|
//!
|
|
|
|
|
//! <b>Returns</b>: r
|
|
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_default_alloc_n(A &a, typename allocator_traits<A>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r));
|
|
|
|
|
++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// uninitialized_fill_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//! <b>Effects</b>:
|
|
|
|
|
//! \code
|
|
|
|
|
//! for (; n--; ++r, ++f)
|
|
|
|
|
//! allocator_traits::construct(a, &*r, v);
|
|
|
|
|
//! \endcode
|
|
|
|
|
//!
|
|
|
|
|
//! <b>Returns</b>: r
|
|
|
|
|
template
|
|
|
|
|
<typename A,
|
|
|
|
|
typename T,
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
F uninitialized_fill_alloc_n(A &a, const T &v, typename allocator_traits<A>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
F back = r;
|
|
|
|
|
BOOST_TRY{
|
|
|
|
|
while (n--) {
|
|
|
|
|
allocator_traits<A>::construct(a, container_detail::to_raw_pointer(&*r), v);
|
|
|
|
|
++r;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH(...){
|
|
|
|
|
for (; back != r; ++back){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::to_raw_pointer(&*back));
|
|
|
|
|
}
|
|
|
|
|
BOOST_RETHROW;
|
|
|
|
|
}
|
|
|
|
|
BOOST_CATCH_END
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-24 21:08:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// copy_or_move
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F copy_or_move(I f, I l, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F copy_or_move(I f, I l, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
*r = *f;
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// copy_or_move_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F copy_or_move_n(I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F copy_or_move_n(I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = *f;
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// copy_or_move_n_source
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline I copy_or_move_n_source(I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::enable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline I copy_or_move_n_source(I f, typename std::iterator_traits<I>::difference_type n, F r
|
|
|
|
|
,typename boost::container::container_detail::disable_if
|
|
|
|
|
< boost::move_detail::is_move_iterator<I> >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = *f;
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return f;
|
|
|
|
|
}
|
2012-03-22 18:46:55 +00:00
|
|
|
|
2013-02-12 21:26:21 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// move
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F move(I f, I l, F r)
|
|
|
|
|
{
|
|
|
|
|
while (f != l) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// move_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline F move_n(I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// move_n_source
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename I, // I models InputIterator
|
|
|
|
|
typename F> // F models ForwardIterator
|
|
|
|
|
inline I move_n_source(I f, typename std::iterator_traits<I>::difference_type n, F r)
|
|
|
|
|
{
|
|
|
|
|
while (n--) {
|
|
|
|
|
*r = ::boost::move(*f);
|
|
|
|
|
++f; ++r;
|
|
|
|
|
}
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-19 21:35:46 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// destroy_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I> // I models InputIterator
|
|
|
|
|
inline void destroy_alloc_n(A &a, I f, typename std::iterator_traits<I>::difference_type n
|
|
|
|
|
,typename boost::container::container_detail::enable_if_c
|
|
|
|
|
< !boost::has_trivial_destructor<typename std::iterator_traits<I>::value_type>::value >::type* = 0)
|
|
|
|
|
{
|
|
|
|
|
while(n--){
|
|
|
|
|
allocator_traits<A>::destroy(a, container_detail::addressof(*f++));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename I> // I models InputIterator
|
|
|
|
|
inline void destroy_alloc_n(A &, I, typename std::iterator_traits<I>::difference_type
|
|
|
|
|
,typename boost::container::container_detail::enable_if_c
|
|
|
|
|
< boost::has_trivial_destructor<typename std::iterator_traits<I>::value_type>::value >::type* = 0)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// deep_swap_alloc_n
|
|
|
|
|
//
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
template
|
|
|
|
|
<typename A
|
|
|
|
|
,typename F // I models ForwardIterator
|
|
|
|
|
,typename G // G models ForwardIterator
|
|
|
|
|
>
|
|
|
|
|
void deep_swap_alloc_n(A &a, F short_range_f, typename allocator_traits<A>::size_type n_i
|
|
|
|
|
, G large_range_f, typename allocator_traits<A>::size_type n_j)
|
|
|
|
|
{
|
|
|
|
|
typename allocator_traits<A>::size_type n = 0;
|
|
|
|
|
typedef typename allocator_traits<A>::value_type value_type;
|
|
|
|
|
for (; n != n_i ; ++short_range_f, ++large_range_f, ++n){
|
|
|
|
|
//boost::swap(*first_sm, *first_la); // may throw
|
|
|
|
|
value_type temp(boost::move(*short_range_f)); // may throw
|
|
|
|
|
*short_range_f = boost::move(*large_range_f); // may throw
|
|
|
|
|
*large_range_f = boost::move(temp); // may throw
|
|
|
|
|
}
|
|
|
|
|
uninitialized_move_alloc_n(a, large_range_f, n_j - n, short_range_f); // may throw
|
|
|
|
|
destroy_alloc_n(a, large_range_f, n_j - n);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-26 18:25:51 +00:00
|
|
|
} //namespace container {
|
|
|
|
|
} //namespace boost {
|
|
|
|
|
|
|
|
|
|
#include <boost/container/detail/config_end.hpp>
|
|
|
|
|
|
2011-12-22 20:08:24 +00:00
|
|
|
#endif //#ifndef BOOST_CONTAINER_DETAIL_UTILITIES_HPP
|