[C++-sig] Possible overload<> template for class members
Aleksey Gurtovoy
agurtovoy at meta-comm.com
Fri Dec 13 09:44:44 CET 2002
Ralf W. Grosse-Kunstleve wrote:
> --- William Trenker <wtrenker at hotmail.com> wrote:
> > .def("show", overload<void,void>(), &Window::show)
> > .def("show", overload<void,const Window*>(), &Window.show)
>
> That looks just like my old "plan A" :-)
>
> > Is something like this even possible?
>
> David kept claiming the answer is no, because in C++ you cannot take
> the "address" of a family over overloaded functions. If Window.show
> has overloads the compiler has no way of knowing which one you mean
> if you just type &Window.show.
Hmm, seems entirely possible to me:
template< typename R, typename A0 = void, typename A1 = void >
struct overload {};
template< typename R >
void def(char const*, overload<R>, R (*f)());
template< typename R, typename A0 >
void def(char const*, overload<R,A0>, R (*f)(A0));
template< typename R, typename A0, typename A1 >
void def(char const*, overload<R,A0,A1>, R (*f)(A0, A1));
template< typename R, typename T >
void def(char const*, overload<R>, R (T::*f)());
template< typename R, typename T, typename A0 >
void def(char const*, overload<R,A0>, R (T::*f)(A0));
template< typename R, typename T, typename A0, typename A1 >
void def(char const*, overload<R,A0,A1>, R (T::*f)(A0, A1));
void show();
bool show(int);
void show(int, bool*);
struct window
{
void show();
bool show(int);
void show(int, bool*);
};
int main()
{
def("show", overload<void>(), &show);
def("show", overload<bool,int>(), &show);
def("show", overload<void,int,bool*>(), &show);
def("show", overload<void>(), &window::show);
def("show", overload<bool,int>(), &window::show);
def("show", overload<void,int,bool*>(), &window::show);
}
Am I missing something?
Aleksey
More information about the Cplusplus-sig
mailing list