Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2006-08-03 05:22:33


Hello all,

I have one specific question. Which I am uncertain if it can be solved anyway.

Imagine the following class structure:

struct A
{
        some_field* x;
};

struct B
{
        optional<A> a_;
};

struct C
{
        optional<B> b_;
};

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 ...

This will be really unpleasent if the structure is more deep then this one. Which is the case in
our project.

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...

Currently I am thinking about boost parameter library, but still uncertain if this problem can be
solved using it...

Can some of you make a suggestion what is the best suitable way of resolving this issue and if
this issue resolvable anyway.

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