diff --git a/example/doc_avl_set.cpp b/example/doc_avl_set.cpp index 561298c..ae67689 100644 --- a/example/doc_avl_set.cpp +++ b/example/doc_avl_set.cpp @@ -12,7 +12,7 @@ //[doc_avl_set_code #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/example/doc_positional_insertion.cpp b/example/doc_positional_insertion.cpp index c851fbd..5d628a0 100644 --- a/example/doc_positional_insertion.cpp +++ b/example/doc_positional_insertion.cpp @@ -12,7 +12,7 @@ //[doc_positional_insertion #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/example/doc_set.cpp b/example/doc_set.cpp index a759e51..dae81ab 100644 --- a/example/doc_set.cpp +++ b/example/doc_set.cpp @@ -12,7 +12,7 @@ //[doc_set_code #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/example/doc_sg_set.cpp b/example/doc_sg_set.cpp index 576dbc7..4920a76 100644 --- a/example/doc_sg_set.cpp +++ b/example/doc_sg_set.cpp @@ -12,7 +12,7 @@ //[doc_sg_set_code #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/example/doc_splay_set.cpp b/example/doc_splay_set.cpp index 6c333b7..831fa03 100644 --- a/example/doc_splay_set.cpp +++ b/example/doc_splay_set.cpp @@ -12,7 +12,7 @@ //[doc_splay_set_code #include #include -#include +#include using namespace boost::intrusive; diff --git a/example/doc_treap_set.cpp b/example/doc_treap_set.cpp index e82cede..f8abbe5 100644 --- a/example/doc_treap_set.cpp +++ b/example/doc_treap_set.cpp @@ -12,7 +12,7 @@ //[doc_treap_set_code #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/example/doc_unordered_set.cpp b/example/doc_unordered_set.cpp index 5468026..ca0b5be 100644 --- a/example/doc_unordered_set.cpp +++ b/example/doc_unordered_set.cpp @@ -12,7 +12,7 @@ //[doc_unordered_set_code #include #include -#include +#include #include using namespace boost::intrusive; diff --git a/include/boost/intrusive/bstree.hpp b/include/boost/intrusive/bstree.hpp index 5a0023a..879dc01 100644 --- a/include/boost/intrusive/bstree.hpp +++ b/include/boost/intrusive/bstree.hpp @@ -38,15 +38,16 @@ #include #include #include +#include #include #include #include #include #include +#include -#include //pair,lexicographical_compare -#include //swap +#include //pair #include //size_t... #include //less, equal_to @@ -912,8 +913,7 @@ class bstree_impl void swap(bstree_impl& other) { //This can throw - using std::swap; - swap(this->comp(), this->comp()); + ::boost::adl_move_swap(this->comp(), this->comp()); //These can't throw node_algorithms::swap_tree(this->header_ptr(), node_ptr(other.header_ptr())); if(constant_time_size){ @@ -1952,7 +1952,7 @@ inline bool operator< ( const bstree_impl &x , const bstree_impl &y) #endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } +{ return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template @@ -1968,29 +1968,11 @@ bool operator== #endif { typedef bstree_impl tree_type; - typedef typename tree_type::const_iterator const_iterator; if(tree_type::constant_time_size && x.size() != y.size()){ return false; } - const_iterator end1 = x.end(); - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(tree_type::constant_time_size){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } + return boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) diff --git a/include/boost/intrusive/detail/algorithm.hpp b/include/boost/intrusive/detail/algorithm.hpp new file mode 100644 index 0000000..de0be63 --- /dev/null +++ b/include/boost/intrusive/detail/algorithm.hpp @@ -0,0 +1,86 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2014-2014. +// +// 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/intrusive for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP +#define BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP + +#if defined(_MSC_VER) +# pragma once +#endif + +namespace boost { +namespace intrusive { + +struct algo_pred_equal +{ + template + bool operator()(const T &x, const T &y) const + { return x == y; } +}; + +struct algo_pred_less +{ + template + bool operator()(const T &x, const T &y) const + { return x < y; } +}; + +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_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2) +{ return (algo_equal)(first1, last1, first2, algo_pred_equal()); } + +template +bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, BinaryPredicate pred) +{ + for (; first1 != last1 && first2 != last2; ++first1, ++first2) + if (!pred(*first1, *first2)) + return false; + return first1 == last1 && first2 == last2; +} + +template +bool algo_equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2) +{ return (algo_equal)(first1, last1, first2, last2, algo_pred_equal()); } + +template + bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, + BinaryPredicate pred) +{ + while (first1 != last1){ + if (first2 == last2 || *first2 < *first1) return false; + else if (pred(*first1, *first2)) return true; + ++first1; ++first2; + } + return (first2 != last2); +} + +template + bool algo_lexicographical_compare (InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2) +{ return (algo_lexicographical_compare)(first1, last1, first2, last2, algo_pred_less()); } + +} //namespace intrusive { +} //namespace boost { + +#endif //#ifndef BOOST_INTRUSIVE_DETAIL_ALGORITHM_HPP diff --git a/include/boost/intrusive/hashtable.hpp b/include/boost/intrusive/hashtable.hpp index 5cb2ae1..fa45bf1 100644 --- a/include/boost/intrusive/hashtable.hpp +++ b/include/boost/intrusive/hashtable.hpp @@ -18,15 +18,7 @@ #include #include -//std C++ -#include //std::equal_to -#include //std::pair -#include //std::swap, std::lower_bound, std::upper_bound -#include //std::size_t -//boost -#include -#include -#include + //General intrusive utilities #include #include @@ -44,7 +36,20 @@ #include #include #include + +//boost +#include +#include +#include #include +#include + +//std C++ +#include //std::equal_to +#include //std::pair +#include //std::lower_bound, std::upper_bound +#include //std::size_t + namespace boost { namespace intrusive { @@ -973,7 +978,7 @@ struct bucket_hash_equal_tcached_begin_, other.cached_begin_); + ::boost::adl_move_swap(this->cached_begin_, other.cached_begin_); } siterator priv_begin() const @@ -1510,13 +1515,12 @@ class hashtable_impl //! found using ADL throw. Basic guarantee. void swap(hashtable_impl& other) { - using std::swap; //These can throw - swap(this->priv_equal(), other.priv_equal()); - swap(this->priv_hasher(), other.priv_hasher()); + ::boost::adl_move_swap(this->priv_equal(), other.priv_equal()); + ::boost::adl_move_swap(this->priv_hasher(), other.priv_hasher()); //These can't throw - swap(this->priv_bucket_traits(), other.priv_bucket_traits()); - swap(this->priv_value_traits(), other.priv_value_traits()); + ::boost::adl_move_swap(this->priv_bucket_traits(), other.priv_bucket_traits()); + ::boost::adl_move_swap(this->priv_value_traits(), other.priv_value_traits()); this->priv_swap_cache(other); if(constant_time_size){ size_type backup = this->priv_size_traits().get_size(); diff --git a/include/boost/intrusive/list.hpp b/include/boost/intrusive/list.hpp index 426c002..ee31deb 100644 --- a/include/boost/intrusive/list.hpp +++ b/include/boost/intrusive/list.hpp @@ -38,13 +38,13 @@ #include #include #include +#include #include #include -#include -#include -#include +#include //std::less +#include //std::size_t, etc. namespace boost { namespace intrusive { @@ -1349,7 +1349,7 @@ inline bool operator< #else (const list_impl &x, const list_impl &y) #endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } +{ return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template @@ -1364,30 +1364,11 @@ bool operator== #endif { typedef list_impl list_type; - typedef typename list_type::const_iterator const_iterator; const bool C = list_type::constant_time_size; if(C && x.size() != y.size()){ return false; } - const_iterator end1 = x.end(); - - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(C){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } + return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) diff --git a/include/boost/intrusive/sgtree.hpp b/include/boost/intrusive/sgtree.hpp index 9ab46a7..232710e 100644 --- a/include/boost/intrusive/sgtree.hpp +++ b/include/boost/intrusive/sgtree.hpp @@ -24,12 +24,6 @@ #include #include -#include -#include -#include -#include -#include -#include #include #include #include @@ -42,7 +36,16 @@ #include #include #include + #include +#include + +#include +#include +#include +#include +#include + namespace boost { namespace intrusive { @@ -304,7 +307,7 @@ class sgtree_impl //! @copydoc ::boost::intrusive::bstree::bstree(bstree &&) sgtree_impl(BOOST_RV_REF(sgtree_impl) x) : tree_type(BOOST_MOVE_BASE(tree_type, x)), alpha_traits(x.get_alpha_traits()) - { std::swap(this->get_alpha_traits(), x.get_alpha_traits()); } + { ::boost::adl_move_swap(this->get_alpha_traits(), x.get_alpha_traits()); } //! @copydoc ::boost::intrusive::bstree::operator=(bstree &&) sgtree_impl& operator=(BOOST_RV_REF(sgtree_impl) x) @@ -402,9 +405,8 @@ class sgtree_impl void swap(sgtree_impl& other) { //This can throw - using std::swap; this->tree_type::swap(static_cast(other)); - swap(this->get_alpha_traits(), other.get_alpha_traits()); + ::boost::adl_move_swap(this->get_alpha_traits(), other.get_alpha_traits()); } //! @copydoc ::boost::intrusive::bstree::clone_from diff --git a/include/boost/intrusive/slist.hpp b/include/boost/intrusive/slist.hpp index 47b5636..fc44cca 100644 --- a/include/boost/intrusive/slist.hpp +++ b/include/boost/intrusive/slist.hpp @@ -40,12 +40,12 @@ #include #include #include +#include #include #include -#include -#include +#include //std::less #include //std::size_t #include //std::pair @@ -2056,7 +2056,7 @@ inline bool operator< ( const slist_impl &x , const slist_impl &y) #endif -{ return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } +{ return ::boost::intrusive::algo_lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) template @@ -2072,30 +2072,11 @@ bool operator== #endif { typedef slist_impl slist_type; - typedef typename slist_type::const_iterator const_iterator; const bool C = slist_type::constant_time_size; if(C && x.size() != y.size()){ return false; } - const_iterator end1 = x.end(); - - const_iterator i1 = x.begin(); - const_iterator i2 = y.begin(); - if(C){ - while (i1 != end1 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1; - } - else{ - const_iterator end2 = y.end(); - while (i1 != end1 && i2 != end2 && *i1 == *i2) { - ++i1; - ++i2; - } - return i1 == end1 && i2 == end2; - } + return ::boost::intrusive::algo_equal(x.cbegin(), x.cend(), y.cbegin(), y.cend()); } #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) diff --git a/include/boost/intrusive/treap.hpp b/include/boost/intrusive/treap.hpp index 7ef4bf8..0438f98 100644 --- a/include/boost/intrusive/treap.hpp +++ b/include/boost/intrusive/treap.hpp @@ -18,13 +18,8 @@ #include #include -#include -#include -#include -#include #include -#include #include #include #include @@ -34,11 +29,19 @@ #include #include #include -#include #include #include #include +#include +#include +#include + +#include +#include +#include + + namespace boost { namespace intrusive { @@ -329,8 +332,7 @@ class treap_impl { tree_type::swap(other); //This can throw - using std::swap; - swap(this->priv_pcomp(), other.priv_pcomp()); + ::boost::adl_move_swap(this->priv_pcomp(), other.priv_pcomp()); } //! Requires: Disposer::operator()(pointer) shouldn't throw. diff --git a/include/boost/intrusive/treap_algorithms.hpp b/include/boost/intrusive/treap_algorithms.hpp index 787c3d0..4094a43 100644 --- a/include/boost/intrusive/treap_algorithms.hpp +++ b/include/boost/intrusive/treap_algorithms.hpp @@ -25,7 +25,6 @@ #include #include #include -#include namespace boost { diff --git a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj index d376bd7..5490f93 100644 --- a/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj +++ b/proj/vc7ide/_intrusivelib/_intrusivelib.vcproj @@ -232,6 +232,9 @@ + + diff --git a/test/bounded_pointer.hpp b/test/bounded_pointer.hpp index 4859300..c5e8e9b 100644 --- a/test/bounded_pointer.hpp +++ b/test/bounded_pointer.hpp @@ -20,6 +20,7 @@ #include #include #include +#include template < typename T > class bounded_pointer; @@ -190,7 +191,7 @@ class bounded_reference // the copy asop is shallow; we need swap overload to shuffle a vector of references friend void swap(bounded_reference& lhs, bounded_reference& rhs) - { std::swap(lhs.m_offset, rhs.m_offset); } + { ::boost::adl_move_swap(lhs.m_offset, rhs.m_offset); } private: template friend class bounded_reference; diff --git a/test/smart_ptr.hpp b/test/smart_ptr.hpp index 2800430..724e9da 100644 --- a/test/smart_ptr.hpp +++ b/test/smart_ptr.hpp @@ -11,9 +11,10 @@ #ifndef BOOST_INTRUSIVE_SMART_PTR_HPP #define BOOST_INTRUSIVE_SMART_PTR_HPP -#include #include #include +#include +#include #if (defined _MSC_VER) # pragma once @@ -36,8 +37,7 @@ struct empty_type{}; template struct random_it -: public boost::iterator +: public iterator { typedef const T* const_pointer; typedef const T& const_reference; @@ -190,6 +190,10 @@ class smart_ptr //!Never throws. bool operator! () const { return m_ptr == 0; } + + //!swap + friend void swap(smart_ptr& x, smart_ptr& y) + { boost::adl_move_swap(x.m_ptr, y.m_ptr); } }; //!smart_ptr == smart_ptr. Never throws. @@ -250,16 +254,6 @@ template inline std::ptrdiff_t operator- (const smart_ptr &pt, const smart_ptr &pt2) { return pt.operator->()- pt2.operator->(); } -//!swap specialization -template -inline void swap (smart_ptr &pt, - smart_ptr &pt2) -{ - typename smart_ptr::value_type *ptr = pt.operator->(); - pt = pt2; - pt2 = ptr; -} - } //namespace intrusive { } //namespace boost { diff --git a/test/unordered_multiset_test.cpp b/test/unordered_multiset_test.cpp index 0d32635..bb0e234 100644 --- a/test/unordered_multiset_test.cpp +++ b/test/unordered_multiset_test.cpp @@ -17,7 +17,7 @@ #include "smart_ptr.hpp" #include "common_functors.hpp" #include -#include //std::sort std::find +#include //std::sort #include #include