summaryrefslogtreecommitdiff
path: root/boost/geometry/util/range.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/geometry/util/range.hpp')
-rw-r--r--boost/geometry/util/range.hpp78
1 files changed, 60 insertions, 18 deletions
diff --git a/boost/geometry/util/range.hpp b/boost/geometry/util/range.hpp
index fe3502f..cf69413 100644
--- a/boost/geometry/util/range.hpp
+++ b/boost/geometry/util/range.hpp
@@ -2,15 +2,15 @@
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
-// This file was modified by Oracle on 2013, 2014.
-// Modifications copyright (c) 2013-2014 Oracle and/or its affiliates.
+// This file was modified by Oracle on 2013, 2014, 2015.
+// Modifications copyright (c) 2013-2015 Oracle and/or its affiliates.
+
+// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
-// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
-
#ifndef BOOST_GEOMETRY_UTIL_RANGE_HPP
#define BOOST_GEOMETRY_UTIL_RANGE_HPP
@@ -30,20 +30,63 @@
namespace boost { namespace geometry { namespace range {
-// NOTE: For SinglePassRanges at could iterate over all elements until the i-th element is met.
+namespace detail {
+
+// NOTE: For SinglePassRanges pos could iterate over all elements until the i-th element was met.
+
+template <typename RandomAccessRange>
+struct pos
+{
+ typedef typename boost::range_iterator<RandomAccessRange>::type iterator;
+ typedef typename boost::range_size<RandomAccessRange>::type size_type;
+ typedef typename boost::range_difference<RandomAccessRange>::type difference_type;
+
+ static inline iterator apply(RandomAccessRange & rng, size_type i)
+ {
+ BOOST_RANGE_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<RandomAccessRange> ));
+ return boost::begin(rng) + static_cast<difference_type>(i);
+ }
+};
+
+} // namespace detail
+
+/*!
+\brief Short utility to conveniently return an iterator of a RandomAccessRange.
+\ingroup utility
+*/
+template <typename RandomAccessRange>
+inline typename boost::range_iterator<RandomAccessRange const>::type
+pos(RandomAccessRange const& rng,
+ typename boost::range_size<RandomAccessRange const>::type i)
+{
+ BOOST_ASSERT(i <= boost::size(rng));
+ return detail::pos<RandomAccessRange const>::apply(rng, i);
+}
+
+/*!
+\brief Short utility to conveniently return an iterator of a RandomAccessRange.
+\ingroup utility
+*/
+template <typename RandomAccessRange>
+inline typename boost::range_iterator<RandomAccessRange>::type
+pos(RandomAccessRange & rng,
+ typename boost::range_size<RandomAccessRange>::type i)
+{
+ BOOST_ASSERT(i <= boost::size(rng));
+ return detail::pos<RandomAccessRange>::apply(rng, i);
+}
/*!
\brief Short utility to conveniently return an element of a RandomAccessRange.
\ingroup utility
*/
template <typename RandomAccessRange>
-inline typename boost::range_value<RandomAccessRange const>::type const&
+inline typename boost::range_reference<RandomAccessRange const>::type
at(RandomAccessRange const& rng,
typename boost::range_size<RandomAccessRange const>::type i)
{
- BOOST_RANGE_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<RandomAccessRange const> ));
BOOST_ASSERT(i < boost::size(rng));
- return *(boost::begin(rng) + i);
+ return * detail::pos<RandomAccessRange const>::apply(rng, i);
}
/*!
@@ -51,13 +94,12 @@ at(RandomAccessRange const& rng,
\ingroup utility
*/
template <typename RandomAccessRange>
-inline typename boost::range_value<RandomAccessRange>::type &
+inline typename boost::range_reference<RandomAccessRange>::type
at(RandomAccessRange & rng,
typename boost::range_size<RandomAccessRange>::type i)
{
- BOOST_RANGE_CONCEPT_ASSERT(( boost::RandomAccessRangeConcept<RandomAccessRange> ));
BOOST_ASSERT(i < boost::size(rng));
- return *(boost::begin(rng) + i);
+ return * detail::pos<RandomAccessRange>::apply(rng, i);
}
/*!
@@ -65,7 +107,7 @@ at(RandomAccessRange & rng,
\ingroup utility
*/
template <typename Range>
-inline typename boost::range_value<Range>::type const&
+inline typename boost::range_reference<Range const>::type
front(Range const& rng)
{
BOOST_ASSERT(!boost::empty(rng));
@@ -77,7 +119,7 @@ front(Range const& rng)
\ingroup utility
*/
template <typename Range>
-inline typename boost::range_value<Range>::type &
+inline typename boost::range_reference<Range>::type
front(Range & rng)
{
BOOST_ASSERT(!boost::empty(rng));
@@ -91,12 +133,12 @@ front(Range & rng)
\ingroup utility
*/
template <typename BidirectionalRange>
-inline typename boost::range_value<BidirectionalRange>::type const&
+inline typename boost::range_reference<BidirectionalRange const>::type
back(BidirectionalRange const& rng)
{
BOOST_RANGE_CONCEPT_ASSERT(( boost::BidirectionalRangeConcept<BidirectionalRange const> ));
BOOST_ASSERT(!boost::empty(rng));
- return *(--boost::end(rng));
+ return *(boost::rbegin(rng));
}
/*!
@@ -104,12 +146,12 @@ back(BidirectionalRange const& rng)
\ingroup utility
*/
template <typename BidirectionalRange>
-inline typename boost::range_value<BidirectionalRange>::type &
+inline typename boost::range_reference<BidirectionalRange>::type
back(BidirectionalRange & rng)
{
- BOOST_RANGE_CONCEPT_ASSERT(( boost::BidirectionalRangeConcept<BidirectionalRange> ));
+ BOOST_RANGE_CONCEPT_ASSERT((boost::BidirectionalRangeConcept<BidirectionalRange>));
BOOST_ASSERT(!boost::empty(rng));
- return *(--boost::end(rng));
+ return *(boost::rbegin(rng));
}