2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 19:12:16 +00:00

Custom less and equal_to for element_proxy specialization of value_traits

[SVN r20882]
This commit is contained in:
Raoul Gough
2003-11-20 18:20:33 +00:00
parent d5c9831da8
commit 7430b7c4a6
2 changed files with 55 additions and 17 deletions

View File

@@ -769,20 +769,21 @@ namespace boost { namespace python { namespace indexing {
typedef typename BOOST_PYTHON_INDEXING_CALL_TRAITS <key_type>::param_type
key_param;
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
typedef value_traits<reference> value_traits_;
#else
#if defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
// value_traits for the reference type (i.e. our element_proxy
// instance) supplies a custom visitor_helper. Compilers without
// partial specialization need help here.
typedef element_proxy_traits<Container> value_traits_;
// Forward visitor_helper to eleemnt_proxy_traits
// Hide base class visitor_helper, which would call the
// unspecialized value_traits version
template<typename PythonClass, typename Policy>
static void visitor_helper (PythonClass &pyClass, Policy const &policy)
{
value_traits_::visitor_helper (pyClass, policy);
}
#endif
// Get value_traits for the reference type (i.e. element_proxy)
// to get the custom visitor_helper
};
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)

View File

@@ -1,4 +1,3 @@
//
// Header file element_proxy_traits.hpp
//
// Copyright (c) 2003 Raoul M. Gough
@@ -7,6 +6,12 @@
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy
// at http://www.boost.org/LICENSE_1_0.txt)
//
// This is a separate header so that element_proxy.hpp is not
// dependant on register_ptr_to_python.hpp. This avoids a problem with
// two-phase name lookup, where register_ptr_to_python must be
// included *after* the element_proxy overload of boost::get_pointer
// is defined.
//
// History
// =======
// 2003/10/23 rmg File creation
@@ -23,28 +28,60 @@
#include <boost/python/implicit.hpp>
namespace boost { namespace python { namespace indexing {
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template<typename ContainerProxy>
struct value_traits<element_proxy<ContainerProxy> >
: public value_traits <
BOOST_DEDUCED_TYPENAME ContainerProxy::raw_value_type>
#else
template<typename ContainerProxy>
struct element_proxy_traits
: public value_traits <
BOOST_DEDUCED_TYPENAME ContainerProxy::raw_value_type>
#endif
{
typedef element_proxy<ContainerProxy> element_proxy_;
typedef typename ContainerProxy::raw_value_type raw_value_type;
typedef value_traits<raw_value_type> base_type;
// Wrap the base class versions of the comparisons using
// indirection
struct less
: std::binary_function<element_proxy_, element_proxy_, bool>
{
typename base_type::less m_base_compare;
bool operator() (
element_proxy_ const &p1, element_proxy_ const &p2) const
{
return m_base_compare (*p1, *p2);
}
};
struct equal_to
: std::binary_function<raw_value_type, element_proxy_, bool>
{
// First param is raw_value_type to interface smoothly with the
// bind1st used in default_algorithms::find
typename base_type::equal_to m_base_compare;
bool operator() (
raw_value_type const &v, element_proxy_ const &p) const
{
return m_base_compare (v, *p);
}
};
template<typename PythonClass, typename Policy>
static void visitor_helper (PythonClass &, Policy const &)
{
typedef element_proxy<ContainerProxy> element_proxy_;
typedef typename ContainerProxy::raw_value_type raw_value_type;
boost::python::register_ptr_to_python<element_proxy_>();
boost::python::implicitly_convertible<raw_value_type, element_proxy_>();
}
};
#if !defined (BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
// value_traits partial specialization for element_proxy instances
template<typename ContainerProxy>
struct value_traits<element_proxy<ContainerProxy> >
: element_proxy_traits<ContainerProxy>
{
};
#endif
} } }
#endif // BOOST_PYTHON_INDEXING_ELEMENT_PROXY_TRAITS_HPP