Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2006-05-19 08:37:15

"John Maddock" <john_at_[hidden]> writes:

> All of which suggests that a compressed-tuple would be a good idea,
> although ordering the items within the tuple to ensure compression
> is actually a larger challenge than folks may have realised.

Actually I think this is pretty easy. Here's the sketch:

  struct empty {};

  template <class Key, class Value, class Tail = empty>
  struct node : Tail
      // typical associative lookup tricks using overloading, per
      // Boost.Parameter library, or, I'm sure, Fusion's map


  template <
      class Types // MPL sequence
    , class Keys // types by which we'll do lookup
  struct compressed_tuple_base
      typedef typename mpl::sort<
        , mpl::less<is_empty<mpl::first<_1> >, is_empty<mpl::first<_2> > >
>::type sorted_pairs;

      typedef typename mpl::fold<
        , node<mpl::second<_2>, mpl::first<_2>, _1>
        , empty
>::type type;

  template <
      class Types // MPL sequence
    , class Keys = mpl::range_c<int, 0, mpl::size<Types>::value>
  struct compressed_tuple
    : compressed_tuple_base<Types,Keys>::type
      // ctors

      // The easy ctor will initialize from a tuple of references,
      // which we can build using tie()

      // get<N> just does lookup with integral_c<int,N> as the key

> In the mean time if additional template constructors can be added, I see no
> problem with that.

I think I'll code it with fusion when I get a moment :).

Dave Abrahams
Boost Consulting

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