Skip to content

Commit

Permalink
Merge pull request #2750 from STEllAR-GROUP/iterator_range
Browse files Browse the repository at this point in the history
Replace boost::iterator_range
  • Loading branch information
hkaiser committed Jul 10, 2017
2 parents af22d33 + bfed508 commit 2f630ce
Show file tree
Hide file tree
Showing 32 changed files with 247 additions and 135 deletions.
Expand Up @@ -1167,7 +1167,7 @@ namespace hpx
//
// std::vector<future<void>> assign_lazy_sync;
// for (partition_description_type const& p,
// boost::make_iterator_range(partitions_.begin(),
// util::make_iterator_range(partitions_.begin(),
// partitions_.end() - 1)
// )
// {
Expand Down
6 changes: 3 additions & 3 deletions hpx/compute/host/block_executor.hpp
Expand Up @@ -16,11 +16,11 @@
#include <hpx/traits/executor_traits.hpp>
#include <hpx/traits/is_executor.hpp>
#include <hpx/util/deferred_call.hpp>
#include <hpx/util/iterator_range.hpp>
#include <hpx/util/range.hpp>
#include <hpx/util/unwrapped.hpp>

#include <boost/atomic.hpp>
#include <boost/range/iterator_range.hpp>

#include <algorithm>
#include <cstddef>
Expand Down Expand Up @@ -163,7 +163,7 @@ namespace hpx { namespace compute { namespace host
parallel::execution::bulk_async_execute(
executors_[i],
std::forward<F>(f),
boost::make_iterator_range(begin, part_end),
util::make_iterator_range(begin, part_end),
std::forward<Ts>(ts)...);
results.insert(
results.end(),
Expand Down Expand Up @@ -205,7 +205,7 @@ namespace hpx { namespace compute { namespace host
parallel::execution::bulk_sync_execute(
executors_[i],
std::forward<F>(f),
boost::make_iterator_range(begin, part_end),
util::make_iterator_range(begin, part_end),
std::forward<Ts>(ts)...);
results.insert(
results.end(),
Expand Down
11 changes: 5 additions & 6 deletions hpx/parallel/util/detail/chunk_size.hpp
Expand Up @@ -9,6 +9,7 @@
#include <hpx/config.hpp>
#include <hpx/lcos/future.hpp>
#include <hpx/util/decay.hpp>
#include <hpx/util/iterator_range.hpp>
#include <hpx/util/tuple.hpp>

#include <hpx/parallel/algorithms/detail/is_negative.hpp>
Expand All @@ -22,8 +23,6 @@
#include <type_traits>
#include <vector>

#include <boost/range/iterator_range.hpp>

///////////////////////////////////////////////////////////////////////////////
namespace hpx { namespace parallel { namespace util { namespace detail
{
Expand Down Expand Up @@ -55,7 +54,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
template <typename ExPolicy, typename Future, typename F1,
typename FwdIter, typename Stride>
// requires traits::is_future<Future>
boost::iterator_range<parallel::util::detail::chunk_size_iterator<FwdIter> >
hpx::util::iterator_range<parallel::util::detail::chunk_size_iterator<FwdIter> >
get_bulk_iteration_shape(
ExPolicy && policy, std::vector<Future>& workitems, F1 && f1,
FwdIter& begin, std::size_t& count, Stride s, std::false_type)
Expand Down Expand Up @@ -122,7 +121,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
iterator shape_begin(begin, chunk_size, count);
iterator shape_end(last, chunk_size);

return boost::make_iterator_range(shape_begin, shape_end);
return hpx::util::make_iterator_range(shape_begin, shape_end);
}

template <typename ExPolicy, typename Future, typename F1,
Expand Down Expand Up @@ -209,7 +208,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
template <typename ExPolicy, typename Future, typename F1,
typename FwdIter, typename Stride>
// requires traits::is_future<Future>
boost::iterator_range<
hpx::util::iterator_range<
parallel::util::detail::chunk_size_idx_iterator<FwdIter>
>
get_bulk_iteration_shape_idx(
Expand Down Expand Up @@ -280,7 +279,7 @@ namespace hpx { namespace parallel { namespace util { namespace detail
iterator shape_begin(begin, chunk_size, count, base_idx);
iterator shape_end(last, chunk_size);

return boost::make_iterator_range(shape_begin, shape_end);
return hpx::util::make_iterator_range(shape_begin, shape_end);
}

template <typename ExPolicy, typename Future, typename F1,
Expand Down
6 changes: 3 additions & 3 deletions hpx/util/histogram.hpp
Expand Up @@ -7,8 +7,8 @@
#define HISTOGRAM_HPP

#include <hpx/config.hpp>
#include <hpx/util/iterator_range.hpp>

#include <boost/range/iterator_range.hpp>
#include <boost/parameter/keyword.hpp>
#include <boost/accumulators/framework/accumulator_base.hpp>
#include <boost/accumulators/framework/extractor.hpp>
Expand Down Expand Up @@ -73,7 +73,7 @@ namespace hpx { namespace util
typedef std::vector<float_type> array_type;

// for boost::result_of
typedef boost::iterator_range<
typedef util::iterator_range<
typename histogram_type::iterator
> result_type;

Expand Down Expand Up @@ -158,7 +158,7 @@ namespace hpx { namespace util
}

// returns a range of pairs
return boost::make_iterator_range(this->histogram_);
return util::make_iterator_range(this->histogram_);
}

private:
Expand Down
94 changes: 94 additions & 0 deletions hpx/util/iterator_range.hpp
@@ -0,0 +1,94 @@
// Copyright (c) 2017 Agustin Berge
//
// Distributed under 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)

#ifndef HPX_UTIL_ITERATOR_RANGE_HPP
#define HPX_UTIL_ITERATOR_RANGE_HPP

#include <hpx/config.hpp>
#include <hpx/traits/is_range.hpp>
#include <hpx/traits/is_iterator.hpp>
#include <hpx/util/range.hpp>

#include <cstddef>
#include <iterator>
#include <type_traits>
#include <utility>

namespace hpx { namespace util
{
template <typename Iterator, typename Sentinel = Iterator>
class iterator_range
{
public:
iterator_range()
: _iterator()
, _sentinel()
{}

iterator_range(Iterator iterator, Sentinel sentinel)
: _iterator(std::move(iterator))
, _sentinel(std::move(sentinel))
{}

Iterator begin() const
{
return _iterator;
}

Iterator end() const
{
return _sentinel;
}

std::ptrdiff_t size() const
{
return std::distance(_iterator, _sentinel);
}

bool empty() const
{
return _iterator == _sentinel;
}

private:
Iterator _iterator;
Sentinel _sentinel;
};

template <
typename Range,
typename Iterator = typename traits::range_iterator<Range>::type,
typename Sentinel = typename traits::range_iterator<Range>::type>
typename std::enable_if<
traits::is_range<Range>::value,
iterator_range<Iterator, Sentinel>
>::type make_iterator_range(Range& r)
{
return iterator_range<Iterator, Sentinel>(util::begin(r), util::end(r));
}

template <
typename Range,
typename Iterator = typename traits::range_iterator<Range const>::type,
typename Sentinel = typename traits::range_iterator<Range const>::type>
typename std::enable_if<
traits::is_range<Range>::value,
iterator_range<Iterator, Sentinel>
>::type make_iterator_range(Range const& r)
{
return iterator_range<Iterator, Sentinel>(util::begin(r), util::end(r));
}

template <typename Iterator, typename Sentinel = Iterator>
typename std::enable_if<
traits::is_iterator<Iterator>::value,
iterator_range<Iterator, Sentinel>
>::type make_iterator_range(Iterator iterator, Sentinel sentinel)
{
return iterator_range<Iterator, Sentinel>(iterator, sentinel);
}
}}

#endif /*HPX_UTIL_ITERATOR_RANGE_HPP*/
5 changes: 2 additions & 3 deletions tests/regressions/lcos/future_range_ambiguity_2032.cpp
Expand Up @@ -7,12 +7,11 @@

#include <hpx/include/traits.hpp>
#include <hpx/include/lcos.hpp>

#include <boost/range/iterator_range.hpp>
#include <hpx/util/iterator_range.hpp>

#include <vector>

typedef boost::iterator_range<
typedef hpx::util::iterator_range<
std::vector<hpx::shared_future<void> >::iterator
> future_range;

Expand Down
3 changes: 2 additions & 1 deletion tests/regressions/util/protect_with_nullary_pfo.cpp
Expand Up @@ -9,6 +9,7 @@
#include <hpx/include/util.hpp>
#include <hpx/include/lcos.hpp>
#include <hpx/util/bind.hpp>
#include <hpx/util/iterator_range.hpp>
#include <hpx/util/protect.hpp>

#include <boost/format.hpp>
Expand Down Expand Up @@ -47,7 +48,7 @@ int hpx_main()
iterator_type itr_b = v1.begin();
iterator_type itr_e = v1.end();

typedef boost::iterator_range<iterator_type> range_type;
typedef hpx::util::iterator_range<iterator_type> range_type;

range_type my_range(itr_b, itr_e);

Expand Down
9 changes: 5 additions & 4 deletions tests/unit/parallel/container_algorithms/copy_range.cpp
Expand Up @@ -8,6 +8,7 @@
#include <hpx/hpx.hpp>
#include <hpx/include/parallel_copy.hpp>
#include <hpx/util/lightweight_test.hpp>
#include <hpx/util/iterator_range.hpp>

#include <cstddef>
#include <iostream>
Expand Down Expand Up @@ -187,7 +188,7 @@ void test_copy_exception(ExPolicy policy, IteratorTag)
bool caught_exception = false;
try {
hpx::parallel::copy(policy,
boost::make_iterator_range(
hpx::util::make_iterator_range(
decorated_iterator(
std::begin(c),
[](){ throw std::runtime_error("test"); }),
Expand Down Expand Up @@ -222,7 +223,7 @@ void test_copy_exception_async(ExPolicy p, IteratorTag)
try {
auto f =
hpx::parallel::copy(p,
boost::make_iterator_range(
hpx::util::make_iterator_range(
decorated_iterator(
std::begin(c),
[](){ throw std::runtime_error("test"); }),
Expand Down Expand Up @@ -294,7 +295,7 @@ void test_copy_bad_alloc(ExPolicy policy, IteratorTag)
bool caught_bad_alloc = false;
try {
hpx::parallel::copy(policy,
boost::make_iterator_range(
hpx::util::make_iterator_range(
decorated_iterator(
std::begin(c),
[](){ throw std::bad_alloc(); }),
Expand Down Expand Up @@ -328,7 +329,7 @@ void test_copy_bad_alloc_async(ExPolicy p, IteratorTag)
try {
auto f =
hpx::parallel::copy(p,
boost::make_iterator_range(
hpx::util::make_iterator_range(
decorated_iterator(
std::begin(c),
[](){ throw std::bad_alloc(); }),
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/parallel/container_algorithms/foreach_tests.hpp
Expand Up @@ -8,6 +8,7 @@

#include <hpx/include/parallel_container_algorithm.hpp>
#include <hpx/util/lightweight_test.hpp>
#include <hpx/util/iterator_range.hpp>

#include <cstddef>
#include <iostream>
Expand All @@ -31,7 +32,7 @@ void test_for_each(ExPolicy && policy, IteratorTag)
std::iota(std::begin(c), std::end(c), std::rand());

hpx::parallel::for_each(std::forward<ExPolicy>(policy),
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) {
Expand Down Expand Up @@ -59,7 +60,7 @@ void test_for_each_async(ExPolicy && p, IteratorTag)

hpx::future<void> f =
hpx::parallel::for_each(std::forward<ExPolicy>(p),
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) {
Expand Down Expand Up @@ -92,7 +93,7 @@ void test_for_each_exception(ExPolicy policy, IteratorTag)
bool caught_exception = false;
try {
hpx::parallel::for_each(policy,
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) { throw std::runtime_error("test"); });
Expand Down Expand Up @@ -124,7 +125,7 @@ void test_for_each_exception_async(ExPolicy p, IteratorTag)
try {
hpx::future<void> f =
hpx::parallel::for_each(p,
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) { throw std::runtime_error("test"); });
Expand Down Expand Up @@ -160,7 +161,7 @@ void test_for_each_bad_alloc(ExPolicy policy, IteratorTag)
bool caught_exception = false;
try {
hpx::parallel::for_each(policy,
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) { throw std::bad_alloc(); });
Expand Down Expand Up @@ -191,7 +192,7 @@ void test_for_each_bad_alloc_async(ExPolicy p, IteratorTag)
try {
hpx::future<void> f =
hpx::parallel::for_each(p,
boost::make_iterator_range(
hpx::util::make_iterator_range(
iterator(std::begin(c)), iterator(std::end(c))
),
[](std::size_t& v) { throw std::bad_alloc(); });
Expand Down

0 comments on commit 2f630ce

Please sign in to comment.