2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-23 17:52:17 +00:00

Added dangling_reference FAQ

Various idiomatic MPL cleanups in indirect_traits.hpp
raw_function support
Patches for CWPro7.2
Patches to pass tests under Python 2.3 with the new bool type.
Tests for member operators returning const objects
Fixes for testing Boost.Python under Cygwin


[SVN r17777]
This commit is contained in:
Dave Abrahams
2003-03-08 03:53:19 +00:00
parent e042228f45
commit a870ce20fc
17 changed files with 618 additions and 474 deletions

View File

@@ -132,7 +132,9 @@ namespace detail
must_be_derived_class_member(Default const&)
{
typedef typename assertion<mpl::not_<is_same<Default,Fn> > >::failed test0;
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
typedef typename assertion<is_polymorphic<T> >::failed test1;
# endif
typedef typename assertion<is_member_function_pointer<Fn> >::failed test2;
not_a_derived_class_member<Default>(Fn());
}

View File

@@ -76,12 +76,17 @@ namespace detail
detail::define_with_defaults(
name, stubs, current, detail::get_signature(sig));
}
template <class T>
object make_function1(T fn, ...) { return make_function(fn); }
object make_function1(object const& x, object const*) { return x; }
}
template <class Fn>
void def(char const* name, Fn fn)
{
detail::scope_setattr_doc(name, boost::python::make_function(fn), 0);
detail::scope_setattr_doc(name, detail::make_function1(fn, &fn), 0);
}
template <class Arg1T, class Arg2T>

View File

