Boost logo

Boost Users :

From: james.jones_at_[hidden]
Date: 2006-08-03 08:58:21


From: "Ovanes Markarian" <om_boost_at_[hidden]>

> Now I have an instance of struct C and would like to know if x is a valid pointer.
> this code is really ugly:

> if(c.b_)
> if(c.b_.a_)
> if(c.b_.a_.x)
> //do smth ...

> The intention would be to write everything in one if-statement. It is not possible
> to implement a bool or ! operator in these structures, since these are not the
> only fields and these operators would not know which field should be checked...

How about just:

if(c.b_ && c.b_.a_ && c.b_.a_.x)
        //do smth ...

Is that cheating? You can do it all in one 'if' statement this way. I suppose you could write a macro to do something like this:

#define CHECK(x,y,z,w) (x.y && x.y.z && x.y.z.w)

and then use it like this:

if(CHECK(c, b_, a_, x))
        //do smth ...

And maybe you could write the macro in such a way as to take arbitrary lists of arguments. But that's the best I can come up with.

-
James Jones Administrative Data Mgmt.
Webmaster 375 Raritan Center Pkwy, Suite A
Data Architect Edison, NJ 08837


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net