Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70690 - trunk/boost/range/algorithm
From: neil_at_[hidden]
Date: 2011-03-29 06:27:02


Author: neilgroves
Date: 2011-03-29 06:27:00 EDT (Tue, 29 Mar 2011)
New Revision: 70690
URL: http://svn.boost.org/trac/boost/changeset/70690

Log:
[boost][range] - Improve the forwarding of the functor, and provide a work-around for the breaking changes in VC10 for_each.
Text files modified:
   trunk/boost/range/algorithm/for_each.hpp | 67 ++++++++++++++++++++++++++++++++++++++-
   1 files changed, 64 insertions(+), 3 deletions(-)

Modified: trunk/boost/range/algorithm/for_each.hpp
==============================================================================
--- trunk/boost/range/algorithm/for_each.hpp (original)
+++ trunk/boost/range/algorithm/for_each.hpp 2011-03-29 06:27:00 EDT (Tue, 29 Mar 2011)
@@ -13,13 +13,52 @@
 #include <boost/range/begin.hpp>
 #include <boost/range/end.hpp>
 #include <boost/range/concepts.hpp>
+#include <boost/ref.hpp>
 #include <algorithm>
 
+#if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
+#include <xutility>
+#endif
+
 namespace boost
 {
     namespace range
     {
 
+#if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
+ namespace for_each_detail
+ {
+ template<typename Iterator, typename UnaryFunction>
+ inline UnaryFunction
+ for_each_impl(Iterator first, Iterator last, UnaryFunction fun,
+ typename enable_if<
+ is_reference_wrapper<UnaryFunction>,
+ void
+ >::type* = 0)
+ {
+ typedef typename std::_Get_unchecked_type<Iterator>::type
+ unchecked_iterator;
+
+ unchecked_iterator unchecked_last = std::_Unchecked(last);
+ for (unchecked_iterator unchecked_first = std::_Unchecked(first); first != last; ++first)
+ fun.get()(*unchecked_first);
+
+ return fun;
+ }
+
+ template<typename Iterator, typename UnaryFunction>
+ inline UnaryFunction
+ for_each_impl(Iterator first, Iterator last, UnaryFunction fn,
+ typename disable_if<
+ is_reference_wrapper<UnaryFunction>,
+ void
+ >::type* = 0)
+ {
+ return std::for_each(first, last, fn);
+ }
+ }
+#endif
+
 /// \brief template function for_each
 ///
 /// range-based version of the for_each std algorithm
@@ -30,7 +69,18 @@
 inline UnaryFunction for_each(SinglePassRange & rng, UnaryFunction fun)
 {
     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> ));
- return std::for_each(boost::begin(rng),boost::end(rng),fun);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
+ return for_each_detail::for_each_impl<
+ typename range_iterator<SinglePassRange>::type,
+ UnaryFunction
+ >(boost::begin(rng), boost::end(rng), fun);
+#else
+ return std::for_each<
+ BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type,
+ UnaryFunction
+ >(boost::begin(rng),boost::end(rng),fun);
+#endif
 }
 
 /// \overload
@@ -38,11 +88,22 @@
 inline UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun)
 {
     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
- return std::for_each(boost::begin(rng), boost::end(rng), fun);
+
+#if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
+ return for_each_detail::for_each_impl<
+ typename range_iterator<const SinglePassRange>::type,
+ UnaryFunction
+ >(boost::begin(rng), boost::end(rng), fun);
+#else
+ return std::for_each<
+ BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type,
+ UnaryFunction
+ >(boost::begin(rng), boost::end(rng), fun);
+#endif
 }
 
     } // namespace range
     using range::for_each;
 } // namespace boost
 
-#endif // include guard
+#endif // include guard
\ No newline at end of file


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