mirror of
https://github.com/boostorg/container.git
synced 2025-08-03 14:34:27 +02:00
Use boost::adl_move_swap instead of own swap utility
Imported basic algorithms from Boost.Intrusive
This commit is contained in:
@@ -21,12 +21,13 @@
|
||||
#include <boost/container/detail/algorithm.hpp> //algo_equal(), algo_lexicographical_compare
|
||||
#include <boost/container/detail/iterator.hpp>
|
||||
#include <boost/container/detail/iterators.hpp>
|
||||
#include <boost/move/adl_move_swap.hpp> //adl_move_swap
|
||||
|
||||
#include "varray_util.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/swap.hpp>
|
||||
|
||||
#include <boost/integer.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
@@ -1556,7 +1557,7 @@ private:
|
||||
this->clear();
|
||||
|
||||
::memcpy(this->data(), other.data(), sizeof(Value) * other.m_size);
|
||||
boost::swap(m_size, other.m_size);
|
||||
boost::adl_move_swap(m_size, other.m_size);
|
||||
}
|
||||
|
||||
// @par Throws
|
||||
@@ -1604,7 +1605,7 @@ private:
|
||||
::memcpy(this->data(), other.data(), sizeof(Value) * other.size());
|
||||
::memcpy(other.data(), temp_ptr, sizeof(Value) * this->size());
|
||||
|
||||
boost::swap(m_size, other.m_size);
|
||||
boost::adl_move_swap(m_size, other.m_size);
|
||||
}
|
||||
|
||||
// @par Throws
|
||||
@@ -1624,7 +1625,7 @@ private:
|
||||
swap_dispatch_impl(this->begin(), this->end(), other.begin(), other.end(), use_memop_in_swap_and_move()); // may throw
|
||||
else
|
||||
swap_dispatch_impl(other.begin(), other.end(), this->begin(), this->end(), use_memop_in_swap_and_move()); // may throw
|
||||
boost::swap(m_size, other.m_size);
|
||||
boost::adl_move_swap(m_size, other.m_size);
|
||||
}
|
||||
|
||||
// @par Throws
|
||||
@@ -1663,7 +1664,7 @@ private:
|
||||
namespace sv = varray_detail;
|
||||
for (; first_sm != last_sm ; ++first_sm, ++first_la)
|
||||
{
|
||||
//boost::swap(*first_sm, *first_la); // may throw
|
||||
//boost::adl_move_swap(*first_sm, *first_la); // may throw
|
||||
value_type temp(boost::move(*first_sm)); // may throw
|
||||
*first_sm = boost::move(*first_la); // may throw
|
||||
*first_la = boost::move(temp); // may throw
|
||||
|
@@ -17,42 +17,13 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/intrusive/detail/algorithm.hpp>
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
|
||||
template<class InputIt1, class InputIt2>
|
||||
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
|
||||
{
|
||||
for (; first1 != last1; ++first1, ++first2) {
|
||||
if (!(*first1 == *first2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class InputIt1, class InputIt2, class BinaryPredicate>
|
||||
bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
|
||||
{
|
||||
for (; first1 != last1; ++first1, ++first2) {
|
||||
if (!p(*first1, *first2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class InputIterator1, class InputIterator2>
|
||||
bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1,
|
||||
InputIterator2 first2, InputIterator2 last2)
|
||||
{
|
||||
while (first1 != last1){
|
||||
if (first2 == last2 || *first2 < *first1) return false;
|
||||
else if (*first1 < *first2) return true;
|
||||
++first1; ++first2;
|
||||
}
|
||||
return (first2 != last2);
|
||||
}
|
||||
using boost::intrusive::algo_equal;
|
||||
using boost::intrusive::algo_lexicographical_compare;
|
||||
|
||||
} //namespace container {
|
||||
} //namespace boost {
|
||||
|
@@ -24,9 +24,10 @@
|
||||
#include <boost/container/detail/type_traits.hpp>
|
||||
#include <boost/container/detail/mpl.hpp>
|
||||
#include <boost/container/detail/type_traits.hpp>
|
||||
#include <boost/move/adl_move_swap.hpp> //swap
|
||||
|
||||
#include <utility> //std::pair
|
||||
#include <boost/container/detail/swap.hpp> //swap
|
||||
|
||||
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
@@ -272,8 +273,8 @@ struct pair
|
||||
//swap
|
||||
void swap(pair& p)
|
||||
{
|
||||
::boost::container::adl_swap(this->first, p.first);
|
||||
::boost::container::adl_swap(this->second, p.second);
|
||||
::boost::adl_move_swap(this->first, p.first);
|
||||
::boost::adl_move_swap(this->second, p.second);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,77 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright 2007, 2008 Steven Watanabe, Joseph Gauterin, Niels Dekker
|
||||
// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
|
||||
// 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.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef BOOST_CONTAINER_DETAIL_SWAP_HPP
|
||||
#define BOOST_CONTAINER_DETAIL_SWAP_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
//Based on Boost.Core's swap, but defaulting to a move-enabled swap.
|
||||
//
|
||||
// Note: the implementation of this utility contains various workarounds:
|
||||
// - swap_impl is put outside the boost namespace, to avoid infinite
|
||||
// recursion (causing stack overflow) when swapping objects of a primitive
|
||||
// type.
|
||||
// - swap_impl has a using-directive, rather than a using-declaration,
|
||||
// because some compilers (including MSVC 7.1, Borland 5.9.3, and
|
||||
// Intel 8.1) don't do argument-dependent lookup when it has a
|
||||
// using-declaration instead.
|
||||
// - boost::swap has two template arguments, instead of one, to
|
||||
// avoid ambiguity when swapping objects of a Boost type that does
|
||||
// not have its own boost::swap overload.
|
||||
|
||||
#include <cstddef> //for std::size_t
|
||||
#include <boost/move/utility_core.hpp> //for boost::move
|
||||
|
||||
namespace boost_container_swap_move {
|
||||
template<class T>
|
||||
void swap(T& left, T& right)
|
||||
{
|
||||
T tmp(::boost::move(left));
|
||||
left = ::boost::move(right);
|
||||
right = ::boost::move(tmp);
|
||||
}
|
||||
} //namespace boost_container_swap_move {
|
||||
|
||||
namespace boost_container_swap
|
||||
{
|
||||
template<class T>
|
||||
void adl_swap_impl(T& left, T& right)
|
||||
{
|
||||
//use boost_container_swap_move::swap if argument dependent lookup fails
|
||||
using namespace boost_container_swap_move;
|
||||
swap(left,right);
|
||||
}
|
||||
|
||||
template<class T, std::size_t N>
|
||||
void adl_swap_impl(T (& left)[N], T (& right)[N])
|
||||
{
|
||||
for (std::size_t i = 0; i < N; ++i){
|
||||
::boost_container_swap::adl_swap_impl(left[i], right[i]);
|
||||
}
|
||||
}
|
||||
} //namespace boost_container_swap {
|
||||
|
||||
namespace boost{
|
||||
namespace container{
|
||||
|
||||
template<class T1, class T2>
|
||||
void adl_swap(T1& left, T2& right)
|
||||
{
|
||||
::boost_container_swap::adl_swap_impl(left, right);
|
||||
}
|
||||
|
||||
} //namespace container{
|
||||
} //namespace boost{
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DETAIL_SWAP_HPP
|
Reference in New Issue
Block a user