|
Boost Users : |
From: Ben Hutchings (ben.hutchings_at_[hidden])
Date: 2003-04-24 12:36:27
dick.bridges_at_[hidden] wrote:
> This is one of the places where I get *REALLY* confused - the 'real'
code
> has multiple returns. Apologies: I should have included this psuedo
code
> in the original example. It looks like this.
>
> <snippet>
> // v is populated somewhere else
> typedef vector<shared_ptr<int> > V;
> V v;
>
> shared_ptr<int> maybe_get_a_pointer()
> {
> shared_ptr<int>::iterator itr;
> itr = find_if(v.begin(), v.end(), some_op);
>
> if(itr != v.end)
> return(*itr);
>
> shared_ptr<int> p;
> return(p);
> }
> </snippet>
>
> Are compilers supposed to be able to match *itr to p in order to apply
the
> NRVO?
I don't know what you mean by "match *itr to p".
The NRVO should be possible for the second return statement, because if
p is constructed then it's always returned. However, optimisations are
by definition optional so the implementation isn't "supposed to" perform
them.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net