From afd1c2d2660415c4e9a54590e3fce3560964791a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Wed, 26 Nov 2014 19:33:27 +0100 Subject: [PATCH] Use boost::adl_move_swap instead of own swap utility Imported basic algorithms from Boost.Intrusive --- bench/detail/varray.hpp | 11 +-- include/boost/container/detail/algorithm.hpp | 37 +--------- include/boost/container/detail/pair.hpp | 7 +- include/boost/container/detail/swap.hpp | 77 -------------------- 4 files changed, 14 insertions(+), 118 deletions(-) delete mode 100644 include/boost/container/detail/swap.hpp diff --git a/bench/detail/varray.hpp b/bench/detail/varray.hpp index dd01646..6629ad3 100644 --- a/bench/detail/varray.hpp +++ b/bench/detail/varray.hpp @@ -21,12 +21,13 @@ #include //algo_equal(), algo_lexicographical_compare #include #include +#include //adl_move_swap #include "varray_util.hpp" #include #include -#include + #include #include @@ -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 diff --git a/include/boost/container/detail/algorithm.hpp b/include/boost/container/detail/algorithm.hpp index bb1854d..ddf8857 100644 --- a/include/boost/container/detail/algorithm.hpp +++ b/include/boost/container/detail/algorithm.hpp @@ -17,42 +17,13 @@ # pragma once #endif +#include + namespace boost { namespace container { -template -bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) -{ - for (; first1 != last1; ++first1, ++first2) { - if (!(*first1 == *first2)) { - return false; - } - } - return true; -} - -template -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 - 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 { diff --git a/include/boost/container/detail/pair.hpp b/include/boost/container/detail/pair.hpp index 457174a..91e4d1e 100644 --- a/include/boost/container/detail/pair.hpp +++ b/include/boost/container/detail/pair.hpp @@ -24,9 +24,10 @@ #include #include #include +#include //swap #include //std::pair -#include //swap + #include @@ -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); } }; diff --git a/include/boost/container/detail/swap.hpp b/include/boost/container/detail/swap.hpp deleted file mode 100644 index f3c902d..0000000 --- a/include/boost/container/detail/swap.hpp +++ /dev/null @@ -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 //for std::size_t -#include //for boost::move - -namespace boost_container_swap_move { - template - 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 - 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 - 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 -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