Boost logo

Boost :

From: Greg Chicares (chicares_at_[hidden])
Date: 2001-09-05 07:19:33


Toon Knapen wrote:
>
> Greg Chicares wrote:
> > Given
> >
> > struct S
> > { int i0; int i1; double d0; std::string s0;};
> >
> > I would like to be able to write
> >
> > S s;
> > s["i0"] = "999.9"; // truncates to int
> > s["i1"] = "888e3"; // converts to int
> > s["d0"] = "777"; // converts to double
> > s["s0"] = "hello";
> >
>
> It would be very nice if you can put this functionality on top of the
> tuples library !
>
> toon

Please help me understand this idea better--I'm not sure what you
have in mind. For instance, taking this example from the documentation

  tuple<X,X,X>(string("Jaba"), string("Daba"), string("Duu"))

there don't seem to be 'natural' names to use for the three elements.

Are you thinking of using this with tiers? In this example

  int i; char c; double d;
  tie(i, c, d) = make_tuple(1,'a', 5.5);
  std::cout << i << " " << c << " " << d;

the scalars might be struct members

  struct C { int i; char c; double d; };

so that a tuple<int, char, double> would contain the same data.
Is the idea to reference tuple elements by indexing names like
"i" and "c"? Tuple::get<N> requires N to be a compile-time
constant (and a string literal can't be made to work), but we
could do indexing by name by creating a parallel struct
containing the same data.

Sorry if I'm overlooking something obvious...


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