Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-09-09 11:32:23


"Joao Abecasis" <jpabecasis_at_[hidden]> wrote in message
news:413FD70A.4060801_at_zmail.pt...
Hi!

I have written a small utility class to provide "empty member
optimization" for arbitrary types. The implementation makes use of the
empty base class optimization (EBCO) but avoids injection of the class.
A uniform and contained interface is exposed wether the optimization
applies or not:

    template <typename T, size_t Index>
    compressed_pair
    {
        // several constructors may be provided but, for now,
        // default and copy constructor
        typedef T value_type;
        value_type & get();
        value_type const & get() const;
    };

I believe this could be used as the basis for a compressed_tuple.

Here's a sample use:

    template <typename T0, typename T1>
    struct A
    : private compressed_member<T0>
    , private compressed_member<T1, 1>
    {
        typedef compressed_member<T0> member0;
        typedef compressed_member<T1, 1> member1;

        T0 const & first() { return base0::get(); }
        T1 const & second() { return base1::get(); }
    };

There is a catch with the current implementation: some regular empty
member (or regular empty member of some compressed_member) could end up
sharing address with an empty compressed_member. This happens because
compressed_member<T> does not inherit from T but hides this
"relationship" from the compiler.

Is there any interest in such an utility?

To test compressed member I wrote another (toy) utility: empty_store.
empty_store is an empty class with a static map that associates an
instance's address to data. Checks are made everywhere to ensure that no
two instances share the same address.

The code can be found (zipped) here: *http://tinyurl.com/4e85l*

Best regards,

João Abecasis

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


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