Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 1999-12-08 09:44:22


Nathan describes exactly what my problem was. The solution was to simply
convert foo to take an iterator instead of a reference. I was successful
in this conversion for every method I needed to call (in sort) except
swap. And calling iter_swap didn't help as that simply calls swap.
vector<bool>::iterator already had the solution on this one by having a
specialized swap method.

So at least for me, one requirement of a proxied iterator is that it
offer a specialization of any method that the algorithm must call with a
T& (e.g. sort requires swap(iter, iter)). And a requirement on the
algorithm is that it not call anything taking a T& except for those
methods that the proxied iterator are required to specialize.

Note that the only reason vector<bool>::iterator __had__ to specialize
swap was for performance reasons. iter_swap could be used in sort and
implemented without calling swap, but at the cost of possibly missing the
specialized swap for heavy weight objects.

-Howard

Greg Colvin wrote on 12/8/99 2:56 AM
>How does this square with Howards experience with making the
>algorithms work for vector<bool>?
>
>----- Original Message -----
>From: Nathan Myers <ncm_at_[hidden]>
>To: <boost_at_[hidden]>
>Sent: Tuesday, December 07, 1999 7:07 PM
>Subject: [boost] Re: graph structure interface (proxies and forward
>iterators)
>
>
>Greg Colvin wrote:
>> ... being a stickler for the
>> return type of operator*() is not worth it. I'm not sure
>> whether we have a library issue or not, but given that we
>> have vector<bool> we will need to fix the ForwardIterator
>> requirements so that vector<bool>::interator conforms. That
>> fix might well apply to GGCL iterators.
>
>The problem solved by requiring operator* to return an actual T&
>is that template argument matching and type deduction cannot look
>past conversions or other apparatus. I.e., if you have a template
>
> template <typename T>
> void foo(T&);
>
>and you say
>
> foo(*it);
>
>, then it.operator*() had better return a T&, or you get a compile
>error. Casts are no help here, because the caller of foo() is little
>more likely to know T than foo() is, and in any case it may not work
>to convert it to a T&. (Typically, if it would, you would have
>returned T& directly from operator*()).
>
>Nathan Myers
>ncm_at_[hidden]
>
>
>------------------------------------------------------------------------
>et the most popular downloads on the Web. They9re new!
>They9re hot! They're FREE! Utilities, drivers, games.
>It's all here. http://clickhere.egroups.com/click/1610
>
>
>
>-- Create a poll/survey for your group!
>-- http://www.egroups.com/vote?listname=boost&m=1
>
>
>
>
>
>------------------------------------------------------------------------
>Join Garden.com's New Affiliate Program. We offer 20,000 products
>that include plants, tools, garden-inspired gifts & lots more! We will
>pay you $10 cash for referrals & up to 10% commission on every sale.
>http://clickhere.egroups.com/click/1903
>
>
>-- Talk to your group with your own voice!
>-- http://www.egroups.com/VoiceChatPage?listName=boost&m=1
>
>


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