From 547c964381f3808c818e7eb6a97fbd673c959456 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Tue, 5 Jan 2021 10:09:01 +0100 Subject: [PATCH] - Reduced compile-time dependencies: - linear_slist_algorithms use a simple node_ptr instead of std::pair on return. - list/slist use operator +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) +# pragma once +#endif + +//A tiny utility to avoid pulling std::pair / utility for +//very simple algorithms/types + +namespace boost { +namespace intrusive { + +template +struct twin +{ + typedef T type; + twin() + : first(), second() + {} + + T first; + T second; +}; + +} //namespace intrusive{ +} //namespace boost{ + +#endif //BOOST_INTRUSIVE_DETAIL_TWIN_HPP diff --git a/include/boost/intrusive/detail/value_functors.hpp b/include/boost/intrusive/detail/value_functors.hpp new file mode 100644 index 0000000..dced9b0 --- /dev/null +++ b/include/boost/intrusive/detail/value_functors.hpp @@ -0,0 +1,42 @@ +#ifndef BOOST_INTRUSIVE_DETAIL_VALUE_FUNCTORS_HPP +#define BOOST_INTRUSIVE_DETAIL_VALUE_FUNCTORS_HPP +/////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2017-2021. 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_CONFIG_HPP +# include +#endif + +#if defined(BOOST_HAS_PRAGMA_ONCE) +# pragma once +#endif + +namespace boost { +namespace intrusive { + +//Functors for member algorithm defaults +template +struct value_less +{ + bool operator()(const ValueType &a, const ValueType &b) const + { return a < b; } +}; + +template +struct value_equal +{ + bool operator()(const ValueType &a, const ValueType &b) const + { return a == b; } +}; + +} //namespace intrusive { +} //namespace boost { + +#endif //BOOST_INTRUSIVE_DETAIL_VALUE_FUNCTORS_HPP diff --git a/include/boost/intrusive/linear_slist_algorithms.hpp b/include/boost/intrusive/linear_slist_algorithms.hpp index 6aeb036..55eb9e8 100644 --- a/include/boost/intrusive/linear_slist_algorithms.hpp +++ b/include/boost/intrusive/linear_slist_algorithms.hpp @@ -19,7 +19,7 @@ #include #include #include -#include //std::pair +#include //for node_pair #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once @@ -62,6 +62,12 @@ class linear_slist_algorithms typedef typename NodeTraits::node_ptr node_ptr; typedef typename NodeTraits::const_node_ptr const_node_ptr; typedef NodeTraits node_traits; + //A simple struct containing: + // + // typedef node_ptr type; + // node_ptr first; + // node_ptr second; + typedef twin node_pair; #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) @@ -222,9 +228,9 @@ class linear_slist_algorithms //! Throws: Nothing. //! //! Complexity: Linear to the number of elements plus the number moved positions. - static std::pair move_first_n_backwards(node_ptr p, std::size_t n) + static node_pair move_first_n_backwards(node_ptr p, std::size_t n) { - std::pair ret; + node_pair ret; //Null shift, or count() == 0 or 1, nothing to do if(!n || !p || !NodeTraits::get_next(p)){ return ret; @@ -277,9 +283,9 @@ class linear_slist_algorithms //! Throws: Nothing. //! //! Complexity: Linear to the number of elements plus the number moved positions. - static std::pair move_first_n_forward(node_ptr p, std::size_t n) + static node_pair move_first_n_forward(node_ptr p, std::size_t n) { - std::pair ret; + node_pair ret; //Null shift, or count() == 0 or 1, nothing to do if(!n || !p || !NodeTraits::get_next(p)) return ret; diff --git a/include/boost/intrusive/list.hpp b/include/boost/intrusive/list.hpp index 4313f12..d924bdd 100644 --- a/include/boost/intrusive/list.hpp +++ b/include/boost/intrusive/list.hpp @@ -39,7 +39,7 @@ #include #include -#include //std::less +#include #include //std::size_t, etc. #if defined(BOOST_HAS_PRAGMA_ONCE) @@ -988,19 +988,19 @@ class list_impl } } - //! Effects: This function sorts the list *this according to std::less. + //! Effects: This function sorts the list *this according to operator <. //! The sort is stable, that is, the relative order of equivalent elements is preserved. //! //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or std::less throws. Basic guarantee. + //! or operator < throws. Basic guarantee. //! //! Notes: Iterators and references are not invalidated. //! //! Complexity: The number of comparisons is approximately N log N, where N //! is the list's size. void sort() - { this->sort(std::less()); } + { this->sort(value_less()); } //! Requires: p must be a comparison function that induces a strict weak ordering //! @@ -1043,18 +1043,18 @@ class list_impl } //! Effects: This function removes all of x's elements and inserts them - //! in order into *this according to std::less. The merge is stable; + //! in order into *this according to operator <. The merge is stable; //! that is, if an element from *this is equivalent to one from x, then the element //! from *this will precede the one from x. //! - //! Throws: If std::less throws. Basic guarantee. + //! Throws: If operator < throws. Basic guarantee. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. //! //! Note: Iterators and references are not invalidated void merge(list_impl& x) - { this->merge(x, std::less()); } + { this->merge(x, value_less()); } //! Requires: p must be a comparison function that induces a strict weak //! ordering and both *this and x must be sorted according to that ordering @@ -1108,21 +1108,21 @@ class list_impl //! Effects: Removes all the elements that compare equal to value. //! No destructors are called. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator == throws. Basic guarantee. //! //! Complexity: Linear time. It performs exactly size() comparisons for equality. //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. void remove(const_reference value) - { this->remove_if(detail::equal_to_value(value)); } + { this->remove_if(value_equal(value)); } //! Requires: Disposer::operator()(pointer) shouldn't throw. //! //! Effects: Removes all the elements that compare equal to value. //! Disposer::operator()(pointer) is called for every removed element. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator == throws. Basic guarantee. //! //! Complexity: Linear time. It performs exactly size() comparisons for equality. //! @@ -1130,7 +1130,7 @@ class list_impl //! and iterators to elements that are not removed remain valid. template void remove_and_dispose(const_reference value, Disposer disposer) - { this->remove_and_dispose_if(detail::equal_to_value(value), disposer); } + { this->remove_and_dispose_if(value_equal(value), disposer); } //! Effects: Removes all the elements for which a specified //! predicate is satisfied. No destructors are called. diff --git a/include/boost/intrusive/slist.hpp b/include/boost/intrusive/slist.hpp index 444f8e9..699aca7 100644 --- a/include/boost/intrusive/slist.hpp +++ b/include/boost/intrusive/slist.hpp @@ -37,13 +37,12 @@ #include #include #include +#include #include #include -#include //std::less #include //std::size_t -#include //std::pair #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once @@ -1431,7 +1430,7 @@ class slist_impl void splice(const_iterator pos, slist_impl &x, const_iterator f, const_iterator l, size_type n) { return this->splice_after(this->previous(pos), x, x.previous(f), x.previous(l), n); } - //! Effects: This function sorts the list *this according to std::less. + //! Effects: This function sorts the list *this according to operator<. //! The sort is stable, that is, the relative order of equivalent elements is preserved. //! //! Throws: If value_traits::node_traits::node @@ -1501,14 +1500,14 @@ class slist_impl //! //! Throws: If value_traits::node_traits::node //! constructor throws (this does not happen with predefined Boost.Intrusive hooks) - //! or std::less throws. Basic guarantee. + //! or operator< throws. Basic guarantee. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. //! //! Note: Iterators and references are not invalidated. void sort() - { this->sort(std::less()); } + { this->sort(value_less()); } //! Requires: p must be a comparison function that induces a strict weak //! ordering and both *this and x must be sorted according to that ordering @@ -1557,18 +1556,18 @@ class slist_impl } //! Effects: This function removes all of x's elements and inserts them - //! in order into *this according to std::less. The merge is stable; + //! in order into *this according to operator<. The merge is stable; //! that is, if an element from *this is equivalent to one from x, then the element //! from *this will precede the one from x. //! - //! Throws: if std::less throws. Basic guarantee. + //! Throws: if operator< throws. Basic guarantee. //! //! Complexity: This function is linear time: it performs at most //! size() + x.size() - 1 comparisons. //! //! Note: Iterators and references are not invalidated void merge(slist_impl& x) - { this->merge(x, std::less()); } + { this->merge(x, value_less()); } //! Effects: Reverses the order of elements in the list. //! @@ -1588,7 +1587,7 @@ class slist_impl //! Effects: Removes all the elements that compare equal to value. //! No destructors are called. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator== throws. Basic guarantee. //! //! Complexity: Linear time. It performs exactly size() comparisons for equality. //! @@ -1603,7 +1602,7 @@ class slist_impl //! Effects: Removes all the elements that compare equal to value. //! Disposer::operator()(pointer) is called for every removed element. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator== throws. Basic guarantee. //! //! Complexity: Linear time. It performs exactly size() comparisons for equality. //! @@ -1671,14 +1670,14 @@ class slist_impl //! Effects: Removes adjacent duplicate elements or adjacent //! elements that are equal from the list. No destructors are called. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator== throws. Basic guarantee. //! //! Complexity: Linear time (size()-1) comparisons calls to pred()). //! //! Note: The relative order of elements that are not removed is unchanged, //! and iterators to elements that are not removed remain valid. void unique() - { this->unique_and_dispose(std::equal_to(), detail::null_disposer()); } + { this->unique_and_dispose(value_equal(), detail::null_disposer()); } //! Effects: Removes adjacent duplicate elements or adjacent //! elements that satisfy some binary predicate from the list. @@ -1700,7 +1699,7 @@ class slist_impl //! elements that satisfy some binary predicate from the list. //! Disposer::operator()(pointer) is called for every removed element. //! - //! Throws: If std::equal_to throws. Basic guarantee. + //! Throws: If operator== throws. Basic guarantee. //! //! Complexity: Linear time (size()-1) comparisons equality comparisons. //! @@ -1708,7 +1707,7 @@ class slist_impl //! and iterators to elements that are not removed remain valid. template void unique_and_dispose(Disposer disposer) - { this->unique(std::equal_to(), disposer); } + { this->unique(value_equal(), disposer); } //! Requires: Disposer::operator()(pointer) shouldn't throw. //! @@ -2035,7 +2034,7 @@ class slist_impl void priv_shift_backwards(size_type n, detail::bool_) { - std::pair ret( + typename node_algorithms::node_pair ret( node_algorithms::move_first_n_forward (node_traits::get_next(this->get_root_node()), (std::size_t)n)); if(ret.first){ @@ -2056,7 +2055,7 @@ class slist_impl void priv_shift_forward(size_type n, detail::bool_) { - std::pair ret( + typename node_algorithms::node_pair ret( node_algorithms::move_first_n_backwards (node_traits::get_next(this->get_root_node()), (std::size_t)n)); if(ret.first){