2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 06:02:14 +00:00

Allow client replacement of value_traits, including less and equal_to members

[SVN r20860]
This commit is contained in:
Raoul Gough
2003-11-19 15:02:10 +00:00
parent 712b90dfe0
commit 887faad373

View File

@@ -31,6 +31,7 @@
#include <boost/type_traits/ice.hpp>
#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<typename Container>
template<typename Container, typename ValueTraits = detail::no_override>
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<Container>::value);
BOOST_STATIC_CONSTANT (
bool, is_mutable = ! boost::is_const<Container>::value);
public:
typedef Container container;
@@ -91,13 +92,19 @@ namespace boost { namespace python { namespace indexing {
typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <index_type>::param_type
index_param;
typedef value_traits<typename base_type::value_type> value_traits_;
// Allow client code to replace the default value traits via our
// second (optional) template parameter
typedef value_traits<typename base_type::value_type> 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<typename Container>
struct default_container_traits : public base_container_traits<Container>
template<typename Container, typename ValueTraits = detail::no_override>
struct default_container_traits
: public base_container_traits<Container, ValueTraits>
{
typedef default_container_traits<Container> self_type;
typedef default_container_traits<Container, ValueTraits> 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<typename Container>
struct default_sequence_traits : public default_container_traits<Container>
template<typename Container, typename ValueTraits = detail::no_override>
struct default_sequence_traits
: public default_container_traits<Container, ValueTraits>
{
typedef default_sequence_traits<Container> self_type;
typedef default_sequence_traits<Container, ValueTraits> 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