Boost logo

Boost :

From: Mats Nilsson (pommac2_at_[hidden])
Date: 2003-11-26 08:57:14


I'm trying to convert a construct like this:

 

template <class R, class T>

struct Foo {

            Foo(R (T::*m)) : member(m) {}

            R T::*member;

};

 

template <class R, class T>

Foo<R, T> makeFoo(R (T::*m)) {

            return Foo<R, T>(m);

}

 

 

struct S { int a; };

makeFoo(&S::a);

 

into something where the member pointer is a template parameter:

 

            template <class R, class T, R (T::*member)>

            struct Foo {};

 

            template <class R, class T, R (T::*member)>

            Foo<R, T, member> make Foo() {

                        return Foo<R, T, member>();

}

 

struct S { int a;};

makeFoo<int, S, &S::a>();

 

but this forces me to explicitly specify the return type and class type.
This is exactly why I used the helper function in the first example. I'm
sure there has to be a workaround somehow that'll allow me to say
something like the following and have the compiler deduce the missing
parts:

 

            makeFoo<&S::a>()

 

I can't think of a better place to ask than here.

 

Thanks

 

Mats Nilsson



Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk