lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Why does this crash?


From: Greg Chicares
Subject: Re: [lmi] Why does this crash?
Date: Sat, 17 Apr 2010 15:21:58 +0000
User-agent: Thunderbird 2.0.0.24 (Windows/20100228)

On 2010-04-17 14:43Z, Vadim Zeitlin wrote:
> On Sat, 17 Apr 2010 14:03:57 +0000 Greg Chicares <address@hidden> wrote:
> 
> GC> with the patch below (it's fine without). Shouldn't this principle:
> GC>   
> http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/
> GC> apply here?
> 
>  The principle applies only when you assign the value returned by the
> function to a (const) reference. It doesn't apply if you use it in any
> other way.

I thought I had done that:

  xml::element const& e = *xml_lmi::retrieve_element(parent, name);

but I *dereferenced* the iterator that retrieve_element() returned:
that's what I was missing.

>  I.e. the only improvement I see here is that you could write
> 
>       xml::node::const_iterator const& i = xml_lmi::retrieve_element(parent, 
> name);
> 
> to avoid making a copy of the iterator. You still need to name it to ensure
> that its lifetime extends to the end of the block.

Without testing, I'd guess that copying the iterator costs little,
and might even be optimized away. Anyway, I wasn't looking for an
improvement; I had written it the incorrect way the first time,
then changed it to the correct form before committing, and I just
couldn't see where the mistake was. Thanks.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]