Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-03-02 12:11:48


Greetings,

    I have just made a class which is able to correctly handle alignments of
the types resembling to boost::optional<>. The booleans which are
responsible to flag if the object is initialized or not are gathered
together so that they will not disturb the alignment of the objects in
question.

    The following example demonstrates how it looks like for now; I am using
typelists but I guess some derivative of tuple<> will be better eventually.
The member function postponed<>::set<>() properly initialized the boolean to
true:

struct A : postponed< typelist<char, typelist<short, typelist<long,
typelist<double, void> > > > >
{
};

int main()
{
    A a;

    new (a.set<0>()) char('M');
    new (a.set<1>()) short(50);
    new (a.set<2>()) long(100000);
    new (a.set<3>()) double(3.1416);

    cout << a.get<0>() << endl;
    cout << a.get<1>() << endl;
    cout << a.get<2>() << endl;
    cout << a.get<3>() << endl;
}

    Maybe the following will be better...:
    new (a.set<0>) char('M');

    I would like some feedback about the logic behind it.

Regards,

Philippe A. Bouchard


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