From 887faad3734aaf7a17e257cfc0c3fd218ffa1546 Mon Sep 17 00:00:00 2001 From: Raoul Gough Date: Wed, 19 Nov 2003 15:02:10 +0000 Subject: [PATCH] Allow client replacement of value_traits, including less and equal_to members [SVN r20860] --- .../suite/indexing/container_traits.hpp | 39 ++++++++++++------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/include/boost/python/suite/indexing/container_traits.hpp b/include/boost/python/suite/indexing/container_traits.hpp index d2254a48..f964f355 100755 --- a/include/boost/python/suite/indexing/container_traits.hpp +++ b/include/boost/python/suite/indexing/container_traits.hpp @@ -31,6 +31,7 @@ #include #define ICE_AND(a, b) type_traits::ice_and<(a), (b)>::value +// #undef'd later in this header namespace boost { namespace python { namespace indexing { #if BOOST_WORKAROUND (BOOST_MSVC, <= 1200) @@ -52,7 +53,7 @@ namespace boost { namespace python { namespace indexing { // and iterator pairs ///////////////////////////////////////////////////////////////////////// - template + template struct base_container_traits : public ::boost::python::indexing::iterator_traits < BOOST_DEDUCED_TYPENAME mpl::if_ < @@ -71,8 +72,8 @@ namespace boost { namespace python { namespace indexing { >::type > base_type; - BOOST_STATIC_CONSTANT (bool, is_mutable - = ! boost::is_const::value); + BOOST_STATIC_CONSTANT ( + bool, is_mutable = ! boost::is_const::value); public: typedef Container container; @@ -91,13 +92,19 @@ namespace boost { namespace python { namespace indexing { typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS ::param_type index_param; - typedef value_traits value_traits_; + // Allow client code to replace the default value traits via our + // second (optional) template parameter + typedef value_traits default_value_traits; - BOOST_STATIC_CONSTANT (bool, has_mutable_ref - = ICE_AND (base_type::has_mutable_ref, is_mutable)); + typedef typename detail::maybe_override < + default_value_traits, ValueTraits>::type value_traits_; - BOOST_STATIC_CONSTANT (bool, has_find - = value_traits_::equality_comparable); + BOOST_STATIC_CONSTANT ( + bool, has_mutable_ref + = ICE_AND (base_type::has_mutable_ref, is_mutable)); + + BOOST_STATIC_CONSTANT ( + bool, has_find = value_traits_::equality_comparable); // Assume the worst for everything else BOOST_STATIC_CONSTANT (bool, has_insert = false); @@ -118,10 +125,11 @@ namespace boost { namespace python { namespace indexing { // at least these requirements ///////////////////////////////////////////////////////////////////////// - template - struct default_container_traits : public base_container_traits + template + struct default_container_traits + : public base_container_traits { - typedef default_container_traits self_type; + typedef default_container_traits self_type; BOOST_STATIC_CONSTANT (bool, has_insert = self_type::is_mutable); BOOST_STATIC_CONSTANT (bool, has_erase = self_type::is_mutable); }; @@ -130,14 +138,17 @@ namespace boost { namespace python { namespace indexing { // Sequences (list, deque, vector) ///////////////////////////////////////////////////////////////////////// - template - struct default_sequence_traits : public default_container_traits + template + struct default_sequence_traits + : public default_container_traits { - typedef default_sequence_traits self_type; + typedef default_sequence_traits self_type; BOOST_STATIC_CONSTANT (bool, has_pop_back = self_type::is_mutable); BOOST_STATIC_CONSTANT (bool, has_push_back = self_type::is_mutable); }; } } } +#undef ICE_AND + #endif // BOOST_PYTHON_INDEXING_CONTAINER_SUITE_HPP