|
Boost Users : |
From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2005-11-03 16:52:41
On Nov 3, 2005, at 12:23 PM, Jeffrey Holle wrote:
> I'm using gcc 4.0.2 with boost 1.33.0.
> I'm getting a compiler warning about taking the address of a
> temporary with the
> following code:
> Edge*
> TransshipmentPivotingRule::enteringEdge(const FeasibleSpanningTree*
> pFST)
> {
> graph_traits<AntiTree>::edge_iterator ei,ei_out;
> tie(ei,ei_out)=edges(*m_pAntiTree);
> return (find_if(ei,ei_out,
> ProfitableEdge(*m_pAntiTree,m_c,m_y,*pFST))!=ei_out) ?
> &*ei : NULL;
> }
>
> Note the "&*ei".
> I know that the iterator is tempory, but what the iterator is
> pointing to isn't.
> Is this a legit warning that I need to be concerned about?
It is probably a legitimate warning. Many of the iterators into
graphs actually do return temporaries, because they build vertex or
edge descriptors on-the-fly from a (typically smaller) internal
representation.
I'd suggest replacing the Edge* with boost::optional<Edge>. You'll
get about the same behavior but without the potential problems with
taking the address of a temporary.
Doug
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