indexing tuples using strings

Jason House jason.james.house at gmail.com
Mon Dec 1 14:14:08 PST 2008


Bill Baxter Wrote:

> On Tue, Dec 2, 2008 at 6:40 AM, Jarrett Billingsley
> <jarrett.billingsley at gmail.com> wrote:
> > On Mon, Dec 1, 2008 at 4:19 PM, llee <larry at workingwondersus.com> wrote:
> >> Is is possible to index the elements within a tuple using strings?
> >> Something similar to the way that associative arrays allow elements to be indexed using strings.
> >>
> >
> > No, because that makes no sense.
> >
> > What does tuple["string"] mean, anyway?
> 
> Tuples have an annoying "auto-flattening" behavior which means that
> it's difficult to create very advanced data structures out of them.
> But you can create a flat tuple a-list with entries like   "fred",
> int, "barney", double, "wilma", ireal
> Then you can write some template functions that will scan through the
> list for a particular string and return the following type if there's
> a match.  You will need to use lots of recursive template-fu.
> 
> --bb

... Or you can just loop over the tuple and return the matching index... No recursive template-foo needed



More information about the Digitalmars-d mailing list