Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-09-22 12:49:14


Wow! After some very ugly hacking I actually was able to implement
tuples using MSVC++!

I was inspired by the post by Dave Abrahams a while back about a poor
man's partial template specialization technique. I decided I wanted
to try the technique out and figured tuples would be a good test of
the technique. So I started hacking away and came up with this first
attempt at part of the cons template (the back bone of the tuple):

struct nil { };

template <typename T>
struct cons_select
{
  template <typename H, typename T>
  struct cons_type
  {
    typedef H head_type;
    typedef T tail_type;
    H head;
    T tail;
  };
};

template <>
struct cons_select<nil>
{
  template <typename H, typename T>
  struct cons_type
  {
    typedef H head_type;
    H head;
  };
};

template <typename H, typename T>
struct cons : cons_select<T>::cons_type<H, T>
{
};

Looked good, but didn't compile. I received the following error with
this code:

d:\hold\boost\tuple\tuple.h(26) : error C2516: 'cons_type<`template-
parameter257',`template-parameter258'>' : is not a legal base class
        d:\hold\boost\tuple\tuple.h(29) : see reference to class
template instantiation 'cons<H,T>' being compiled

I couldn't see anything wrong with the code so I spent a full day
hacking away with variations on the idea, just to discover VC++ has a
parsing bug (go figure) that can be worked around simply by changing
the order of template parameters for cons<> (template <typename T,
typename H>)! Makes no sense to me, but it works.

I've uploaded a complete tuple implementation that compiles under
VC++ (ver 6, SP 4) to the lambda folder (in a subfolder) so you can
take a look at what was required to do this. The code is based off
of the article "Tuples and multiple return values in C++", and so
isn't completely compatible with the implementation in LL (yet), but
it compiles cleanly and passes preliminary test code. I'm not sure
about the efficiency of the code produced, but at least I've got a
working tuple!

Bill Kempf


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