Boost logo

Boost :

From: Gary Powell (Gary.Powell_at_[hidden])
Date: 2001-06-19 17:57:40


> [John Max Skaller]
> 2. Why the limit of 10 elements? Why not 20? Is the limit documented?
> [Gary]
> Laziness. :>,

        :-)

> At some point there will be a limit. What is reasonable? Do you even have
a
> use for 20?

        No. But I regularly use tuples of up to 6 or 7 elements,
which is too close to 10 for comfort, IMHO.
[Gary]
I see what you mean, I'll talk to Jaakko, but for the first release I'd
rather not add another 10. But maybe Jaakko won't mind.

> [John Max Skaller]
> 3. How does one get a pointer to member? [ptm]

> [Gary]
> use bind? But then that assumes you want to hold an element as well.
>
> How about this:
>
> tuple<ResultType (ObjectType::*)()> foo(ResultType (ObjectType::* const
&f)
> () )
> {
> return tuple<ResultType (ObjectType::*)()>(f);
> }
>
> Here a function foo, takes a member function f, from class ObjectType,
> returning a ResultType, which takes no arguments.) And the function foo
> returns a tuple holding that pointer to member.
>
> And did you really want to know this, or just want us to put it in the
docs?

        Urgle :-) I don't understand. Here is a tuple:

        tuple<int, float>

and I want to get a pointer to member 'float' ptm so that

        tuple<int, float> x;
        float i = x.*ptm;

I want something equivalent to

        get_ptm<N, T>()

which is a pointer to the n'th member of the tuple type T,
so I can write:

        float (tuple<int,float>::*ptm) = get_ptm<2,tuple<int,float> >();

If the tuple had named members, I could write:

        &tuple<int,float>::mem_2 // did I get the syntax right?

but it doesn't have named members, so you have to provide
a function which does the equivalent job.

[Gary]
Well I don't think you can get what you want here. (Maybe Jaakko will answer
this better.)
Anyway my understanding of this goes as follows:

A tuple<int, float>

contains the element from public inheritance a
   cons<int, cons<float, nil> > type;

And thus,

  &tuple::cons<int, cons<float, nil> >::head.tail.head

is the pointer to the member you wanted. But ugh!

I'm a bit confused as to the why this sort of access is necessary. (As it
requires you to know all the types within the tuple.) Do you have an example
of the sort of problem you are solving with this technique? Then maybe I'll
understand the issues better.

Thanks again for all the comments.

   Yours,
  -gary-


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