Re: [Implementation] Calling wrapped functions, converters, policies
David Abrahams <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Daniel Wallin <[email protected]> writes: >>>The same goes for argument_package. Here we also have get() functions: >>> >>> template<class Base, int N> >>> PyObject* get(PyObject* args, mpl::int_<N>) >>> { return PySomethingSomething(.., N); } >>> >>> template<int N> >>> struct offset_arg // IIRC you have something like this in BPL >>> { >>> offset_arg(PyObject*) {} >>> }; >> Yep, in boost/python/make_constructor.hpp >> >>>With a special overload that handles the composite case where every >>>argument_package has a base type which must be queried: >>> >>> template<class Base, int M, int N> >>> PyObject* get(offset_arg<M>, const Base& base, mpl::int_<N>) >>> { return get(base, mpl::int_<N + M>()); } >> Wha?? >> Why isn't the base object stored in the offset_arg<>, as in BPL? Do >> you need to explain what Base is? > > Because the different CallPolicies in the composite_call_policies type > have no knowledge of each other. What I don't like here is the need for a "special overload". It feels like a very nonuniform special-case. And it proliferates: you'll need to do something similar for arity (querying the size of the argument package), won't you? > Meaning we would need to make the > nested argument_package a metafunction: > > struct my_policy > { > template<class Base> > struct argument_package > { > typedef offset_arg<1, Base> type; > }; > }; That might be better. > I think it's nicer to create a composite hierarchy: > > composite_argument_package< > offset_arg<1> > , composite_argument_package< > offset_arg<9> > , composite_argument_package_native< > PyObject* > > > > > > > > template<class Pkg, class Base> > struct composite_argument_package : Base > { > // some forwarding constructors goes here Nasty. Forwarding is hard to do well. > Pkg pkg_; > }; > > template<class Pkg, class Base, int N> > PyObject* get( > const composite_argument_package<Pkg, Base>& x, mpl::int_<N>) > { > // forward to correct get() function > return get(x.pkg_, static_cast<const Base&>(x), mpl::int_<N>()); Why are you using static_cast instead of implicit_cast here? > } > > See what I'm driving at? Not yet. -- Dave Abrahams Boost Consulting www.boost-consulting.com ------------------------------------------------------- This SF. Net email is sponsored by: GoToMyPC GoToMyPC is the fast, easy and secure way to access your computer from any Web browser or wireless device. Click here to Try it Free! https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl