Boost logo

Boost :

From: Hamish Mackenzie (boost_at_[hidden])
Date: 2001-11-27 08:27:43


> [ two people made the point that typelists should be instantiable ]
>
> how about something like (off the top of my head)
>
> template<typename Head, typename Tail> class dummy_pair_without_storage{
> // typedefs as per boost::compressed_pair
> };
>
> template<template<class, class> class PairType, typename Head, typename
> Tail>
> class tuply_thing : public PairType<Head, Tail>{ // ok, a better name would
> be good
> typedef PairType< Head, Tail > base;
> public:
> typedef typename base::first_type head_type;
> typedef typename base::second_type tail_type;
> // etc. etc.
> // constructors too
> };

I think it should use private inheritance here. We could add a member
class to represent the empty list (say nil or empty).

How about recusive_node as the name.

>
> template<typename Head, typename Tail>
> class typelist : public tuply_thing<dummy_pair_without_storage, Head,
> Tail>{};
>
> template<typename Head, typename Tail>
> class tuple : public tuply_thing<boost::compressed_pair, Head, Tail>{};
>

I think this should definitely give us the best of both worlds.

It does break my suggested language extension but we could add a
parameter to the macro.

Something like

#define RECURSIVE_3( Type, Item0, Item1, Item2 ) \
  Type< Item0, Type< Item1, Type< Item2, Type::nil > > >

#define RECURSIVE_3_T( Type, Item0, Item1, Item2, Tail ) \
  Type< Item0, Type< Item1, Type< Item2, Tail > > >

A possible language extension to replace these macros would be...

#define RECURSIVE_3( Type, Item0, Item1, Item2 ) \
  recursive< Type, Item0, Item1, Item2 >

#define RECURSIVE_3_T( Type, Item0, Item1, Item2, Tail ) \
  recursive< Type, Item0, Item1, Item2 | Tail >

I think this would also sovle the problem of defining lists of
constants.

Hamish


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