Skip to content

Commit 0c1e2a7

Browse files
committed
copy_mutable_reference -> copy_non_const_reference
arbitrary arg support for constructors [SVN r13508]
1 parent d5c35a1 commit 0c1e2a7

4 files changed

Lines changed: 269 additions & 147 deletions

File tree

include/boost/python/class_fwd.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef CLASS_FWD_DWA200222_HPP
77
# define CLASS_FWD_DWA200222_HPP
88
# include <boost/python/detail/not_specified.hpp>
9+
# include <boost/python/args.hpp>
10+
# include <boost/python/bases.hpp>
911

1012
namespace boost { namespace python {
1113

include/boost/python/data_members.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# include <boost/type_traits/transform_traits.hpp>
1313
# include <boost/type_traits/cv_traits.hpp>
1414
# include <boost/python/return_value_policy.hpp>
15-
# include <boost/python/copy_mutable_reference.hpp>
15+
# include <boost/python/copy_non_const_reference.hpp>
1616

1717
namespace boost { namespace python {
1818

@@ -63,7 +63,7 @@ namespace detail
6363
template <class C, class D>
6464
objects::function* make_getter(D C::*pm)
6565
{
66-
typedef return_value_policy<copy_mutable_reference> default_policy;
66+
typedef return_value_policy<copy_non_const_reference> default_policy;
6767
return new objects::function(
6868
objects::py_function(
6969
::boost::bind(

include/boost/python/object/make_holder.hpp

Lines changed: 35 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -10,158 +10,48 @@
1010
# include <boost/python/object/forward.hpp>
1111
# include <boost/python/object/class.hpp>
1212
# include <boost/python/detail/wrap_python.hpp>
13+
# include <boost/python/detail/preprocessor.hpp>
14+
# include <boost/preprocessor/repeat.hpp>
15+
# include <boost/preprocessor/enum.hpp>
1316

1417
namespace boost { namespace python { namespace objects {
1518

1619
template <int nargs> struct make_holder;
1720

18-
template <>
19-
struct make_holder<0>
20-
{
21-
template <class Holder, class ArgList>
22-
struct apply
23-
{
24-
static void execute(
25-
PyObject* p)
26-
{
27-
(new Holder(p))->install(p);
28-
}
29-
};
21+
# ifndef BOOST_PYTHON_GENERATE_CODE
22+
# include <boost/python/preprocessed/make_holder.hpp>
23+
# endif
24+
25+
26+
# define BOOST_PYTHON_FORWARD_ARG(index, ignored) \
27+
typedef typename mpl::at<index,ArgList>::type BOOST_PP_CAT(t,index); \
28+
typedef typename forward<BOOST_PP_CAT(t,index)>::type BOOST_PP_CAT(f,index);
29+
30+
# define BOOST_PYTHON_DO_FORWARD_ARG(index, ignored) \
31+
BOOST_PP_CAT(f,index)(BOOST_PP_CAT(a, index))
32+
33+
# define BOOST_PYTHON_MAKE_HOLDER(nargs,ignored) \
34+
template <> \
35+
struct make_holder<nargs> \
36+
{ \
37+
template <class Holder, class ArgList> \
38+
struct apply \
39+
{ \
40+
BOOST_PP_REPEAT(nargs, BOOST_PYTHON_FORWARD_ARG, nil) \
41+
\
42+
static void execute( \
43+
PyObject* p \
44+
BOOST_PP_COMMA_IF(nargs) BOOST_PYTHON_ENUM_PARAMS2(nargs, (t,a)) ) \
45+
{ \
46+
(new Holder( \
47+
p \
48+
BOOST_PP_COMMA_IF(nargs) BOOST_PP_ENUM( \
49+
nargs,BOOST_PYTHON_DO_FORWARD_ARG,nil)))->install(p); \
50+
} \
51+
}; \
3052
};
3153

32-
33-
template <>
34-
struct make_holder<1>
35-
{
36-
template <class Holder, class ArgList>
37-
struct apply
38-
{
39-
typedef typename mpl::at<0,ArgList>::type t0;
40-
typedef typename forward<t0>::type f0;
41-
42-
static void execute(
43-
PyObject* p
44-
, t0 a0)
45-
{
46-
(new Holder(p, f0(a0)))->install(p);
47-
}
48-
};
49-
};
50-
51-
template <>
52-
struct make_holder<2>
53-
{
54-
template <class Holder, class ArgList>
55-
struct apply
56-
{
57-
typedef typename mpl::at<0,ArgList>::type t0;
58-
typedef typename forward<t0>::type f0;
59-
typedef typename mpl::at<1,ArgList>::type t1;
60-
typedef typename forward<t1>::type f1;
61-
62-
static void execute(
63-
PyObject* p, t0 a0, t1 a1)
64-
{
65-
(new Holder(p, f0(a0), f1(a1)))->install(p);
66-
}
67-
};
68-
};
69-
70-
template <>
71-
struct make_holder<3>
72-
{
73-
template <class Holder, class ArgList>
74-
struct apply
75-
{
76-
typedef typename mpl::at<0,ArgList>::type t0;
77-
typedef typename forward<t0>::type f0;
78-
typedef typename mpl::at<1,ArgList>::type t1;
79-
typedef typename forward<t1>::type f1;
80-
typedef typename mpl::at<2,ArgList>::type t2;
81-
typedef typename forward<t2>::type f2;
82-
83-
static void execute(
84-
PyObject* p, t0 a0, t1 a1, t2 a2)
85-
{
86-
(new Holder(p, f0(a0), f1(a1), f2(a2)))->install(p);
87-
}
88-
};
89-
};
90-
91-
template <>
92-
struct make_holder<4>
93-
{
94-
template <class Holder, class ArgList>
95-
struct apply
96-
{
97-
typedef typename mpl::at<0,ArgList>::type t0;
98-
typedef typename forward<t0>::type f0;
99-
typedef typename mpl::at<1,ArgList>::type t1;
100-
typedef typename forward<t1>::type f1;
101-
typedef typename mpl::at<2,ArgList>::type t2;
102-
typedef typename forward<t2>::type f2;
103-
typedef typename mpl::at<3,ArgList>::type t3;
104-
typedef typename forward<t3>::type f3;
105-
106-
static void execute(
107-
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3)
108-
{
109-
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3)))->install(p);
110-
}
111-
};
112-
};
113-
114-
template <>
115-
struct make_holder<5>
116-
{
117-
template <class Holder, class ArgList>
118-
struct apply
119-
{
120-
typedef typename mpl::at<0,ArgList>::type t0;
121-
typedef typename forward<t0>::type f0;
122-
typedef typename mpl::at<1,ArgList>::type t1;
123-
typedef typename forward<t1>::type f1;
124-
typedef typename mpl::at<2,ArgList>::type t2;
125-
typedef typename forward<t2>::type f2;
126-
typedef typename mpl::at<3,ArgList>::type t3;
127-
typedef typename forward<t3>::type f3;
128-
typedef typename mpl::at<4,ArgList>::type t4;
129-
typedef typename forward<t4>::type f4;
130-
131-
static void execute(
132-
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4)
133-
{
134-
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4)))->install(p);
135-
}
136-
};
137-
};
138-
139-
template <>
140-
struct make_holder<6>
141-
{
142-
template <class Holder, class ArgList>
143-
struct apply
144-
{
145-
typedef typename mpl::at<0,ArgList>::type t0;
146-
typedef typename forward<t0>::type f0;
147-
typedef typename mpl::at<1,ArgList>::type t1;
148-
typedef typename forward<t1>::type f1;
149-
typedef typename mpl::at<2,ArgList>::type t2;
150-
typedef typename forward<t2>::type f2;
151-
typedef typename mpl::at<3,ArgList>::type t3;
152-
typedef typename forward<t3>::type f3;
153-
typedef typename mpl::at<4,ArgList>::type t4;
154-
typedef typename forward<t4>::type f4;
155-
typedef typename mpl::at<5,ArgList>::type t5;
156-
typedef typename forward<t5>::type f5;
157-
158-
static void execute(
159-
PyObject* p, t0 a0, t1 a1, t2 a2, t3 a3, t4 a4, t5 a5)
160-
{
161-
(new Holder(p, f0(a0), f1(a1), f2(a2), f3(a3), f4(a4), f5(a5)))->install(p);
162-
}
163-
};
164-
};
54+
BOOST_PYTHON_REPEAT_ARITY_2ND(BOOST_PYTHON_MAKE_HOLDER,nil)
16555

16656
}}} // namespace boost::python::objects
16757

0 commit comments

Comments
 (0)