@@ -6,7 +6,6 @@
#ifndef INDIRECT_TRAITS_DWA2002131_HPP
# define INDIRECT_TRAITS_DWA2002131_HPP
# include <boost/type_traits/is_function.hpp>
# include <boost/type_traits/detail/ice_and.hpp>
# include <boost/type_traits/is_reference.hpp>
# include <boost/type_traits/is_pointer.hpp>
# include <boost/type_traits/is_class.hpp>
@@ -16,8 +15,18 @@
# include <boost/type_traits/remove_cv.hpp>
# include <boost/type_traits/remove_reference.hpp>
# include <boost/type_traits/remove_pointer.hpp>
# include <boost/type_traits/detail/ice_and.hpp>
# include <boost/detail/workaround.hpp>
# if 0 && BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
# include <boost/type_traits/is_enum.hpp>
# endif
# include <boost/mpl/if.hpp>
# include <boost/mpl/bool.hpp>
# include <boost/mpl/and.hpp>
# include <boost/mpl/not.hpp>
# include <boost/mpl/aux_/lambda_support.hpp>
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
@@ -28,27 +37,24 @@ namespace boost { namespace python { namespace detail {
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
template <class T>
struct is_reference_to_const
struct is_reference_to_const : mpl::false_
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class T>
struct is_reference_to_const<T const&>
struct is_reference_to_const<T const&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
template<class T>
struct is_reference_to_const<T const volatile&>
struct is_reference_to_const<T const volatile&> : mpl::true_
{
static const bool value = true;
};
# endif
template <class T>
struct is_reference_to_function : mpl::bool_<false>
struct is_reference_to_function : mpl::false_
{
};
@@ -58,9 +64,8 @@ struct is_reference_to_function<T&> : is_function<T>
};
template <class T>
struct is_pointer_to_function : mpl::bool_<false>
struct is_pointer_to_function : mpl::false_
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
// There's no such thing as a pointer-to-cv-function, so we don't need
@@ -71,7 +76,7 @@ struct is_pointer_to_function<T*> : is_function<T>
};
template <class T>
struct is_reference_to_member_function_pointer_impl : mpl::bool_<false>
struct is_reference_to_member_function_pointer_impl : mpl::false_
{
};
@@ -91,23 +96,23 @@ struct is_reference_to_member_function_pointer
template <class T>
struct is_reference_to_function_pointer_aux
: mpl::and_<
is_reference<T>
, is_pointer_to_function<
typename remove_cv<
typename remove_reference<T>::type
>::type
>
>
{
// There's no such thing as a pointer-to-cv-function, so we don't need specializations for those
BOOST_STATIC_CONSTANT(bool, value = (
is_reference<T>::value
& is_pointer_to_function<
typename remove_cv<
typename remove_reference<T>::type
>::type
>::value));
typedef mpl::bool_<value> type;
};
template <class T>
struct is_reference_to_function_pointer
: mpl::if_c<
is_reference_to_function<T>::value
, mpl::bool_<false>
: mpl::if_<
is_reference_to_function<T>
, mpl::false_
, is_reference_to_function_pointer_aux<T>
>::type
{
@@ -115,70 +120,60 @@ struct is_reference_to_function_pointer
template <class T>
struct is_reference_to_non_const
: mpl::and_<
is_reference<T>
, mpl::not_<
is_reference_to_const<T>
>
>
{
BOOST_STATIC_CONSTANT(
bool, value = (
::boost::type_traits::ice_and<
::boost::is_reference<T>::value
, ::boost::type_traits::ice_not<
::boost::python::detail::is_reference_to_const<T>::value>::value
>::value)
);
};
template <class T>
struct is_reference_to_volatile
struct is_reference_to_volatile : mpl::false_
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class T>
struct is_reference_to_volatile<T volatile&>
struct is_reference_to_volatile<T volatile&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
# if defined(BOOST_MSVC) && _MSC_FULL_VER <= 13102140 // vc7.01 alpha workaround
template <class T>
struct is_reference_to_volatile<T const volatile&>
struct is_reference_to_volatile<T const volatile&> : mpl::true_
{
static const bool value = true;
};
# endif
template <class T>
struct is_reference_to_pointer
struct is_reference_to_pointer : mpl::false_
{
BOOST_STATIC_CONSTANT(bool, value = false);
};
template <class T>
struct is_reference_to_pointer<T*&>
struct is_reference_to_pointer<T*&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
template <class T>
struct is_reference_to_pointer<T* const&>
struct is_reference_to_pointer<T* const&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
template <class T>
struct is_reference_to_pointer<T* volatile&>
struct is_reference_to_pointer<T* volatile&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
template <class T>
struct is_reference_to_pointer<T* const volatile&>
struct is_reference_to_pointer<T* const volatile&> : mpl::true_
{
BOOST_STATIC_CONSTANT(bool, value = true);
};
template <class T>
struct is_reference_to_class
struct is_reference_to_classx
{
BOOST_STATIC_CONSTANT(
bool, value
@@ -196,19 +191,47 @@ struct is_reference_to_class
};
template <class T>
struct is_pointer_to_class
struct is_reference_to_class
: mpl::and_<
is_reference<T>
# if 0 && BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
, mpl::not_<
is_enum<
typename remove_cv<
typename remove_reference<T>::type
>::type
>
>
# endif
, is_class<
typename remove_cv<
typename remove_reference<T>::type
>::type
>
>
{
};
template <class T>
struct is_pointer_to_class
: mpl::and_<
is_pointer<T>
# if 0 && BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
, mpl::not_<
is_enum<
typename remove_cv<
typename remove_pointer<T>::type
>::type
>
>
# endif
, is_class<
typename remove_cv<
typename remove_pointer<T>::type
>::type
>
>
{
BOOST_STATIC_CONSTANT(
bool, value
= (boost::type_traits::ice_and<
is_pointer<T>::value
, is_class<
typename remove_cv<
typename remove_pointer<T>::type
>::type
>::value
>::value)
);
};
# else
@@ -220,8 +243,8 @@ typedef char (&outer_no_type)[1];
template <typename V>
struct is_const_help
{
typedef typename mpl::if_c<
is_const<V>::value
typedef typename mpl::if_<
is_const<V>
, inner_yes_type
, inner_no_type
>::type type;
@@ -230,8 +253,8 @@ struct is_const_help
template <typename V>
struct is_volatile_help
{
typedef typename mpl::if_c<
is_volatile<V>::value
typedef typename mpl::if_<
is_volatile<V>
, inner_yes_type
, inner_no_type
>::type type;
@@ -240,8 +263,8 @@ struct is_volatile_help
template <typename V>
struct is_pointer_help
{
typedef typename mpl::if_c<
is_pointer<V>::value
typedef typename mpl::if_<
is_pointer<V>
, inner_yes_type
, inner_no_type
>::type type;
@@ -250,8 +273,8 @@ struct is_pointer_help
template <typename V>
struct is_class_help
{
typedef typename mpl::if_c<
is_class<V>::value
typedef typename mpl::if_<
is_class<V>
, inner_yes_type
, inner_no_type
>::type type;

View File

@@ -315,7 +315,10 @@ namespace detail
, mpl::push_front<>
>::type args;
typedef typename ClassT::holder_selector::type selector_t;
typedef typename ClassT::holder_selector holder_selector_t;
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
typedef typename holder_selector_t::type selector_t;
# endif
typedef typename ClassT::held_type held_type_t;
cl.def(

View File

@@ -11,6 +11,7 @@
# include <boost/mpl/if.hpp>
# include <boost/type_traits/object_traits.hpp>
# include <boost/type_traits/is_polymorphic.hpp>
# include <boost/detail/workaround.hpp>
namespace boost { namespace python { namespace objects {
@@ -108,16 +109,20 @@ struct implicit_cast_generator
template <class Source, class Target>
struct cast_generator
{
// CWPro7 will return false sometimes, but that's OK since we can
// always cast up with dynamic_cast<>
// It's OK to return false, since we can always cast up with
// dynamic_cast<> if neccessary.
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
BOOST_STATIC_CONSTANT(bool, is_upcast = false);
# else
BOOST_STATIC_CONSTANT(
bool, is_upcast = (
is_base_and_derived<Target,Source>::value
));
# endif
typedef typename mpl::if_c<
is_upcast
# if defined(__MWERKS__) && __MWERKS__ <= 0x2406
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
// grab a few more implicit_cast cases for CodeWarrior
|| !is_polymorphic<Source>::value
|| !is_polymorphic<Target>::value

View File

@@ -48,8 +48,14 @@ struct make_ptr_instance
}
template <class U>
static inline PyTypeObject* get_derived_class_object(mpl::false_, U*)
static inline PyTypeObject* get_derived_class_object(mpl::false_, U* x)
{
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
if (typeid(*x) != typeid(U))
return get_derived_class_object(mpl::true_(), x);
# else
(void)x;
# endif
return 0;
}
};