Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-01-15 19:26:02

Larry Evans wrote:

> OK. I read the page differently. I thought it meant that
> there was difficult or impossible to access the elements. Then there's
> the sentence on p. 191:
> We can't access any other than the first one directly.
> OK, I guess "can't access directly" does not mean "can't access",


> but then consider the next paragraph:
> it's difficult to access the value member of a given type even by
> casting to an appropriate base class.
> This leaves me with the impression that it's "difficult" to access
> members other than the first; yet a template member function such as
> boost::tuple's, get<1>, doesn't seem difficult, at least to me.

It's not difficult if you have the function. In any case the code in
the book is looking up a member by its type, not by its index.

> I've replaced the file with another, get_inherit_side_test.cpp, which,
> in test_instantiate(void), actually creates an instance of the
> tuple_type and accesses the 0-th element with:
> t.get_inherit_side<inherit_side_right,tuple_type,0>::type::left_type::value;
> Obviously, this could be shortened with a member template,
> t.get<0>()
> which simply returned the above expression. The uploaded code compiles
> with just a warning about t being used before it's defined.

>> The code in your posting used the construct
>> r.get_tail< .... >
>> I don't see how that can compile unless something is defined with a
>> member template called "get_tail."
> Sorry, I should have said:
> r.get_tail<...>::head_type::value;

That wouldn't have changed anything. I wasn't confused about the lack
of something after ">" (heck, it might have been there for all I know).
There was no member function template called get_tail, which makes the
above just as un-compilable as whatever you wrote before.

> but then I would have had to provide the code like that in the
> newly uploaded file, and it didn't seem, at the time, necessary
> to demonstrate my point.

>> It's certainly more difficult than typing
>> The book isn't making a very deep point there, but the point it does
>> make is valid.
> OK, but I, and maybe others, are interpreting the page as meaning
> inherit_linearly is less capable than tuple as far as accessing
> the elements.

First of all, nothing in the book gives you any reason to think the text
is saying it's difficult compared to working with boost::tuple. We
don't even mention boost::tuple there.

Second of all, by itself, of course the **result of invoking
inherit_linearly** shown on that page is less capable than tuple,
because there's no convenient access function like get<> provided.

Finally, the kind of access being done is completely different from
what's done with tuple.

I think I'll wait to see if anyone else is confused by this before
worrying about it. :o)

Dave Abrahams
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at