Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-08-03 09:17:31


On Thu, August 3, 2006 14:58, james.jones_at_[hidden] wrote:
> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
James,

thanks for your answer. This seems to be the possibly best solution. I will play
around with it
and see how this can be realized with arbitrary lists.

This if is not a really nice solution, since the names of the classes are really
long... The
problem resides that users have to retype this long names (approx. 20 chars each
name). I know
that this can be an error source, but anyway it is there an can not be changed.

if(c.b_ && c.b_.a_ && c.b_.a_.x)

Somehow I forgot, that && is a lazy operation. This seems to be a really nice and
elegant solution
in my opinion. The only problem is that this is a macro.

With Kind Regards,

Ovanes Markarian


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