mirror of
https://github.com/boostorg/python.git
synced 2026-01-26 06:42:27 +00:00
*** empty log message ***
[SVN r13210]
This commit is contained in:
@@ -43,6 +43,13 @@ struct non_member_function_cast_impl
|
||||
template <class T>
|
||||
struct member_function_cast_impl
|
||||
{
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
template <class U>
|
||||
static non_member_function_cast_impl stage1(U)
|
||||
{
|
||||
return non_member_function_cast_impl();
|
||||
}
|
||||
# endif
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()> stage1(R (S::*)())
|
||||
{
|
||||
@@ -85,7 +92,6 @@ struct member_function_cast_impl
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)>();
|
||||
}
|
||||
|
||||
# if 1
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()const> stage1(R (S::*)()const)
|
||||
{
|
||||
@@ -170,7 +176,6 @@ struct member_function_cast_impl
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)volatile>();
|
||||
}
|
||||
|
||||
// # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class S, class R>
|
||||
static cast_helper<S,R(T::*)()const volatile> stage1(R (S::*)()const volatile)
|
||||
{
|
||||
@@ -212,17 +217,20 @@ struct member_function_cast_impl
|
||||
{
|
||||
return cast_helper<S,R(T::*)(A0,A1,A2,A3,A4,A5)const volatile>();
|
||||
}
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
template <class T, class SF>
|
||||
struct member_function_cast
|
||||
# ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
|
||||
: member_function_cast_impl<T>
|
||||
# else
|
||||
: mpl::select_type<
|
||||
is_member_function_pointer<SF>::value
|
||||
, member_function_cast_impl<T>
|
||||
, non_member_function_cast_impl
|
||||
>::type
|
||||
# endif
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
@@ -45,9 +45,14 @@ template <class F>
|
||||
PyObject* wrap_function(F f)
|
||||
{
|
||||
return wrap_function_select<
|
||||
# if 1
|
||||
type_traits::ice_not<
|
||||
is_pointer<F>::value
|
||||
# else
|
||||
type_traits::ice_or<
|
||||
is_function<F>::value
|
||||
, is_member_function_pointer<F>::value
|
||||
# endif
|
||||
>::value >::execute(f);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace
|
||||
make_iterator_property_map(
|
||||
to_target
|
||||
, get(vertex_index, reverse_topology)
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
# ifdef BOOST_NO_STD_ITERATOR_TRAITS
|
||||
, *to_target
|
||||
# endif
|
||||
)
|
||||
|
||||
@@ -59,11 +59,14 @@ bpl-test virtual_functions ;
|
||||
|
||||
# --- unit tests of library components ---
|
||||
unit-test indirect_traits_test
|
||||
: indirect_traits_test.cpp : <include>$(BOOST_ROOT) ;
|
||||
: indirect_traits_test.cpp : <include>$(BOOST_ROOT) ;
|
||||
unit-test destroy_test
|
||||
: destroy_test.cpp : <include>$(BOOST_ROOT) ;
|
||||
unit-test pointer_type_id_test
|
||||
: pointer_type_id_test.cpp : <include>$(BOOST_ROOT) ;
|
||||
: pointer_type_id_test.cpp : <include>$(BOOST_ROOT) ;
|
||||
|
||||
unit-test member_function_cast
|
||||
: member_function_cast.cpp : <include>$(BOOST_ROOT) ;
|
||||
|
||||
unit-test select_from_python_test
|
||||
: select_from_python_test.cpp
|
||||
|
||||
55
test/member_function_cast.cpp
Normal file
55
test/member_function_cast.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright David Abrahams 2002. Permission to copy, use,
|
||||
// modify, sell and distribute this software is granted provided this
|
||||
// copyright notice appears in all copies. This software is provided
|
||||
// "as is" without express or implied warranty, and with no claim as
|
||||
// to its suitability for any purpose.
|
||||
#include <boost/python/detail/member_function_cast.hpp>
|
||||
#include <boost/type_traits.hpp>
|
||||
#include <boost/type.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
using namespace boost;
|
||||
|
||||
template <class T, class S>
|
||||
void assert_same(S, type<T>* = 0)
|
||||
{
|
||||
BOOST_STATIC_ASSERT((is_same<T,S>::value));
|
||||
}
|
||||
|
||||
template <class Expected, class Target, class F>
|
||||
void assert_mf_cast(F f, type<Expected>* = 0, type<Target>* = 0)
|
||||
{
|
||||
assert_same<Expected>(
|
||||
python::detail::member_function_cast<Target,F>::stage1(f).stage2((Target*)0).stage3(f)
|
||||
);
|
||||
}
|
||||
|
||||
struct X
|
||||
{
|
||||
int f() const { return 0; }
|
||||
void g(char*) {}
|
||||
};
|
||||
|
||||
struct Y : X
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct Z : Y
|
||||
{
|
||||
int f() const { return 0; }
|
||||
void g(char*) {}
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
assert_mf_cast<int (Y::*)() const, Y>(&X::f);
|
||||
assert_mf_cast<void (Y::*)(char*), Y>(&X::g);
|
||||
|
||||
assert_mf_cast<int (Z::*)() const, Y>(&Z::f);
|
||||
assert_mf_cast<void (Z::*)(char*), Y>(&Z::g);
|
||||
|
||||
assert_mf_cast<int, Y>(3);
|
||||
assert_mf_cast<X, Y>(X());
|
||||
return 0;
|
||||
};
|
||||
@@ -16,10 +16,13 @@
|
||||
extern "C" BOOL WINAPI DllMain ( HINSTANCE hInst, DWORD wDataSeg, LPVOID lpvReserved );
|
||||
|
||||
# ifdef BOOST_MSVC
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4297)
|
||||
extern "C" void structured_exception_translator(unsigned int, EXCEPTION_POINTERS*)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
# pragma warning(pop)
|
||||
# endif
|
||||
|
||||
BOOL WINAPI DllMain(
|
||||
|
||||
Reference in New Issue
Block a user