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? In case it matters, AntiTree is a filtered_graph.
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
Douglas Gregor wrote:
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
Thanks for the sugguestion, looks useful and I'll give it a try. By the way, after you discouraged me from attempting to using a subgraph to represent a spanning tree, I discovered filtered_graph. This is exactly what I was looking for.
participants (2)
-
Douglas Gregor
-
Jeffrey Holle