Boost logo

Boost :

From: Jason House (jhouse_at_[hidden])
Date: 2003-01-23 17:54:48


"Rozental, Gennadiy" wrote:
>
> First of all there are several glitches here:
> I am not sure that you allowed to use template parameter for defining
> partial specialization.

Well, is it allowed? I am new to generic programming stuff, so forgive
any stupid comments I make... If I remember right, a templated
definition is only evaluated for a specific instance... I'd think that
when it is read for an instance, that a given template paramater should
then be well defined, and that specialization using a template parameter
shouldn't be a problem.... or at least conceptually... I can definitely
see it being an odd case for a compiler.

> Even if above class definition is allowed foobar.var<Cash> will be invalud
> cause var<Cash> is a type name. So basically what you are doing is unusable.

Ok, some updated code for the class definition, hopefully it will make
more sense. Something like this didn't compile as well in visual
studio, so I didn't post that code.

template <typename _T1, int _Name1, typename _T2, int _Name2>
class named_pair: pair<_T1,_T2>{
  public:

  template <int _Name>
  void var();

  _T1& var<_Name1>() {return First}; //VC6 dislikes these 2 lines
  _T2& var<_Name2>() {return Second}; //(different return type)
};

enum{ Cash, Name };

void main(int argc, char *argv[]){
  named_pair<float, Cash, char*, Name> foobar;

  foobar.var<Cash>() = 32.2;
  foobar.var<Name>() = "Fred";
}

> Look on MPL example for inherit_linear. It may have what you need.

Well, as I said, I'm new... I can find mpl documentation, but searches
for inherit_linear came up with nothing.

Maybe I should try and make my goal clearer. I wanted to be able to
define a collection of variables for use with STL that is as simple to
define as a struct. The difference being that all the useful operators
are defined... comparisons, assignments, etc...

The associative type list looks like it does exactly what I wanted, as
far as having a name to associate with retrieval of a specific
variable. But it lacks the nice default copy constructor and less than
operator.

I assume that the associative list is only a list at compile time? Does
it compile to efficient code? If so, a simple wrapper around it could
do what I wanted, and still retain whatever other special features it
has.


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