Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:59:16

0001 //  Copyright Neil Groves 2009. Use, modification and
0002 //  distribution is subject to the Boost Software License, Version
0003 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 //
0006 //
0007 // For more information, see http://www.boost.org/libs/range/
0008 //
0009 #ifndef BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
0010 #define BOOST_RANGE_ALGORITHM_FOR_EACH_HPP_INCLUDED
0011 
0012 #include <boost/concept_check.hpp>
0013 #include <boost/range/begin.hpp>
0014 #include <boost/range/end.hpp>
0015 #include <boost/range/concepts.hpp>
0016 #include <boost/utility/enable_if.hpp>
0017 #include <boost/ref.hpp>
0018 #include <algorithm>
0019 
0020 #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
0021 #include <xutility>
0022 #endif
0023 
0024 namespace boost
0025 {
0026     namespace range
0027     {
0028 
0029 #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
0030         namespace for_each_detail
0031         {
0032             template<typename Iterator, typename UnaryFunction>
0033             inline UnaryFunction
0034             for_each_impl(Iterator first, Iterator last, UnaryFunction fun,
0035                           typename ::boost::enable_if<
0036                             is_reference_wrapper<UnaryFunction>,
0037                             void
0038                           >::type* = 0)
0039             {
0040                     typedef typename std::_Get_unchecked_type<Iterator>::type
0041                                 unchecked_iterator;
0042 
0043                     unchecked_iterator unchecked_last = std::_Unchecked(last);
0044                     for (unchecked_iterator unchecked_first = std::_Unchecked(first); first != last; ++first)
0045                             fun.get()(*unchecked_first);
0046 
0047                     return fun;
0048             }
0049 
0050             template<typename Iterator, typename UnaryFunction>
0051             inline UnaryFunction
0052             for_each_impl(Iterator first, Iterator last, UnaryFunction fn,
0053                           typename disable_if<
0054                             is_reference_wrapper<UnaryFunction>,
0055                             void
0056                           >::type* = 0)
0057             {
0058                 return std::for_each<Iterator, UnaryFunction>(first, last, fn);
0059             }
0060         }
0061 #endif
0062 
0063 /// \brief template function for_each
0064 ///
0065 /// range-based version of the for_each std algorithm
0066 ///
0067 /// \pre SinglePassRange is a model of the SinglePassRangeConcept
0068 /// \pre UnaryFunction is a model of the UnaryFunctionConcept
0069 template< class SinglePassRange, class UnaryFunction >
0070 inline UnaryFunction for_each(SinglePassRange & rng, UnaryFunction fun)
0071 {
0072     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<SinglePassRange> ));
0073     
0074 #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
0075         return for_each_detail::for_each_impl<
0076                 typename range_iterator<SinglePassRange>::type,
0077                 UnaryFunction
0078         >(boost::begin(rng), boost::end(rng), fun);
0079 #else
0080     return std::for_each<
0081         BOOST_DEDUCED_TYPENAME range_iterator<SinglePassRange>::type,
0082         UnaryFunction
0083     >(boost::begin(rng),boost::end(rng),fun);
0084 #endif    
0085 }
0086 
0087 /// \overload
0088 template< class SinglePassRange, class UnaryFunction >
0089 inline UnaryFunction for_each(const SinglePassRange& rng, UnaryFunction fun)
0090 {
0091     BOOST_RANGE_CONCEPT_ASSERT(( SinglePassRangeConcept<const SinglePassRange> ));
0092     
0093 #if BOOST_WORKAROUND(BOOST_MSVC, == 1600)
0094         return for_each_detail::for_each_impl<
0095                 typename range_iterator<const SinglePassRange>::type,
0096                 UnaryFunction
0097         >(boost::begin(rng), boost::end(rng), fun);
0098 #else    
0099     return std::for_each<
0100         BOOST_DEDUCED_TYPENAME range_iterator<const SinglePassRange>::type,
0101         UnaryFunction
0102     >(boost::begin(rng), boost::end(rng), fun);
0103 #endif    
0104 }
0105 
0106     } // namespace range
0107     using range::for_each;
0108 } // namespace boost
0109 
0110 #endif // include guard