Re: Declaring overloads (and template functions).
Daniel Wallin <[email protected]>
| Newsgroups | gmane.comp.lib.boost.langbinding |
|---|---|
| Message-ID | <[email protected]> |
Rene Rivera wrote: > Roman Yakovenko wrote: >> On 7/26/07, Rene Rivera <[email protected]> wrote: >>> ===C++ >>> class_<A>() >>> .def("f", overload<void(int)>(&A::f)) >>> === >>> >>> Though, I'm not sure if one can make such an "overload<>()" function >>> smart enough to automatically turn the bare function type into the >>> corresponding member function pointer type. >> I could be wrong but you can check this with boost::function library. >> http://boost.org/doc/html/function/tutorial.html#id1186900 . >> If that library can do this, than you can do it too. > > That is equivalent to using is_member_function_pointer > <http://boost.org/doc/html/boost_typetraits/reference.html#boost_typetraits.is_member_function_pointer>. > The problems with those is that we don't have a member function pointer > yet. To be clear the function might be declared as: > > template <typename FunctionType, typename FunctionPointerType> > FunctionPointerType overload( FunctionPointerType p ) > { > return p; > } > > The hard part is in calculating the FunctionPointerType such that > FunctionType doesn't have include the "A::*" member pointer > qualification. I personally dont't see a way of doing it :-( Here's a prototype: template <class T> struct types {}; template <class R, class T> struct types<R(T)> { typedef R result; typedef T a0; typedef int arity1; }; template <class R, class T, class U> struct types<R(T,U)> { typedef R result; typedef T a0; typedef U a1; typedef int arity2; }; template <class T, class C> void overload(typename types<T>::result (C::*)(typename types<T>::a0), typename types<T>::arity1 = 0); template <class T, class C> void overload(typename types<T>::result (C::*)(typename types<T>::a0, typename types<T>::a1), typename types<T>::arity2 = 0); struct A { void f(int); char f(float,int); }; int main() { overload<char(float,int)>(&A::f); } HTH, -- Daniel Wallin Boost Consulting www.boost-consulting.com ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/