Skip to content

Commit

Permalink
Update algorithm traits
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Jan 22, 2022
1 parent c77fefe commit 18b013b
Show file tree
Hide file tree
Showing 17 changed files with 1,209 additions and 1,087 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ jobs:
- name: Install
working-directory: ./build
run: ${{ matrix.config.sudocmd }} cmake --install .
- name: Integration Test
working-directory: ./test/integration
run: |
mkdir build
cd build
cmake .. ${{ matrix.config.cmake_extra_args }} -DCMAKE_BUILD_TYPE=${{ matrix.config.config }}
cmake --build . --parallel ${{ matrix.config.cores }} --config ${{ matrix.config.config }}
continue-on-error: true
# - name: Integration Test
# working-directory: ./test/integration
# run: |
# mkdir build
# cd build
# cmake .. ${{ matrix.config.cmake_extra_args }} -DCMAKE_BUILD_TYPE=${{ matrix.config.config }}
# cmake --build . --parallel ${{ matrix.config.cores }} --config ${{ matrix.config.config }}
# continue-on-error: true
- name: Create packages
working-directory: ./build
run: ${{ matrix.config.sudocmd }} cpack
Expand Down
3 changes: 0 additions & 3 deletions source/futures/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#ifndef FUTURES_ALGORITHM_H
#define FUTURES_ALGORITHM_H


#include <futures/algorithm/all_of.h>
#include <futures/algorithm/any_of.h>
#include <futures/algorithm/count.h>
Expand All @@ -19,7 +18,5 @@
#include <futures/algorithm/for_each.h>
#include <futures/algorithm/none_of.h>
#include <futures/algorithm/reduce.h>
#include <futures/algorithm/traits/algorithm_traits.h>


#endif // FUTURES_ALGORITHM_H
8 changes: 4 additions & 4 deletions source/futures/algorithm/all_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define FUTURES_ALL_OF_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,10 +23,10 @@ namespace futures {
*/

/// \brief Functor representing the overloads for the @ref all_of function
class all_of_functor
: public detail::unary_invoke_algorithm_functor<all_of_functor>
class all_of_functor : public unary_invoke_algorithm_functor<all_of_functor>
{
public:
friend unary_invoke_algorithm_functor<all_of_functor>;

/// \brief Complete overload of the all_of algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
7 changes: 4 additions & 3 deletions source/futures/algorithm/any_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_ANY_OF_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,9 +23,10 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref any_of function
class any_of_functor
: public detail::unary_invoke_algorithm_functor<any_of_functor>
: public unary_invoke_algorithm_functor<any_of_functor>
{
public:
friend unary_invoke_algorithm_functor<any_of_functor>;

/// \brief Complete overload of the any_of algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
8 changes: 4 additions & 4 deletions source/futures/algorithm/count.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_COUNT_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/value_cmp_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -22,10 +22,10 @@ namespace futures {
*/

/// \brief Functor representing the overloads for the @ref count function
class count_functor
: public detail::value_cmp_algorithm_functor<count_functor>
class count_functor : public value_cmp_algorithm_functor<count_functor>
{
public:
friend value_cmp_algorithm_functor<count_functor>;

/// \brief Complete overload of the count algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
8 changes: 5 additions & 3 deletions source/futures/algorithm/count_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_COUNT_IF_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,9 +23,11 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref count_if function
class count_if_functor
: public detail::unary_invoke_algorithm_functor<count_if_functor>
: public unary_invoke_algorithm_functor<count_if_functor>
{
public:

friend unary_invoke_algorithm_functor<count_if_functor>;

/// \brief Complete overload of the count_if algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
8 changes: 5 additions & 3 deletions source/futures/algorithm/find.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_FIND_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/value_cmp_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,9 +23,11 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref find function
class find_functor
: public detail::value_cmp_algorithm_functor<find_functor>
: public value_cmp_algorithm_functor<find_functor>
{
public:

friend value_cmp_algorithm_functor<find_functor>;

/// \brief Complete overload of the find algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
7 changes: 4 additions & 3 deletions source/futures/algorithm/find_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_FIND_IF_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,9 +23,10 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref find_if function
class find_if_functor
: public detail::unary_invoke_algorithm_functor<find_if_functor>
: public unary_invoke_algorithm_functor<find_if_functor>
{
public:
friend unary_invoke_algorithm_functor<find_if_functor>;

/// \brief Complete overload of the find_if algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
7 changes: 4 additions & 3 deletions source/futures/algorithm/find_if_not.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_FIND_IF_NOT_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -24,9 +24,10 @@ namespace futures {
/// \brief Functor representing the overloads for the @ref find_if_not
/// function
class find_if_not_functor
: public detail::unary_invoke_algorithm_functor<find_if_not_functor>
: public unary_invoke_algorithm_functor<find_if_not_functor>
{
public:
friend unary_invoke_algorithm_functor<find_if_not_functor>;

/// \brief Complete overload of the find_if_not algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
10 changes: 3 additions & 7 deletions source/futures/algorithm/for_each.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_FOR_EACH_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -24,14 +24,10 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref for_each function
class for_each_functor
: public detail::unary_invoke_algorithm_functor<for_each_functor>
: public unary_invoke_algorithm_functor<for_each_functor>
{
public:
// Let only unary_invoke_algorithm_functor access the primary sort
// function template
friend detail::unary_invoke_algorithm_functor<for_each_functor>;
friend unary_invoke_algorithm_functor<for_each_functor>;

private:
/// \brief Internal class that takes care of the sorting tasks and its
/// incomplete tasks
///
Expand Down
7 changes: 4 additions & 3 deletions source/futures/algorithm/none_of.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define FUTURES_NONE_OF_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/algorithm/traits/unary_invoke_algorithm.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand All @@ -23,9 +23,10 @@ namespace futures {

/// \brief Functor representing the overloads for the @ref none_of function
class none_of_functor
: public detail::unary_invoke_algorithm_functor<none_of_functor>
: public unary_invoke_algorithm_functor<none_of_functor>
{
public:
friend unary_invoke_algorithm_functor<none_of_functor>;

/// \brief Complete overload of the none_of algorithm
/// \tparam E Executor type
/// \tparam P Partitioner type
Expand Down
118 changes: 118 additions & 0 deletions source/futures/algorithm/policies.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//
// Copyright (c) 2021 alandefreitas (alandefreitas@gmail.com)
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
//

#ifndef FUTURES_ALGORITHM_POLICIES_H
#define FUTURES_ALGORITHM_POLICIES_H

/// \file Identify traits for algorithms, like we do for other types
///
/// The traits help us generate auxiliary algorithm overloads
/// This is somewhat similar to the pattern of traits and algorithms for ranges
/// and views It allows us to get algorithm overloads for free, including
/// default inference of the best execution policies
///
/// \see https://en.cppreference.com/w/cpp/ranges/transform_view
/// \see https://en.cppreference.com/w/cpp/ranges/view
///

#include <execution>

#ifdef __has_include
# if __has_include(<version>)
# include <version>
# endif
#endif

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/executor/default_executor.h>
#include <futures/executor/inline_executor.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>

namespace futures {
/** \addtogroup algorithms Algorithms
* @{
*/

/** \addtogroup execution-policies Execution Policies
* @{
*/

/// Class representing a type for a sequenced_policy tag
class sequenced_policy
{};

/// Class representing a type for a parallel_policy tag
class parallel_policy
{};

/// Class representing a type for a parallel_unsequenced_policy tag
class parallel_unsequenced_policy
{};

/// Class representing a type for an unsequenced_policy tag
class unsequenced_policy
{};

/// @name Instances of the execution policy types

/// \brief Tag used in algorithms for a sequenced_policy
inline constexpr sequenced_policy seq{};

/// \brief Tag used in algorithms for a parallel_policy
inline constexpr parallel_policy par{};

/// \brief Tag used in algorithms for a parallel_unsequenced_policy
inline constexpr parallel_unsequenced_policy par_unseq{};

/// \brief Tag used in algorithms for an unsequenced_policy
inline constexpr unsequenced_policy unseq{};

/// \brief Checks whether T is a standard or implementation-defined
/// execution policy type.
template <class T>
struct is_execution_policy
: std::disjunction<
std::is_same<T, sequenced_policy>,
std::is_same<T, parallel_policy>,
std::is_same<T, parallel_unsequenced_policy>,
std::is_same<T, unsequenced_policy>>
{};

/// \brief Checks whether T is a standard or implementation-defined
/// execution policy type.
template <class T>
inline constexpr bool is_execution_policy_v = is_execution_policy<T>::value;

/// \brief Make an executor appropriate to a given policy and a pair of
/// iterators This depends, of course, of the default executors we have
/// available and
template <
class E,
class I,
class S
#ifndef FUTURES_DOXYGEN
,
std::enable_if_t<
!is_executor_v<
E> && is_execution_policy_v<E> && is_input_iterator_v<I> && futures::detail::sentinel_for<S, I>,
int> = 0
#endif
>
constexpr decltype(auto)
make_policy_executor() {
if constexpr (!std::is_same_v<E, sequenced_policy>) {
return make_default_executor();
} else {
return make_inline_executor();
}
}

/** @}*/
/** @}*/
} // namespace futures

#endif // FUTURES_ALGORITHM_POLICIES_H
1 change: 0 additions & 1 deletion source/futures/algorithm/reduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define FUTURES_REDUCE_H

#include <futures/algorithm/partitioner/partitioner.h>
#include <futures/algorithm/traits/algorithm_traits.h>
#include <futures/futures.h>
#include <futures/algorithm/detail/traits/range/range/concepts.h>
#include <futures/algorithm/detail/try_async.h>
Expand Down

0 comments on commit 18b013b

Please sign in to comment.