Boost logo

Boost :

From: John Femiani (JOHN.FEMIANI_at_[hidden])
Date: 2007-05-13 17:33:48


Hi all,

 

I wrote a little macro that uses BOOST_TYPEOF to determine the type of
one of its arguments, but it fails when I pass (*this) as an argument in
vc8. I forced emulation because, according to the docs, vc8 does not
seem to have the bug that let other vc compilers actually support native
typeof. I don't know the internals of the TYPEOF library well enough
to diagnose the problem, but the error is easy to produce.

 

 

#define BOOST_TYPEOF_COMPLIANT

#include <boost/typeof/typeof.hpp>

#include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()

 

template<class Inner> struct A;

 

BOOST_TYPEOF_REGISTER_TEMPLATE(A,1);

 

#define USES_TYPEOF_IN_A_MACRO(X) \

    { \

      BOOST_TYPEOF_TPL(X) &ref = X; \

      BOOST_TYPEOF_TPL(X)::inner_t inner = X.inner(); \

    }

 

 

template<class Inner>

struct A{

    typedef Inner inner_t;

 

    inner_t inner() {

        return Inner();

    }

   

    void do_something() {

        A<Inner>& star_this = *this;

        USES_TYPEOF_IN_A_MACRO(star_this);

        USES_TYPEOF_IN_A_MACRO(*this); //ERROR!

    }

};

 

 

 

void main(){

  A<int> a;

  a.do_something();

};

 

If there is any way to accomplish the type of access I am attempting
from inside a macro I would really appreciate it (in my use case macros
seem to be absolutely necessary for other reasons). As you can see from
the example it is possible to avoid the problem by creating a reference
to *this and passing that, but I do not like this in principle because
too many caveats make the macro difficult to use.

 

 

John


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