Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84466 - trunk/boost/graph/detail
From: jewillco_at_[hidden]
Date: 2013-05-24 17:19:22


Author: jewillco
Date: 2013-05-24 17:19:21 EDT (Fri, 24 May 2013)
New Revision: 84466
URL: http://svn.boost.org/trac/boost/changeset/84466

Log:
Chaned project1st and project2nd function objects to return copies rather than references to arguments, preventing a dangling reference when the type of the argument passed in is not exactly the same as the template argument of the projection function object
Text files modified:
   trunk/boost/graph/detail/histogram_sort.hpp | 9 +++++++--
   1 files changed, 7 insertions(+), 2 deletions(-)

Modified: trunk/boost/graph/detail/histogram_sort.hpp
==============================================================================
--- trunk/boost/graph/detail/histogram_sort.hpp (original)
+++ trunk/boost/graph/detail/histogram_sort.hpp 2013-05-24 17:19:21 EDT (Fri, 24 May 2013)
@@ -274,16 +274,21 @@
   }
 }
 
+// The versions of operator()() here can't return by reference because the
+// actual type passed in may not match Pair, in which case the reference
+// parameter is bound to a temporary that could end up dangling after the
+// operator returns.
+
 template <typename Pair>
 struct project1st {
   typedef typename Pair::first_type result_type;
- const result_type& operator()(const Pair& p) const {return p.first;}
+ result_type operator()(const Pair& p) const {return p.first;}
 };
 
 template <typename Pair>
 struct project2nd {
   typedef typename Pair::second_type result_type;
- const result_type& operator()(const Pair& p) const {return p.second;}
+ result_type operator()(const Pair& p) const {return p.second;}
 };
 
     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk