Skip to content

Commit

Permalink
Fixing all_of, any_of, and none_of
Browse files Browse the repository at this point in the history
  • Loading branch information
hkaiser committed Jun 23, 2017
1 parent 3887a5c commit dc23b2e
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 43 deletions.
80 changes: 52 additions & 28 deletions hpx/parallel/algorithms/all_any_none.hpp
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2014 Hartmut Kaiser
// Copyright (c) 2007-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -41,9 +41,9 @@ namespace hpx { namespace parallel { inline namespace v1
: none_of::algorithm("none_of")
{}

template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
static bool
sequential(ExPolicy, InIter first, InIter last, F && f)
sequential(ExPolicy, FwdIter first, FwdIter last, F && f)
{
return std::none_of(first, last, std::forward<F>(f));
}
Expand Down Expand Up @@ -109,9 +109,9 @@ namespace hpx { namespace parallel { inline namespace v1
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it applies user-provided function objects.
/// \tparam InIter The type of the source iterators used (deduced).
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// input iterator.
/// forward iterator.
/// \tparam F The type of the function/function object to use
/// (deduced). Unlike its sequential form, the parallel
/// overload of \a none_of requires \a F to meet the
Expand All @@ -134,7 +134,7 @@ namespace hpx { namespace parallel { inline namespace v1
/// The signature does not need to have const&, but
/// the function must not modify the objects passed
/// to it. The type \a Type must be such that an object
/// of type \a InIter can be dereferenced and then
/// of type \a FwdIter can be dereferenced and then
/// implicitly converted to Type.
///
/// The application of function objects in parallel algorithm
Expand All @@ -157,21 +157,29 @@ namespace hpx { namespace parallel { inline namespace v1
/// \a f returns true for no elements in the range, false
/// otherwise. It returns true if the range is empty.
///
template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
inline typename std::enable_if<
execution::is_execution_policy<ExPolicy>::value,
typename util::detail::algorithm_result<ExPolicy, bool>::type
>::type
none_of(ExPolicy && policy, InIter first, InIter last, F && f)
none_of(ExPolicy && policy, FwdIter first, FwdIter last, F && f)
{
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
static_assert(
(hpx::traits::is_input_iterator<InIter>::value),
(hpx::traits::is_input_iterator<FwdIter>::value),
"Requires at least input iterator.");

typedef std::integral_constant<bool,
execution::is_sequenced_execution_policy<ExPolicy>::value ||
!hpx::traits::is_forward_iterator<InIter>::value
!hpx::traits::is_forward_iterator<FwdIter>::value
> is_seq;
#else
static_assert(
(hpx::traits::is_forward_iterator<FwdIter>::value),
"Requires at least forward iterator.");

typedef execution::is_sequenced_execution_policy<ExPolicy> is_seq;
#endif

return detail::none_of().call(
std::forward<ExPolicy>(policy), is_seq(),
Expand All @@ -189,9 +197,9 @@ namespace hpx { namespace parallel { inline namespace v1
: any_of::algorithm("any_of")
{}

template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
static bool
sequential(ExPolicy, InIter first, InIter last, F && f)
sequential(ExPolicy, FwdIter first, FwdIter last, F && f)
{
return std::any_of(first, last, std::forward<F>(f));
}
Expand Down Expand Up @@ -257,9 +265,9 @@ namespace hpx { namespace parallel { inline namespace v1
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it applies user-provided function objects.
/// \tparam InIter The type of the source iterators used (deduced).
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// input iterator.
/// forward iterator.
/// \tparam F The type of the function/function object to use
/// (deduced). Unlike its sequential form, the parallel
/// overload of \a any_of requires \a F to meet the
Expand All @@ -282,7 +290,7 @@ namespace hpx { namespace parallel { inline namespace v1
/// The signature does not need to have const&, but
/// the function must not modify the objects passed
/// to it. The type \a Type must be such that an object
/// of type \a InIter can be dereferenced and then
/// of type \a FwdIter can be dereferenced and then
/// implicitly converted to Type.
///
/// The application of function objects in parallel algorithm
Expand All @@ -305,21 +313,29 @@ namespace hpx { namespace parallel { inline namespace v1
/// \a f returns true for at least one element in the range,
/// false otherwise. It returns false if the range is empty.
///
template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
inline typename std::enable_if<
execution::is_execution_policy<ExPolicy>::value,
typename util::detail::algorithm_result<ExPolicy, bool>::type
>::type
any_of(ExPolicy && policy, InIter first, InIter last, F && f)
any_of(ExPolicy && policy, FwdIter first, FwdIter last, F && f)
{
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
static_assert(
(hpx::traits::is_input_iterator<InIter>::value),
(hpx::traits::is_input_iterator<FwdIter>::value),
"Requires at least input iterator.");

typedef std::integral_constant<bool,
execution::is_sequenced_execution_policy<ExPolicy>::value ||
!hpx::traits::is_forward_iterator<InIter>::value
!hpx::traits::is_forward_iterator<FwdIter>::value
> is_seq;
#else
static_assert(
(hpx::traits::is_forward_iterator<FwdIter>::value),
"Requires at least forward iterator.");

typedef execution::is_sequenced_execution_policy<ExPolicy> is_seq;
#endif

return detail::any_of().call(
std::forward<ExPolicy>(policy), is_seq(),
Expand All @@ -337,9 +353,9 @@ namespace hpx { namespace parallel { inline namespace v1
: all_of::algorithm("all_of")
{}

template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
static bool
sequential(ExPolicy, InIter first, InIter last, F && f)
sequential(ExPolicy, FwdIter first, FwdIter last, F && f)
{
return std::all_of(first, last, std::forward<F>(f));
}
Expand Down Expand Up @@ -404,9 +420,9 @@ namespace hpx { namespace parallel { inline namespace v1
/// It describes the manner in which the execution
/// of the algorithm may be parallelized and the manner
/// in which it applies user-provided function objects.
/// \tparam InIter The type of the source iterators used (deduced).
/// \tparam FwdIter The type of the source iterators used (deduced).
/// This iterator type must meet the requirements of an
/// input iterator.
/// forward iterator.
/// \tparam F The type of the function/function object to use
/// (deduced). Unlike its sequential form, the parallel
/// overload of \a all_of requires \a F to meet the
Expand All @@ -429,7 +445,7 @@ namespace hpx { namespace parallel { inline namespace v1
/// The signature does not need to have const&, but
/// the function must not modify the objects passed
/// to it. The type \a Type must be such that an object
/// of type \a InIter can be dereferenced and then
/// of type \a FwdIter can be dereferenced and then
/// implicitly converted to Type.
///
/// The application of function objects in parallel algorithm
Expand All @@ -452,21 +468,29 @@ namespace hpx { namespace parallel { inline namespace v1
/// \a f returns true for all elements in the range, false
/// otherwise. It returns true if the range is empty.
///
template <typename ExPolicy, typename InIter, typename F>
template <typename ExPolicy, typename FwdIter, typename F>
inline typename std::enable_if<
execution::is_execution_policy<ExPolicy>::value,
typename util::detail::algorithm_result<ExPolicy, bool>::type
>::type
all_of(ExPolicy && policy, InIter first, InIter last, F && f)
all_of(ExPolicy && policy, FwdIter first, FwdIter last, F && f)
{
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
static_assert(
(hpx::traits::is_input_iterator<InIter>::value),
(hpx::traits::is_input_iterator<FwdIter>::value),
"Requires at least input iterator.");

typedef std::integral_constant<bool,
execution::is_sequenced_execution_policy<ExPolicy>::value ||
!hpx::traits::is_forward_iterator<InIter>::value
!hpx::traits::is_forward_iterator<FwdIter>::value
> is_seq;
#else
static_assert(
(hpx::traits::is_forward_iterator<FwdIter>::value),
"Requires at least forward iterator.");

typedef execution::is_sequenced_execution_policy<ExPolicy> is_seq;
#endif

return detail::all_of().call(
std::forward<ExPolicy>(policy), is_seq(),
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/parallel/algorithms/all_of.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2014 Hartmut Kaiser
// Copyright (c) 2014-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -131,11 +131,9 @@ void all_of_test()
{
test_all_of<std::random_access_iterator_tag>();
test_all_of<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_all_of<std::input_iterator_tag>();

// test_all_of_exec<std::random_access_iterator_tag>();
// test_all_of_exec<std::forward_iterator_tag>();
// test_all_of_exec<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -243,7 +241,9 @@ void all_of_exception_test()
{
test_all_of_exception<std::random_access_iterator_tag>();
test_all_of_exception<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_all_of_exception<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -349,7 +349,9 @@ void all_of_bad_alloc_test()
{
test_all_of_bad_alloc<std::random_access_iterator_tag>();
test_all_of_bad_alloc<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_all_of_bad_alloc<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/parallel/algorithms/any_of.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2014 Hartmut Kaiser
// Copyright (c) 2014-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -131,11 +131,9 @@ void any_of_test()
{
test_any_of<std::random_access_iterator_tag>();
test_any_of<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_any_of<std::input_iterator_tag>();

// test_any_of_exec<std::random_access_iterator_tag>();
// test_any_of_exec<std::forward_iterator_tag>();
// test_any_of_exec<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -243,7 +241,9 @@ void any_of_exception_test()
{
test_any_of_exception<std::random_access_iterator_tag>();
test_any_of_exception<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_any_of_exception<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -349,7 +349,9 @@ void any_of_bad_alloc_test()
{
test_any_of_bad_alloc<std::random_access_iterator_tag>();
test_any_of_bad_alloc<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_any_of_bad_alloc<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/parallel/algorithms/none_of.cpp
@@ -1,4 +1,4 @@
// Copyright (c) 2014 Hartmut Kaiser
// Copyright (c) 2014-2017 Hartmut Kaiser
//
// 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)
Expand Down Expand Up @@ -133,11 +133,9 @@ void none_of_test()
{
test_none_of<std::random_access_iterator_tag>();
test_none_of<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_none_of<std::input_iterator_tag>();

// test_none_of_exec<std::random_access_iterator_tag>();
// test_none_of_exec<std::forward_iterator_tag>();
// test_none_of_exec<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -245,7 +243,9 @@ void none_of_exception_test()
{
test_none_of_exception<std::random_access_iterator_tag>();
test_none_of_exception<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_none_of_exception<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -351,7 +351,9 @@ void none_of_bad_alloc_test()
{
test_none_of_bad_alloc<std::random_access_iterator_tag>();
test_none_of_bad_alloc<std::forward_iterator_tag>();
#if defined(HPX_HAVE_ALGORITHM_INPUT_ITERATOR_SUPPORT)
test_none_of_bad_alloc<std::input_iterator_tag>();
#endif
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit dc23b2e

Please sign in to comment.