1 // Copyright Neil Groves 2010. Use, modification and 2 // distribution is subject to the Boost Software License, Version 3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at 4 // http://www.boost.org/LICENSE_1_0.txt) 5 // 6 // 7 // For more information, see http://www.boost.org/libs/range/ 8 // 9 #ifndef BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED 10 #define BOOST_RANGE_COUNTING_RANGE_HPP_INCLUDED 11 12 #include <boost/config.hpp> 13 #if BOOST_MSVC >= 1400 14 #pragma warning(push) 15 #pragma warning(disable : 4244) 16 #endif 17 18 #include <boost/range/iterator_range_core.hpp> 19 #include <boost/range/value_type.hpp> 20 #include <boost/range/iterator.hpp> 21 #include <boost/iterator/counting_iterator.hpp> 22 23 namespace boost 24 { 25 template<class Value> 26 inline iterator_range<counting_iterator<Value> > counting_range(Value first,Value last)27 counting_range(Value first, Value last) 28 { 29 typedef counting_iterator<Value> counting_iterator_t; 30 typedef iterator_range<counting_iterator_t> result_t; 31 return result_t(counting_iterator_t(first), 32 counting_iterator_t(last)); 33 } 34 35 template<class Range> 36 inline iterator_range< 37 counting_iterator< 38 BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type 39 > 40 > counting_range(const Range & rng)41 counting_range(const Range& rng) 42 { 43 typedef counting_iterator< 44 BOOST_DEDUCED_TYPENAME range_iterator<const Range>::type 45 > counting_iterator_t; 46 47 typedef iterator_range<counting_iterator_t> result_t; 48 49 return result_t(counting_iterator_t(boost::begin(rng)), 50 counting_iterator_t(boost::end(rng))); 51 } 52 53 template<class Range> 54 inline iterator_range< 55 counting_iterator< 56 BOOST_DEDUCED_TYPENAME range_iterator<Range>::type 57 > 58 > counting_range(Range & rng)59 counting_range(Range& rng) 60 { 61 typedef counting_iterator< 62 BOOST_DEDUCED_TYPENAME range_iterator<Range>::type 63 > counting_iterator_t; 64 65 typedef iterator_range<counting_iterator_t> result_t; 66 67 return result_t(counting_iterator_t(boost::begin(rng)), 68 counting_iterator_t(boost::end(rng))); 69 } 70 } // namespace boost 71 72 #if BOOST_MSVC >= 1400 73 #pragma warning(pop) 74 #endif 75 76 #endif // include guard 77