From 922a1b9194f0e9cd0c2b8ef3fa80fd3a9b1fe749 Mon Sep 17 00:00:00 2001 From: Raoul Gough Date: Wed, 19 Nov 2003 12:45:29 +0000 Subject: [PATCH] Allow client replacement of value_traits, including less and equal_to members [SVN r20855] --- .../python/suite/indexing/algorithms.hpp | 38 +++++++++---------- .../python/suite/indexing/iterator_traits.hpp | 20 +++++----- include/boost/python/suite/indexing/list.hpp | 20 +++++++++- .../python/suite/indexing/suite_utils.hpp | 18 +++++++++ .../python/suite/indexing/value_traits.hpp | 7 ++-- 5 files changed, 68 insertions(+), 35 deletions(-) diff --git a/include/boost/python/suite/indexing/algorithms.hpp b/include/boost/python/suite/indexing/algorithms.hpp index fa2ddd70..9c5ff39f 100755 --- a/include/boost/python/suite/indexing/algorithms.hpp +++ b/include/boost/python/suite/indexing/algorithms.hpp @@ -28,27 +28,11 @@ #include #include #include +#include #include #include namespace boost { namespace python { namespace indexing { - namespace detail { - struct no_override { }; - - template - struct maybe_override - { - // Probably need to disable this if there is no partial - // specialization support, because Override is almost certain to - // be an incomplete type. If that is right, the workaround - // version would just have to do "typedef Base type;" - - typedef typename mpl::if_ - , Base, Override> - ::type type; - }; - } - template class default_algorithms { @@ -233,7 +217,13 @@ namespace boost { namespace python { namespace indexing { default_algorithms::find ( container &c, key_param key) { - return std::find (most_derived::begin(c), most_derived::end(c), key); + typedef typename container_traits::value_traits_ value_traits_; + typedef typename value_traits_::equal_to comparison; + + return std::find_if ( + most_derived::begin(c) + , most_derived::end(c) + , std::bind1st (comparison(), key)); } ///////////////////////////////////////////////////////////////////////// @@ -268,7 +258,13 @@ namespace boost { namespace python { namespace indexing { default_algorithms::count ( container &c, key_param key) { - return std::count (most_derived::begin(c), most_derived::end(c), key); + typedef typename container_traits::value_traits_ value_traits_; + typedef typename value_traits_::equal_to comparison; + + return std::count_if ( + most_derived::begin(c) + , most_derived::end(c) + , std::bind1st (comparison(), key)); } ///////////////////////////////////////////////////////////////////////// @@ -391,7 +387,9 @@ namespace boost { namespace python { namespace indexing { template void default_algorithms::sort (container &c) { - std::sort (most_derived::begin(c), most_derived::end(c)); + typedef typename container_traits::value_traits_ value_traits_; + typedef typename value_traits_::less comparison; + std::sort (most_derived::begin(c), most_derived::end(c), comparison()); } ///////////////////////////////////////////////////////////////////////// diff --git a/include/boost/python/suite/indexing/iterator_traits.hpp b/include/boost/python/suite/indexing/iterator_traits.hpp index b3e5850b..eade66c4 100755 --- a/include/boost/python/suite/indexing/iterator_traits.hpp +++ b/include/boost/python/suite/indexing/iterator_traits.hpp @@ -42,13 +42,13 @@ namespace boost { namespace python { namespace indexing { typedef ::boost::detail::iterator_traits std_traits; public: - typedef Iterator iterator; - typedef BOOST_DEDUCED_TYPENAME std_traits::value_type value_type; - typedef BOOST_DEDUCED_TYPENAME std_traits::reference reference; - typedef BOOST_DEDUCED_TYPENAME std_traits::difference_type difference_type; + typedef Iterator iterator; + typedef typename std_traits::value_type value_type; + typedef typename std_traits::reference reference; + typedef typename std_traits::difference_type difference_type; - BOOST_STATIC_CONSTANT (bool, has_copyable_iter = false); - BOOST_STATIC_CONSTANT (bool, is_reorderable = false); + BOOST_STATIC_CONSTANT (bool, has_copyable_iter = false); + BOOST_STATIC_CONSTANT (bool, is_reorderable = false); BOOST_STATIC_CONSTANT ( bool, has_mutable_ref = is_mutable_ref::value); @@ -121,11 +121,11 @@ namespace boost { namespace python { namespace indexing { template class deduced_traits { - typedef BOOST_DEDUCED_TYPENAME ::boost::BOOST_ITERATOR_CATEGORY< - Iterator>::type category; + typedef typename ::boost::BOOST_ITERATOR_CATEGORY::type + category; - typedef BOOST_DEDUCED_TYPENAME ::boost::detail::std_category < - category>::type max_category; + typedef typename ::boost::detail::std_category::type + max_category; public: typedef typename traits_by_category diff --git a/include/boost/python/suite/indexing/list.hpp b/include/boost/python/suite/indexing/list.hpp index eb7712ac..50b79b87 100755 --- a/include/boost/python/suite/indexing/list.hpp +++ b/include/boost/python/suite/indexing/list.hpp @@ -24,6 +24,11 @@ #include #include +#if BOOST_WORKAROUND (BOOST_MSVC, == 1200) +# include +# include +#endif + namespace boost { namespace python { namespace indexing { ///////////////////////////////////////////////////////////////////////// // Algorithms implementation for std::list instances @@ -93,7 +98,20 @@ namespace boost { namespace python { namespace indexing { template void list_algorithms::sort (container &c) { - c.sort(); + typedef typename container_traits::value_traits_ value_traits_; + typedef typename value_traits_::less comparison; +#if BOOST_WORKAROUND (BOOST_MSVC, == 1200) + // MSVC6 doesn't have a templated sort member in list, so we just + // use the parameterless version. This gives the correct behaviour + // provided that value_traits_::less is std::less. It + // would be possible to support std::greater (the only other + // overload of list::sort in MSVC6) with some additional work. + BOOST_STATIC_ASSERT ( + (::boost::is_same >::value)); + c.sort (); +#else + c.sort (comparison()); +#endif } } } } diff --git a/include/boost/python/suite/indexing/suite_utils.hpp b/include/boost/python/suite/indexing/suite_utils.hpp index 267a94d6..05e6e55b 100755 --- a/include/boost/python/suite/indexing/suite_utils.hpp +++ b/include/boost/python/suite/indexing/suite_utils.hpp @@ -86,6 +86,24 @@ namespace boost { namespace python { namespace indexing { typedef __int64 type; }; #endif + + namespace detail { + struct no_override { }; + + template + struct maybe_override + { + // Probably need to disable this if there is no partial + // specialization support, because Override is almost certain to + // be an incomplete type. If that is right, the workaround + // version would just have to do "typedef Base type;" + + typedef typename mpl::if_ + , Base, Override> + ::type type; + }; + } + } } } #endif // BOOST_PYTHON_INDEXING_SUITE_UTILS_HPP diff --git a/include/boost/python/suite/indexing/value_traits.hpp b/include/boost/python/suite/indexing/value_traits.hpp index 045b1b66..4eeb6fc5 100755 --- a/include/boost/python/suite/indexing/value_traits.hpp +++ b/include/boost/python/suite/indexing/value_traits.hpp @@ -22,17 +22,16 @@ #define BOOST_PYTHON_INDEXING_VALUE_TRAITS_HPP #include +#include namespace boost { namespace python { namespace indexing { template struct value_traits { BOOST_STATIC_CONSTANT (bool, equality_comparable = true); - // Meaning from C++98 standard section 20.1.1 + typedef std::equal_to equal_to; BOOST_STATIC_CONSTANT (bool, lessthan_comparable = true); - - // static bool const has_less = true; - // etc... + typedef std::less less; // Default, do-nothing, version of visitor_helper template