Skip to content

Commit

Permalink
Shorter template argument names
Browse files Browse the repository at this point in the history
  • Loading branch information
alugowski committed Nov 14, 2023
1 parent 6893ca9 commit 97043cd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
18 changes: 9 additions & 9 deletions benchmark/algorithm_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

////////////////////////////////

template <class ExecutionPolicy>
template <class ExecPolicy>
void all_of(benchmark::State& state) {
auto values = iota_vector(arr_length);

for ([[maybe_unused]] auto _ : state) {
bool res;
if constexpr (is_policy<ExecutionPolicy>::value) {
res = std::all_of(policy<ExecutionPolicy>::get(), values.begin(), values.end(), [&](auto v) { return v >= 0; });
if constexpr (is_policy<ExecPolicy>::value) {
res = std::all_of(policy<ExecPolicy>::get(), values.begin(), values.end(), [&](auto v) { return v >= 0; });
} else {
res = std::all_of(values.begin(), values.end(), [&](auto v) { return v >= 0; });
}
Expand All @@ -38,14 +38,14 @@ BENCHMARK(all_of<std_par>)->UseRealTime();

////////////////////////////////

template <class ExecutionPolicy>
template <class ExecPolicy>
void for_each(benchmark::State& state) {
auto values = iota_vector<int>(arr_length);
std::vector<int> dest(arr_length);

for ([[maybe_unused]] auto _ : state) {
if constexpr (is_policy<ExecutionPolicy>::value) {
std::for_each(policy<ExecutionPolicy>::get(), values.begin(), values.end(), [&](auto v) { slow(); dest[v] = v; });
if constexpr (is_policy<ExecPolicy>::value) {
std::for_each(policy<ExecPolicy>::get(), values.begin(), values.end(), [&](auto v) { slow(); dest[v] = v; });
} else {
std::for_each(values.begin(), values.end(), [&](auto v) {slow(); dest[v] = v;});
}
Expand All @@ -62,14 +62,14 @@ BENCHMARK(for_each<std_par>)->UseRealTime();

////////////////////////////////

template <class ExecutionPolicy>
template <class ExecPolicy>
void transform(benchmark::State& state) {
auto values = iota_vector<int>(arr_length);
std::vector<int> dest(arr_length);

for ([[maybe_unused]] auto _ : state) {
if constexpr (is_policy<ExecutionPolicy>::value) {
std::transform(policy<ExecutionPolicy>::get(), values.begin(), values.end(), dest.begin(), [&](auto v) { slow(); return v; });
if constexpr (is_policy<ExecPolicy>::value) {
std::transform(policy<ExecPolicy>::get(), values.begin(), values.end(), dest.begin(), [&](auto v) { slow(); return v; });
} else {
std::transform(values.begin(), values.end(), dest.begin(), [&](auto v) { slow(); return v; });
}
Expand Down
6 changes: 3 additions & 3 deletions benchmark/numeric_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

////////////////////////////////

template <class ExecutionPolicy>
template <class ExecPolicy>
void reduce(benchmark::State& state) {
auto values = iota_vector(arr_length);

for ([[maybe_unused]] auto _ : state) {
int64_t sum = 0;
if constexpr (is_policy<ExecutionPolicy>::value) {
sum = std::reduce(policy<ExecutionPolicy>::get(), values.begin(), values.end());
if constexpr (is_policy<ExecPolicy>::value) {
sum = std::reduce(policy<ExecPolicy>::get(), values.begin(), values.end());
} else {
sum = std::reduce(values.begin(), values.end());
}
Expand Down
18 changes: 9 additions & 9 deletions include/poolstl/algorithm
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ namespace std {
* NOTE: Iterators are expected to be random access.
* See std::for_each https://en.cppreference.com/w/cpp/algorithm/for_each
*/
template <class ExecutionPolicy, class InputIt, class UnaryFunction>
poolstl::internal::enable_if_poolstl_execution_policy<ExecutionPolicy, void>
for_each(ExecutionPolicy &&policy, InputIt first, InputIt last, UnaryFunction f) {
poolstl::internal::parallel_for(std::forward<ExecutionPolicy>(policy), first, last, f);
template <class ExecPolicy, class RandIt, class UnaryFunction>
poolstl::internal::enable_if_poolstl_execution_policy<ExecPolicy, void>
for_each(ExecPolicy &&policy, RandIt first, RandIt last, UnaryFunction f) {
poolstl::internal::parallel_for(std::forward<ExecPolicy>(policy), first, last, f);
}

/**
* NOTE: Iterators are expected to be random access.
* See std::for_each_n https://en.cppreference.com/w/cpp/algorithm/for_each_n
*/
template <class ExecutionPolicy, class InputIt, class Size, class UnaryFunction>
poolstl::internal::enable_if_poolstl_execution_policy<ExecutionPolicy, InputIt>
for_each_n(ExecutionPolicy &&policy, InputIt first, Size n, UnaryFunction f) {
InputIt last = first;
template <class ExecPolicy, class RandIt, class Size, class UnaryFunction>
poolstl::internal::enable_if_poolstl_execution_policy<ExecPolicy, RandIt>
for_each_n(ExecPolicy &&policy, RandIt first, Size n, UnaryFunction f) {
RandIt last = first;
std::advance(last, n);
poolstl::internal::parallel_for(std::forward<ExecutionPolicy>(policy), first, last, f);
poolstl::internal::parallel_for(std::forward<ExecPolicy>(policy), first, last, f);
return last;
}

Expand Down
8 changes: 4 additions & 4 deletions include/poolstl/execution
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ namespace poolstl {
return pool;
}

template <typename ExecutionPolicy>
ttp::task_thread_pool& pool(ExecutionPolicy&) {
template <typename ExecPolicy>
ttp::task_thread_pool& pool(ExecPolicy&) {
return *get_default_pool();
}

Expand All @@ -54,11 +54,11 @@ namespace poolstl {
template <> struct is_poolstl_execution_policy<::poolstl::execution::parallel_policy> : std::true_type {};
template <> struct is_poolstl_execution_policy<::poolstl::execution::par_pool> : std::true_type {};

template <class ExecutionPolicy, class Tp>
template <class ExecPolicy, class Tp>
using enable_if_poolstl_execution_policy =
typename std::enable_if<
is_poolstl_execution_policy<
typename std::remove_cv<typename std::remove_reference<ExecutionPolicy>::type>::type>::value,
typename std::remove_cv<typename std::remove_reference<ExecPolicy>::type>::type>::value,
Tp>::type;
}
}
Expand Down
8 changes: 4 additions & 4 deletions include/poolstl/internal/ttp_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
namespace poolstl {
namespace internal {

template <class ExecutionPolicy, class InputIt, class UnaryFunction>
void parallel_for(ExecutionPolicy &&policy, InputIt first, InputIt last, UnaryFunction f) {
template <class ExecPolicy, class RandIt, class UnaryFunction>
void parallel_for(ExecPolicy &&policy, RandIt first, RandIt last, UnaryFunction f) {
::std::vector<::std::future<void>> futures;
auto chunk_size = get_chunk_size(first, last, pool(policy).get_num_threads());

while (first < last) {
InputIt loop_end = chunk_advance(first, last, chunk_size);
RandIt loop_end = chunk_advance(first, last, chunk_size);

futures.emplace_back(pool(policy).submit([&f](InputIt chunk_first, InputIt chunk_last) {
futures.emplace_back(pool(policy).submit([&f](RandIt chunk_first, RandIt chunk_last) {
for (; chunk_first != chunk_last; ++chunk_first) {
f(*chunk_first);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ include(Catch)
add_executable(poolstl_test poolstl_test.cpp)
target_link_libraries(poolstl_test PRIVATE Catch2::Catch2WithMain poolSTL::poolSTL)
target_compile_definitions(poolstl_test PRIVATE CATCH_CONFIG_FAST_COMPILE)
# Catch2 requires C++14
target_compile_features(poolstl_test PUBLIC cxx_std_14)
# Catch2 requires C++14, some implemented methods were only added in C++17
target_compile_features(poolstl_test PUBLIC cxx_std_17)

catch_discover_tests(poolstl_test)

Expand Down

0 comments on commit 97043cd

Please sign in to comment.