Re: Conversion policies
David Abrahams <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Daniel Wallin <[email protected]> writes: > Given a conversion policy which handles conversions > xxx -> C++, what should be passed to the converter > function so that it can deduce the type? > > struct my_converter_policy > { > template<class T> > T convert(const param_type&, ...<T>); > ^^^^^^ what goes here? > }; > > The simplest approach would be to just pass a > boost::type<T>, but this means partial ordering > won't work. Why? Comeau accepts this: template <class T> struct type {}; template <class T> int* convert(int, type<T>); template <class T> long* convert(int, type<T*>); int* x = convert(0, type<int>()); long* y = convert(0, type<char*>()); > Also, IIRC, trying to deduce T from > type<const T&> results in an ICE on VC6.5. vc6.5 compiles this just fine: template <class T> struct type {}; template <class T> int* convert(int, type<T>); int* x = convert(0, type<int const&>()); Of course, if you're concerned about partial ordering, vc6.5/7 doesn't support it; you have to "help", and the ways I know of helping do seem to produce ICEs with vc6.5 when combined with type<...>. Why don't we go with class specialization, anyway? struct my_converter_policy { template <class T> struct apply { static T execute(const param_type&); }; }; > FWIW, in luabind, we handle this by decorating the > type: > > T by_value<T> > T& by_reference<T> > const T& by_const_reference<T> > T* by_pointer<T> > const T* by_const_pointer<T> I guess I don't really understand the motivation, here. Could you say a little more about why you want to distinguish those cases? Is there something wrong with the way Boost.Python does this now (whatever "this" is ;->)? -- Dave Abrahams Boost Consulting www.boost-consulting.com ------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01