Boost logo

Boost :

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


    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

    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

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.


Philippe A. Bouchard

Boost list run by bdawes at, gregod at, cpdaniel at, john at