//
//===----------------------------------------------------------------------===//
-#ifndef __PSTL_algorithm_impl_H
-#define __PSTL_algorithm_impl_H
+#ifndef _PSTL_ALGORITHM_IMPL_H
+#define _PSTL_ALGORITHM_IMPL_H
#include <iterator>
#include <type_traits>
#include "execution_impl.h"
#include "memory_impl.h"
#include "parallel_backend_utils.h"
-#include "unseq_backend_simd.h"
-
-#if __PSTL_USE_PAR_POLICIES
#include "parallel_backend.h"
#include "parallel_impl.h"
-#endif
+#include "unseq_backend_simd.h"
+
namespace __pstl
{
return __internal::__brick_any_of(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Pred, class _IsVector>
bool
__pattern_any_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Pred __pred,
_IsVector __is_vector, /*parallel=*/std::true_type)
{
return __internal::__except_handler([&]() {
- return __internal::__parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, __last,
- [__pred, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
- return __internal::__brick_any_of(__i, __j, __pred, __is_vector);
- });
+ return __internal::__parallel_or(std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ [__pred, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
+ return __internal::__brick_any_of(__i, __j, __pred, __is_vector);
+ });
});
}
-#endif
// [alg.foreach]
// for_each_n with no policy
__internal::__brick_walk1(__first, __last, __f, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Function, class _IsVector>
void
__pattern_walk1(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Function __f,
});
});
}
-#endif
template <class _ExecutionPolicy, class _ForwardIterator, class _Brick>
void
__brick(__first, __last);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Brick>
void
__pattern_walk_brick(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Brick __brick,
[__brick](_ForwardIterator __i, _ForwardIterator __j) { __brick(__i, __j); });
});
}
-#endif
//------------------------------------------------------------------------
// walk1_n
__brick_walk1_n(_ForwardIterator __first, _Size __n, _Function __f, /*_IsVectorTag=*/std::false_type)
{
return __internal::__for_each_n_it_serial(__first, __n,
- [&__f](_ForwardIterator __it) { __f(*__it); }); // calling serial version
+ [&__f](_ForwardIterator __it) { __f(*__it); }); // calling serial version
}
template <class _RandomAccessIterator, class _DifferenceType, class _Function>
return __internal::__brick_walk1_n(__first, __n, __f, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Function, class _IsVector>
_RandomAccessIterator
__pattern_walk1_n(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _Size __n, _Function __f,
_IsVector __is_vector,
/*is_parallel=*/std::true_type)
{
- __internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f, __is_vector, std::true_type());
+ __internal::__pattern_walk1(std::forward<_ExecutionPolicy>(__exec), __first, __first + __n, __f, __is_vector,
+ std::true_type());
return __first + __n;
}
-#endif
template <class _ExecutionPolicy, class _ForwardIterator, class _Size, class _Brick>
_ForwardIterator
return __brick(__first, __n);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Brick>
_RandomAccessIterator
__pattern_walk_brick_n(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _Size __n, _Brick __brick,
return __first + __n;
});
}
-#endif
//------------------------------------------------------------------------
// walk2 (pseudo)
return __internal::__brick_walk2(__first1, __last1, __first2, __f, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Function, class _IsVector>
_ForwardIterator2
__pattern_walk2(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
return __first2 + (__last1 - __first1);
});
}
-#endif
template <class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2, class _Function,
class _IsVector>
_ForwardIterator2
__pattern_walk2_n(_ExecutionPolicy&&, _ForwardIterator1 __first1, _Size __n, _ForwardIterator2 __first2, _Function __f,
- _IsVector is_vector, /*parallel=*/std::false_type) noexcept
+ _IsVector __is_vector, /*parallel=*/std::false_type) noexcept
{
- return __internal::__brick_walk2_n(__first1, __n, __first2, __f, is_vector);
+ return __internal::__brick_walk2_n(__first1, __n, __first2, __f, __is_vector);
}
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _Size, class _RandomAccessIterator2,
return __brick(__first1, __last1, __first2);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Brick>
_RandomAccessIterator2
__pattern_walk2_brick(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
return __first2 + (__last1 - __first1);
});
}
-#endif
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _Size, class _RandomAccessIterator2, class _Brick>
_RandomAccessIterator2
__pattern_walk2_brick_n(_ExecutionPolicy&& __exec, _RandomAccessIterator1 __first1, _Size __n,
return __first2 + __n;
});
}
-#endif
template <class _ExecutionPolicy, class _ForwardIterator1, class _Size, class _ForwardIterator2, class _Brick>
_ForwardIterator2
return __internal::__brick_walk3(__first1, __last1, __first2, __first3, __f, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2,
class _RandomAccessIterator3, class _Function, class _IsVector>
_RandomAccessIterator3
__par_backend::__parallel_for(
std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
[__f, __first1, __first2, __first3, __is_vector](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
- __internal::__brick_walk3(__i, __j, __first2 + (__i - __first1), __first3 + (__i - __first1), __f, __is_vector);
+ __internal::__brick_walk3(__i, __j, __first2 + (__i - __first1), __first3 + (__i - __first1), __f,
+ __is_vector);
});
return __first3 + (__last1 - __first1);
});
}
-#endif
//------------------------------------------------------------------------
// equal
return __internal::__brick_equal(__first1, __last1, __first2, __last2, __p, __is_vector);
}
-#if _PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate,
class _IsVector>
bool
});
});
}
-#endif
//------------------------------------------------------------------------
// equal version for sequences with equal length
return __internal::__brick_equal(__first1, __last1, __first2, __p, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _BinaryPredicate,
class _IsVector>
bool
});
});
}
-#endif
//------------------------------------------------------------------------
// find_if
return __internal::__brick_find_if(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate, class _IsVector>
_ForwardIterator
__pattern_find_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
/*is_parallel=*/std::true_type)
{
return __internal::__except_handler([&]() {
- return __internal::__parallel_find(std::forward<_ExecutionPolicy>(__exec), __first, __last,
- [__pred, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
- return __internal::__brick_find_if(__i, __j, __pred, __is_vector);
- },
- std::less<typename std::iterator_traits<_ForwardIterator>::difference_type>(),
- /*is_first=*/true);
+ return __internal::__parallel_find(
+ std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ [__pred, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
+ return __internal::__brick_find_if(__i, __j, __pred, __is_vector);
+ },
+ std::less<typename std::iterator_traits<_ForwardIterator>::difference_type>(),
+ /*is_first=*/true);
});
}
-#endif
//------------------------------------------------------------------------
// find_end
while (__first != __last && (__global_last - __first >= __n2))
{
// find position of *s_first in [first, last) (it can be start of subsequence)
- __first = __internal::__brick_find_if(__first, __last,
- __equal_value_by_pred<_ValueType, _BinaryPredicate>(*__s_first, __pred), __is_vector);
+ __first = __internal::__brick_find_if(
+ __first, __last, __equal_value_by_pred<_ValueType, _BinaryPredicate>(*__s_first, __pred), __is_vector);
// if position that was found previously is the start of subsequence
// then we can exit the loop (b_first == true) or keep the position
// check that all of elements in [first+1, first+count) equal to value
if (__first != __last && (__global_last - __first >= __count) &&
- !__internal::__brick_any_of(__first + 1, __first + __count, __not_pred<decltype(__unary_pred)>(__unary_pred),
- __is_vector))
+ !__internal::__brick_any_of(__first + 1, __first + __count,
+ __not_pred<decltype(__unary_pred)>(__unary_pred), __is_vector))
{
return __first;
}
return __internal::__brick_find_end(__first, __last, __s_first, __s_last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate,
class _IsVector>
_ForwardIterator1
{
if (__last - __first == __s_last - __s_first)
{
- const bool __res = __internal::__pattern_equal(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __pred,
- __is_vector, std::true_type());
+ const bool __res = __internal::__pattern_equal(std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ __s_first, __pred, __is_vector, std::true_type());
return __res ? __first : __last;
}
else
{
return __internal::__except_handler([&]() {
- return __internal::__parallel_find(
+ return __internal::__parallel_find(
std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__last, __s_first, __s_last, __pred, __is_vector](_ForwardIterator1 __i, _ForwardIterator1 __j) {
- return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, false, __is_vector);
+ return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, false,
+ __is_vector);
},
std::greater<typename std::iterator_traits<_ForwardIterator1>::difference_type>(), /*is_first=*/false);
});
}
}
-#endif
//------------------------------------------------------------------------
// find_first_of
return __internal::__brick_find_first_of(__first, __last, __s_first, __s_last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate,
class _IsVector>
_ForwardIterator1
_IsVector __is_vector, /*is_parallel=*/std::true_type) noexcept
{
return __internal::__except_handler([&]() {
- return __internal::__parallel_find(
+ return __internal::__parallel_find(
std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__s_first, __s_last, __pred, __is_vector](_ForwardIterator1 __i, _ForwardIterator1 __j) {
return __internal::__brick_find_first_of(__i, __j, __s_first, __s_last, __pred, __is_vector);
std::less<typename std::iterator_traits<_ForwardIterator1>::difference_type>(), /*is_first=*/true);
});
}
-#endif
//------------------------------------------------------------------------
// search
return __internal::__brick_search(__first, __last, __s_first, __s_last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate,
class _IsVector>
_ForwardIterator1
{
if (__last - __first == __s_last - __s_first)
{
- const bool __res = __internal::__pattern_equal(std::forward<_ExecutionPolicy>(__exec), __first, __last, __s_first, __pred,
- __is_vector, std::true_type());
+ const bool __res = __internal::__pattern_equal(std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ __s_first, __pred, __is_vector, std::true_type());
return __res ? __first : __last;
}
else
return __internal::__parallel_find(
std::forward<_ExecutionPolicy>(__exec), __first, __last,
[__last, __s_first, __s_last, __pred, __is_vector](_ForwardIterator1 __i, _ForwardIterator1 __j) {
- return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, true, __is_vector);
+ return __internal::__find_subrange(__i, __j, __last, __s_first, __s_last, __pred, true,
+ __is_vector);
},
std::less<typename std::iterator_traits<_ForwardIterator1>::difference_type>(), /*is_first=*/true);
});
}
}
-#endif
//------------------------------------------------------------------------
// search_n
return __internal::__brick_search_n(__first, __last, __count, __value, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Size, class _Tp, class _BinaryPredicate,
class _IsVector>
_RandomAccessIterator
{
if (__last - __first == __count)
{
- const bool __result =
- !__internal::__pattern_any_of(std::forward<_ExecutionPolicy>(__exec), __first, __last,
- [&__value, &__pred](const _Tp& __val) { return !__pred(__val, __value); }, __is_vector,
- /*is_parallel*/ std::true_type());
+ const bool __result = !__internal::__pattern_any_of(
+ std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ [&__value, &__pred](const _Tp& __val) { return !__pred(__val, __value); }, __is_vector,
+ /*is_parallel*/ std::true_type());
return __result ? __first : __last;
}
else
});
}
}
-#endif
//------------------------------------------------------------------------
// copy_n
__brick_copy_if(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _UnaryPredicate __pred,
/*vector=*/std::true_type) noexcept
{
-#if (__PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT)
return __unseq_backend::__simd_copy_if(__first, __last - __first, __result, __pred);
#else
return std::copy_if(__first, __last, __result, __pred);
__brick_copy_by_mask(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result,
bool* __restrict __mask, _Assigner __assigner, /*vector=*/std::true_type) noexcept
{
-#if (__PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT)
__unseq_backend::__simd_copy_by_mask(__first, __last - __first, __result, __mask, __assigner);
#else
__internal::__brick_copy_by_mask(__first, __last, __result, __mask, __assigner, std::false_type());
__brick_partition_by_mask(_RandomAccessIterator __first, _RandomAccessIterator __last, _OutputIterator1 __out_true,
_OutputIterator2 __out_false, bool* __mask, /*vector=*/std::true_type) noexcept
{
-#if (__PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT)
__unseq_backend::__simd_partition_by_mask(__first, __last - __first, __out_true, __out_false, __mask);
#else
__internal::__brick_partition_by_mask(__first, __last, __out_true, __out_false, __mask, std::false_type());
return __internal::__brick_copy_if(__first, __last, __result, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _UnaryPredicate,
class _IsVector>
_OutputIterator
__par_backend::__parallel_strict_scan(
std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
[=](_DifferenceType __i, _DifferenceType __len) { // Reduce
- return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len), __mask + __i,
- __pred, __is_vector)
+ return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len),
+ __mask + __i, __pred, __is_vector)
.first;
},
std::plus<_DifferenceType>(), // Combine
[=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) { // Scan
- __internal::__brick_copy_by_mask(__first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
- [](_RandomAccessIterator __x, _OutputIterator __z) { *__z = *__x; },
- __is_vector);
+ __internal::__brick_copy_by_mask(
+ __first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
+ [](_RandomAccessIterator __x, _OutputIterator __z) { *__z = *__x; }, __is_vector);
},
[&__m](_DifferenceType __total) { __m = __total; });
return __result + __m;
// trivial sequence - use serial algorithm
return __internal::__brick_copy_if(__first, __last, __result, __pred, __is_vector);
}
-#endif
//------------------------------------------------------------------------
// count
return __internal::__brick_count(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Predicate, class _IsVector>
typename std::iterator_traits<_ForwardIterator>::difference_type
__pattern_count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
std::plus<_SizeType>());
});
}
-#endif
//------------------------------------------------------------------------
// unique
__brick_unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred,
/*is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::unique(__first, __last, __pred);
}
return __internal::__brick_unique(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
// That function is shared between two algorithms - remove_if (__pattern_remove_if) and unique (pattern unique). But a mask calculation is different.
// So, a caller passes _CalcMask brick into remove_elements.
template <class _ExecutionPolicy, class _ForwardIterator, class _CalcMask, class _IsVector>
_ForwardIterator
__remove_elements(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _CalcMask __calc_mask,
- _IsVector __is_vector)
+ _IsVector __is_vector)
{
typedef typename std::iterator_traits<_ForwardIterator>::difference_type _DifferenceType;
typedef typename std::iterator_traits<_ForwardIterator>::value_type _Tp;
return __local_min;
}
// find first iterator that should be removed
- bool* __result =
- __internal::__brick_find_if(__mask + __i, __mask + __j, [](bool __val) { return !__val; }, __is_vector);
+ bool* __result = __internal::__brick_find_if(__mask + __i, __mask + __j,
+ [](bool __val) { return !__val; }, __is_vector);
if (__result - __mask == __j)
{
return __local_min;
__par_backend::__parallel_strict_scan(
std::forward<_ExecutionPolicy>(__exec), __n, _DifferenceType(0),
[__mask, __is_vector](_DifferenceType __i, _DifferenceType __len) {
- return __internal::__brick_count(__mask + __i, __mask + __i + __len, [](bool __val) { return __val; }, __is_vector);
+ return __internal::__brick_count(__mask + __i, __mask + __i + __len, [](bool __val) { return __val; },
+ __is_vector);
},
std::plus<_DifferenceType>(),
[=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) {
- __internal::__brick_copy_by_mask(__first + __i, __first + __i + __len, __result + __initial, __mask + __i,
- [](_ForwardIterator __x, _Tp* __z) {
- __internal::__invoke_if_else(std::is_trivial<_Tp>(), [&]() { *__z = std::move(*__x); },
- [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
- },
- __is_vector);
+ __internal::__brick_copy_by_mask(
+ __first + __i, __first + __i + __len, __result + __initial, __mask + __i,
+ [](_ForwardIterator __x, _Tp* __z) {
+ __internal::__invoke_if_else(std::is_trivial<_Tp>(), [&]() { *__z = std::move(*__x); },
+ [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
+ },
+ __is_vector);
},
[&__m](_DifferenceType __total) { __m = __total; });
return __first + __m;
});
}
-#endif
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _BinaryPredicate, class _IsVector>
_ForwardIterator
__pattern_unique(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred,
return __internal::__remove_elements(
std::forward<_ExecutionPolicy>(__exec), ++__first, __last,
[&__pred, __is_vector](bool* __b, bool* __e, _ForwardIterator __it) {
- __internal::__brick_walk3(__b, __e, __it - 1, __it,
- [&__pred](bool& __x, _ReferenceType __y, _ReferenceType __z) { __x = !__pred(__y, __z); },
- __is_vector);
+ __internal::__brick_walk3(
+ __b, __e, __it - 1, __it,
+ [&__pred](bool& __x, _ReferenceType __y, _ReferenceType __z) { __x = !__pred(__y, __z); }, __is_vector);
},
__is_vector);
}
-#endif
//------------------------------------------------------------------------
// unique_copy
__brick_unique_copy(_RandomAccessIterator __first, _RandomAccessIterator __last, OutputIterator __result,
_BinaryPredicate __pred, /*vector=*/std::true_type) noexcept
{
-#if (__PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT)
return __unseq_backend::__simd_unique_copy(__first, __last - __first, __result, __pred);
#else
return std::unique_copy(__first, __last, __result, __pred);
return __unseq_backend::__simd_calc_mask_2(__first, __last - __first, __mask, __pred);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator, class _BinaryPredicate,
class _IsVector>
_OutputIterator
++__extra;
}
return __internal::__brick_calc_mask_2<_DifferenceType>(__first + __i, __first + (__i + __len),
- __mask + __i, __pred, __is_vector) +
+ __mask + __i, __pred, __is_vector) +
__extra;
},
std::plus<_DifferenceType>(), // Combine
[=](_DifferenceType __i, _DifferenceType __len, _DifferenceType __initial) { // Scan
// Phase 2 is same as for __pattern_copy_if
- __internal::__brick_copy_by_mask(__first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
- [](_RandomAccessIterator __x, _OutputIterator __z) { *__z = *__x; },
- __is_vector);
+ __internal::__brick_copy_by_mask(
+ __first + __i, __first + (__i + __len), __result + __initial, __mask + __i,
+ [](_RandomAccessIterator __x, _OutputIterator __z) { *__z = *__x; }, __is_vector);
},
[&__m](_DifferenceType __total) { __m = __total; });
return __result + __m;
// trivial sequence - use serial algorithm
return __internal::__brick_unique_copy(__first, __last, __result, __pred, __is_vector);
}
-#endif
//------------------------------------------------------------------------
// reverse
__internal::__brick_reverse(__first, __last, _is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _BidirectionalIterator, class _IsVector>
void
__pattern_reverse(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
__internal::__brick_reverse(__inner_first, __inner_last, __last - (__inner_first - __first), __is_vector);
});
}
-#endif
//------------------------------------------------------------------------
// reverse_copy
return __internal::__brick_reverse_copy(__first, __last, __d_first, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _BidirectionalIterator, class _OutputIterator, class _IsVector>
_OutputIterator
__pattern_reverse_copy(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
[__is_vector, __first, __len, __d_first](_BidirectionalIterator __inner_first,
_BidirectionalIterator __inner_last) {
__internal::__brick_reverse_copy(__inner_first, __inner_last,
- __d_first + (__len - (__inner_last - __first)), __is_vector);
+ __d_first + (__len - (__inner_last - __first)),
+ __is_vector);
});
return __d_first + __len;
}
-#endif
//------------------------------------------------------------------------
// rotate
__brick_rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
/*is_vector=*/std::false_type) noexcept
{
-#if __PSTL_CPP11_STD_ROTATE_BROKEN
+#if _PSTL_CPP11_STD_ROTATE_BROKEN
std::rotate(__first, __middle, __last);
return std::next(__first, std::distance(__middle, __last));
#else
return __internal::__brick_rotate(__first, __middle, __last, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _IsVector>
_ForwardIterator
__pattern_rotate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle,
__par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __first, __middle,
[__last, __middle, __is_vector](_ForwardIterator __b, _ForwardIterator __e) {
- __internal::__brick_move(__b, __e, __b + (__last - __middle), __is_vector);
+ __internal::__brick_move(__b, __e, __b + (__last - __middle),
+ __is_vector);
});
__par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __result, __result + (__n - __m),
[__first, __result, __is_vector](_Tp* __b, _Tp* __e) {
- __internal::__brick_move(__b, __e, __first + (__b - __result), __is_vector);
+ __internal::__brick_move(__b, __e, __first + (__b - __result),
+ __is_vector);
});
return __first + (__last - __middle);
_Tp* __result = __buf.get();
__par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __first, __middle,
[__first, __result, __is_vector](_ForwardIterator __b, _ForwardIterator __e) {
- __internal::__brick_uninitialized_move(__b, __e, __result + (__b - __first),
- __is_vector);
+ __internal::__brick_uninitialized_move(
+ __b, __e, __result + (__b - __first), __is_vector);
});
__par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __middle, __last,
[__first, __middle, __is_vector](_ForwardIterator __b, _ForwardIterator __e) {
- __internal::__brick_move(__b, __e, __first + (__b - __middle), __is_vector);
+ __internal::__brick_move(__b, __e, __first + (__b - __middle),
+ __is_vector);
});
__par_backend::__parallel_for(std::forward<_ExecutionPolicy>(__exec), __result, __result + __m,
[__n, __m, __first, __result, __is_vector](_Tp* __b, _Tp* __e) {
- __internal::__brick_move(__b, __e, __first + ((__n - __m) + (__b - __result)),
- __is_vector);
+ __internal::__brick_move(
+ __b, __e, __first + ((__n - __m) + (__b - __result)), __is_vector);
});
return __first + (__last - __middle);
});
}
}
-#endif
//------------------------------------------------------------------------
// rotate_copy
return __internal::__brick_rotate_copy(__first, __middle, __last, __result, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _OutputIterator, class _IsVector>
_OutputIterator
__pattern_rotate_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __middle,
});
return __result + (__last - __first);
}
-#endif
//------------------------------------------------------------------------
// is_partitioned
return __internal::__brick_is_partitioned(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _IsVector>
bool
__pattern_is_partitioned(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
});
}
}
-#endif
//------------------------------------------------------------------------
// partition
__brick_partition(_ForwardIterator __first, _ForwardIterator __last, _UnaryPredicate __pred,
/*is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::partition(__first, __last, __pred);
}
return __internal::__brick_partition(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _IsVector>
_ForwardIterator
__pattern_partition(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
__par_backend::__parallel_for(
std::forward<_ExecutionPolicy>(__exec), __val1.__pivot, __val1.__pivot + __size1,
[__val1, __val2, __size1, __is_vector](_ForwardIterator __i, _ForwardIterator __j) {
- __internal::__brick_swap_ranges(__i, __j, (__val2.__pivot - __size1) + (__i - __val1.__pivot), __is_vector);
+ __internal::__brick_swap_ranges(__i, __j, (__val2.__pivot - __size1) + (__i - __val1.__pivot),
+ __is_vector);
});
return {__new_begin, __val2.__pivot - __size1, __val2.__end};
}
return __result.__pivot;
});
}
-#endif
//------------------------------------------------------------------------
// stable_partition
__brick_stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _UnaryPredicate __pred,
/*__is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::stable_partition(__first, __last, __pred);
}
return __internal::__brick_stable_partition(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _BidirectionalIterator, class _UnaryPredicate, class _IsVector>
_BidirectionalIterator
__pattern_stable_partition(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __last,
return __result.__pivot;
});
}
-#endif
//------------------------------------------------------------------------
// partition_copy
__brick_partition_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator1 __out_true,
_OutputIterator2 __out_false, _UnaryPredicate __pred, /*is_vector=*/std::true_type) noexcept
{
-#if (__PSTL_MONOTONIC_PRESENT)
+#if (_PSTL_MONOTONIC_PRESENT)
return __unseq_backend::__simd_partition_copy(__first, __last - __first, __out_true, __out_false, __pred);
#else
return std::partition_copy(__first, __last, __out_true, __out_false, __pred);
return __internal::__brick_partition_copy(__first, __last, __out_true, __out_false, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _OutputIterator1, class _OutputIterator2,
class _UnaryPredicate, class _IsVector>
std::pair<_OutputIterator1, _OutputIterator2>
if (_DifferenceType(1) < __n)
{
__par_backend::__buffer<bool> __mask_buf(__n);
- return __internal::__except_handler([&__exec, __n, __first, __out_true, __out_false, __is_vector, __pred, &__mask_buf]() {
+ return __internal::__except_handler([&__exec, __n, __first, __out_true, __out_false, __is_vector, __pred,
+ &__mask_buf]() {
bool* __mask = __mask_buf.get();
_ReturnType __m{};
__par_backend::__parallel_strict_scan(
std::forward<_ExecutionPolicy>(__exec), __n, std::make_pair(_DifferenceType(0), _DifferenceType(0)),
[=](_DifferenceType __i, _DifferenceType __len) { // Reduce
- return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len), __mask + __i,
- __pred, __is_vector);
+ return __internal::__brick_calc_mask_1<_DifferenceType>(__first + __i, __first + (__i + __len),
+ __mask + __i, __pred, __is_vector);
},
[](const _ReturnType& __x, const _ReturnType& __y) -> _ReturnType {
return std::make_pair(__x.first + __y.first, __x.second + __y.second);
}, // Combine
[=](_DifferenceType __i, _DifferenceType __len, _ReturnType __initial) { // Scan
- __internal::__brick_partition_by_mask(__first + __i, __first + (__i + __len), __out_true + __initial.first,
- __out_false + __initial.second, __mask + __i, __is_vector);
+ __internal::__brick_partition_by_mask(__first + __i, __first + (__i + __len),
+ __out_true + __initial.first, __out_false + __initial.second,
+ __mask + __i, __is_vector);
},
[&__m](_ReturnType __total) { __m = __total; });
return std::make_pair(__out_true + __m.first, __out_false + __m.second);
// trivial sequence - use serial algorithm
return __internal::__brick_partition_copy(__first, __last, __out_true, __out_false, __pred, __is_vector);
}
-#endif
//------------------------------------------------------------------------
// sort
std::sort(__first, __last, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsVector>
void
__pattern_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
__last - __first);
});
}
-#endif
//------------------------------------------------------------------------
// stable_sort
std::stable_sort(__first, __last, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsVector>
void
__pattern_stable_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last,
_Compare __comp) { std::stable_sort(__first, __last, __comp); });
});
}
-#endif
//------------------------------------------------------------------------
// partial_sort
std::partial_sort(__first, __middle, __last, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsVector>
void
__pattern_partial_sort(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __middle,
__n);
});
}
-#endif
//------------------------------------------------------------------------
// partial_sort_copy
return std::partial_sort_copy(__first, __last, __d_first, __d_last, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _RandomAccessIterator, class _Compare, class _IsVector>
_RandomAccessIterator
__pattern_partial_sort_copy(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
_ForwardIterator __j1 = __first + (__j - __d_first);
// 1. Copy elements from input to output
-#if !__PSTL_ICC_18_OMP_SIMD_BROKEN
+# if !_PSTL_ICC_18_OMP_SIMD_BROKEN
__internal::__brick_copy(__i1, __j1, __i, __is_vector);
-#else
+# else
std::copy(__i1, __j1, __i);
-#endif
+# endif
// 2. Sort elements in output sequence
std::sort(__i, __j, __comp);
},
}
});
}
-#endif
//------------------------------------------------------------------------
// adjacent_find
return __internal::__brick_adjacent_find(__first, __last, __pred, __is_vector, __or_semantic);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _BinaryPredicate, class _IsVector>
_RandomAccessIterator
__pattern_adjacent_find(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last,
);
});
}
-#endif
//------------------------------------------------------------------------
// nth_element
std::nth_element(__first, __nth, __last, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsVector>
void
__pattern_nth_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __nth,
do
{
__x = __internal::__pattern_partition(std::forward<_ExecutionPolicy>(__exec), __first + 1, __last,
- [&__comp, __first](const _Tp& __x) { return __comp(__x, *__first); }, __is_vector,
- /*is_parallel=*/std::true_type());
+ [&__comp, __first](const _Tp& __x) { return __comp(__x, *__first); },
+ __is_vector,
+ /*is_parallel=*/std::true_type());
--__x;
if (__x != __first)
{
}
} while (__x != __nth);
}
-#endif
//------------------------------------------------------------------------
// fill, fill_n
__internal::__brick_fill(__first, __last, __value, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Tp, class _IsVector>
_ForwardIterator
__pattern_fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value,
return __last;
});
}
-#endif
template <class _OutputIterator, class _Size, class _Tp>
_OutputIterator
__pattern_fill_n(_ExecutionPolicy&& __exec, _OutputIterator __first, _Size __count, const _Tp& __value,
/*is_parallel=*/std::true_type, _IsVector __is_vector)
{
- return __internal::__pattern_fill(std::forward<_ExecutionPolicy>(__exec), __first, __first + __count, __value, std::true_type(),
- __is_vector);
+ return __internal::__pattern_fill(std::forward<_ExecutionPolicy>(__exec), __first, __first + __count, __value,
+ std::true_type(), __is_vector);
}
//------------------------------------------------------------------------
__internal::__brick_generate(__first, __last, __g, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _Generator, class _IsVector>
_ForwardIterator
__pattern_generate(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Generator __g,
return __last;
});
}
-#endif
template <class OutputIterator, class Size, class _Generator>
OutputIterator
return __internal::__brick_generate_n(__first, __count, __g, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _OutputIterator, class _Size, class _Generator, class _IsVector>
_OutputIterator
__pattern_generate_n(_ExecutionPolicy&& __exec, _OutputIterator __first, _Size __count, _Generator __g,
{
static_assert(__is_random_access_iterator<_OutputIterator>::value,
"Pattern-brick error. Should be a random access iterator.");
- return __internal::__pattern_generate(std::forward<_ExecutionPolicy>(__exec), __first, __first + __count, __g, std::true_type(),
- __is_vector);
+ return __internal::__pattern_generate(std::forward<_ExecutionPolicy>(__exec), __first, __first + __count, __g,
+ std::true_type(), __is_vector);
}
-#endif
//------------------------------------------------------------------------
// remove
__brick_remove_if(_RandomAccessIterator __first, _RandomAccessIterator __last, _UnaryPredicate __pred,
/* __is_vector = */ std::true_type) noexcept
{
-#if __PSTL_MONOTONIC_PRESENT
+#if _PSTL_MONOTONIC_PRESENT
return __unseq_backend::__simd_remove_if(__first, __last - __first, __pred);
#else
return std::remove_if(__first, __last, __pred);
return __internal::__brick_remove_if(__first, __last, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator, class _UnaryPredicate, class _IsVector>
_ForwardIterator
__pattern_remove_if(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last,
return __internal::__brick_remove_if(__first, __last, __pred, __is_vector);
}
- return __internal::__remove_elements(std::forward<_ExecutionPolicy>(__exec), __first, __last,
- [&__pred, __is_vector](bool* __b, bool* __e, _ForwardIterator __it) {
- __internal::__brick_walk2(__b, __e, __it,
- [&__pred](bool& __x, _ReferenceType __y) { __x = !__pred(__y); },
- __is_vector);
- },
- __is_vector);
+ return __internal::__remove_elements(
+ std::forward<_ExecutionPolicy>(__exec), __first, __last,
+ [&__pred, __is_vector](bool* __b, bool* __e, _ForwardIterator __it) {
+ __internal::__brick_walk2(__b, __e, __it, [&__pred](bool& __x, _ReferenceType __y) { __x = !__pred(__y); },
+ __is_vector);
+ },
+ __is_vector);
}
-#endif
//------------------------------------------------------------------------
// merge
_ForwardIterator2 __last2, _OutputIterator __d_first, _Compare __comp,
/* __is_vector = */ std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::merge(__first1, __last1, __first2, __last2, __d_first, __comp);
}
return __internal::__brick_merge(__first1, __last1, __first2, __last2, __d_first, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _OutputIterator,
class _Compare, class _IsVector>
_OutputIterator
__par_backend::__parallel_merge(
std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __d_first, __comp,
[__is_vector](_RandomAccessIterator1 __f1, _RandomAccessIterator1 __l1, _RandomAccessIterator2 __f2,
- _RandomAccessIterator2 __l2, _OutputIterator __f3,
- _Compare __comp) { return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, __is_vector); });
+ _RandomAccessIterator2 __l2, _OutputIterator __f3, _Compare __comp) {
+ return __internal::__brick_merge(__f1, __l1, __f2, __l2, __f3, __comp, __is_vector);
+ });
return __d_first + (__last1 - __first1) + (__last2 - __first2);
}
-#endif
//------------------------------------------------------------------------
// inplace_merge
__brick_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_Compare __comp, /* __is_vector = */ std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial")
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial")
std::inplace_merge(__first, __middle, __last, __comp);
}
__internal::__brick_inplace_merge(__first, __middle, __last, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _BidirectionalIterator, class _Compare, class _IsVector>
void
__pattern_inplace_merge(_ExecutionPolicy&& __exec, _BidirectionalIterator __first, _BidirectionalIterator __middle,
_Tp* __r = __buf.get();
__internal::__except_handler([&]() {
auto __move_values = [](_BidirectionalIterator __x, _Tp* __z) {
- __internal::__invoke_if_else(std::is_trivial<_Tp>(), [&]() { *__z = std::move(*__x); },
- [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
+ __internal::__invoke_if_else(std::is_trivial<_Tp>(), [&]() { *__z = std::move(*__x); },
+ [&]() { ::new (std::addressof(*__z)) _Tp(std::move(*__x)); });
};
auto __move_sequences = [](_BidirectionalIterator __first1, _BidirectionalIterator __last1, _Tp* __first2) {
});
});
}
-#endif
//------------------------------------------------------------------------
// includes
return std::includes(__first1, __last1, __first2, __last2, __comp);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare, class _IsVector>
bool
__pattern_includes(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
return !__comp(*__first1, *__first2) && !__comp(*__first2, *__first1);
return __internal::__except_handler([&]() {
- return !__internal::__parallel_or(
+ return !__internal::__parallel_or(
std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
[__first1, __last1, __first2, __last2, &__comp](_ForwardIterator2 __i, _ForwardIterator2 __j) {
- __PSTL_ASSERT(__j > __i);
- //__PSTL_ASSERT(__j - __i > 1);
+ _PSTL_ASSERT(__j > __i);
+ //assert(__j - __i > 1);
//1. moving boundaries to "consume" subsequence of equal elements
auto __is_equal = [&__comp](_ForwardIterator2 __a, _ForwardIterator2 __b) -> bool {
//2. testing is __a subsequence of the second range included into the first range
auto __b = std::lower_bound(__first1, __last1, *__i, __comp);
- __PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
- __PSTL_ASSERT(!__comp(*(__j - 1), *__i));
+ _PSTL_ASSERT(!__comp(*(__last1 - 1), *__b));
+ _PSTL_ASSERT(!__comp(*(__j - 1), *__i));
return !std::includes(__b, __last1, __i, __j, __comp);
});
});
}
-#endif
constexpr auto __set_algo_cut_off = 1000;
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _IsVector, class _SizeFunction, class _SetOP>
_OutputIterator
__par_backend::__buffer<_T> __buf(__size_func(__n1, __n2));
- return __internal::__except_handler([&__exec, __n1, __first1, __last1, __first2, __last2, __result, __is_vector, __comp,
- __size_func, __set_op, &__buf]() {
+ return __internal::__except_handler([&__exec, __n1, __first1, __last1, __first2, __last2, __result, __is_vector,
+ __comp, __size_func, __set_op, &__buf]() {
auto __buffer = __buf.get();
_DifferenceType __m{};
auto __scan = [=](_DifferenceType, _DifferenceType, const _SetRange& __s) { // Scan
if (!__s.empty())
- __internal::__brick_move(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len), __result + __s.__pos,
- __is_vector);
+ __internal::__brick_move(__buffer + __s.__buf_pos, __buffer + (__s.__buf_pos + __s.__len),
+ __result + __s.__pos, __is_vector);
};
__par_backend::__parallel_strict_scan(
std::forward<_ExecutionPolicy>(__exec), __n1, _SetRange{0, 0, 0}, //-1, 0},
return __result + __m;
});
}
-#endif
-#if __PSTL_USE_PAR_POLICIES
//a shared parallel pattern for '__pattern_set_union' and '__pattern_set_symmetric_difference'
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _SetUnionOp, class _IsVector>
_OutputIterator
__parallel_set_union_op(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
- _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
- _SetUnionOp __set_union_op, _IsVector __is_vector)
+ _ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
+ _Compare __comp, _SetUnionOp __set_union_op, _IsVector __is_vector)
{
typedef typename std::iterator_traits<_ForwardIterator1>::difference_type _DifferenceType;
const auto __n1 = __last1 - __first1;
const auto __n2 = __last2 - __first2;
- auto copy_range1 = [__is_vector](_ForwardIterator1 __begin, _ForwardIterator1 __end, _OutputIterator __res) {
+ auto __copy_range1 = [__is_vector](_ForwardIterator1 __begin, _ForwardIterator1 __end, _OutputIterator __res) {
return __internal::__brick_copy(__begin, __end, __res, __is_vector);
};
- auto copy_range2 = [__is_vector](_ForwardIterator2 __begin, _ForwardIterator2 __end, _OutputIterator __res) {
+ auto __copy_range2 = [__is_vector](_ForwardIterator2 __begin, _ForwardIterator2 __end, _OutputIterator __res) {
return __internal::__brick_copy(__begin, __end, __res, __is_vector);
};
// {1} {}: parallel copying just first sequence
if (__n2 == 0)
- return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result, copy_range1,
- std::true_type());
+ return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
+ __copy_range1, std::true_type());
// {} {2}: parallel copying justmake second sequence
if (__n1 == 0)
- return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2, __result, copy_range2,
- std::true_type());
+ return __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2, __result,
+ __copy_range2, std::true_type());
// testing whether the sequences are intersected
_ForwardIterator1 __left_bound_seq_1 = std::lower_bound(__first1, __last1, *__first2, __comp);
if (__left_bound_seq_1 == __last1)
{
//{1} < {2}: seq2 is wholly greater than seq1, so, do parallel copying seq1 and seq2
- __par_backend::__parallel_invoke(std::forward<_ExecutionPolicy>(__exec),
- [=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1,
- __last1, __result, copy_range1, std::true_type());
- },
- [=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2,
- __last2, __result + __n1, copy_range2,
- std::true_type());
- });
+ __par_backend::__parallel_invoke(
+ std::forward<_ExecutionPolicy>(__exec),
+ [=] {
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __result,
+ __copy_range1, std::true_type());
+ },
+ [=] {
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2,
+ __result + __n1, __copy_range2, std::true_type());
+ });
return __result + __n1 + __n2;
}
if (__left_bound_seq_2 == __last2)
{
//{2} < {1}: seq2 is wholly greater than seq1, so, do parallel copying seq1 and seq2
- __par_backend::__parallel_invoke(std::forward<_ExecutionPolicy>(__exec),
- [=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2,
- __last2, __result, copy_range2, std::true_type());
- },
- [=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1,
- __last1, __result + __n2, copy_range1,
- std::true_type());
- });
+ __par_backend::__parallel_invoke(
+ std::forward<_ExecutionPolicy>(__exec),
+ [=] {
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __last2, __result,
+ __copy_range2, std::true_type());
+ },
+ [=] {
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
+ __result + __n2, __copy_range1, std::true_type());
+ });
return __result + __n1 + __n2;
}
std::forward<_ExecutionPolicy>(__exec),
//do parallel copying of [first1; left_bound_seq_1)
[=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __left_bound_seq_1, __res_or,
- copy_range1, std::true_type());
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first1, __left_bound_seq_1,
+ __res_or, __copy_range1, std::true_type());
},
[=, &__result] {
- __result = __internal::__parallel_set_op(std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1,
- __first2, __last2, __result, __comp,
- [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; },
- __set_union_op, __is_vector);
+ __result = __internal::__parallel_set_op(
+ std::forward<_ExecutionPolicy>(__exec), __left_bound_seq_1, __last1, __first2, __last2, __result,
+ __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op,
+ __is_vector);
});
return __result;
}
const auto __m2 = __left_bound_seq_2 - __first2;
- __PSTL_ASSERT(__m1 == 0 || __m2 == 0);
+ _PSTL_ASSERT(__m1 == 0 || __m2 == 0);
if (__m2 > __set_algo_cut_off)
{
auto __res_or = __result;
std::forward<_ExecutionPolicy>(__exec),
//do parallel copying of [first2; left_bound_seq_2)
[=] {
- __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __left_bound_seq_2, __res_or,
- copy_range2, std::true_type());
+ __internal::__pattern_walk2_brick(std::forward<_ExecutionPolicy>(__exec), __first2, __left_bound_seq_2,
+ __res_or, __copy_range2, std::true_type());
},
[=, &__result] {
- __result = __internal::__parallel_set_op(std::forward<_ExecutionPolicy>(__exec), __first1, __last1,
- __left_bound_seq_2, __last2, __result, __comp,
- [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; },
- __set_union_op, __is_vector);
+ __result = __internal::__parallel_set_op(
+ std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __left_bound_seq_2, __last2, __result,
+ __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op,
+ __is_vector);
});
return __result;
}
- return __internal::__parallel_set_op(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
- __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op,
- __is_vector);
+ return __internal::__parallel_set_op(
+ std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
+ [](_DifferenceType __n, _DifferenceType __m) { return __n + __m; }, __set_union_op, __is_vector);
}
-#endif
//------------------------------------------------------------------------
// set_union
_ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
/*__is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
}
return __internal::__brick_set_union(__first1, __last1, __first2, __last2, __result, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _IsVector>
_OutputIterator
return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
typedef typename std::iterator_traits<_OutputIterator>::value_type _T;
- return __internal::__parallel_set_union_op(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
- __comp,
- [](_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
- _ForwardIterator2 __last2, _T* __result, _Compare __comp) {
- return std::set_union(__first1, __last1, __first2, __last2, __result, __comp);
- },
- __is_vector);
+ return __internal::__parallel_set_union_op(
+ std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
+ [](_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2, _ForwardIterator2 __last2,
+ _T* __result,
+ _Compare __comp) { return std::set_union(__first1, __last1, __first2, __last2, __result, __comp); },
+ __is_vector);
}
-#endif
//------------------------------------------------------------------------
// set_intersection
_ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
/*__is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::set_intersection(__first1, __last1, __first2, __last2, __result, __comp);
}
return __internal::__brick_set_intersection(__first1, __last1, __first2, __last2, __result, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _IsVector>
_OutputIterator
// [left_bound_seq_1; last1) and [left_bound_seq_2; last2) - use serial algorithm
return std::set_intersection(__left_bound_seq_1, __last1, __left_bound_seq_2, __last2, __result, __comp);
}
-#endif
//------------------------------------------------------------------------
// set_difference
_ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
/*__is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
}
return __internal::__brick_set_difference(__first1, __last1, __first2, __last2, __result, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _IsVector>
_OutputIterator
std::true_type());
if (__n1 + __n2 > __set_algo_cut_off)
- return __internal::__parallel_set_op(std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result,
- __comp, [](_DifferenceType __n, _DifferenceType __m) { return __n; },
- [](_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
- _ForwardIterator2 __last2, _T* __result, _Compare __comp) {
- return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
- },
- __is_vector);
+ return __internal::__parallel_set_op(
+ std::forward<_ExecutionPolicy>(__exec), __first1, __last1, __first2, __last2, __result, __comp,
+ [](_DifferenceType __n, _DifferenceType __m) { return __n; },
+ [](_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
+ _ForwardIterator2 __last2, _T* __result,
+ _Compare __comp) { return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp); },
+ __is_vector);
// use serial algorithm
return std::set_difference(__first1, __last1, __first2, __last2, __result, __comp);
}
-#endif
//------------------------------------------------------------------------
// set_symmetric_difference
_ForwardIterator2 __last2, _OutputIterator __result, _Compare __comp,
/*__is_vector=*/std::true_type) noexcept
{
- __PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
+ _PSTL_PRAGMA_MESSAGE("Vectorized algorithm unimplemented, redirected to serial");
return std::set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp);
}
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _OutputIterator __result,
_Compare __comp, _IsVector __is_vector, /*is_parallel=*/std::false_type) noexcept
{
- return __internal::__brick_set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp, __is_vector);
+ return __internal::__brick_set_symmetric_difference(__first1, __last1, __first2, __last2, __result, __comp,
+ __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _OutputIterator,
class _Compare, class _IsVector>
_OutputIterator
},
__is_vector);
}
-#endif
//------------------------------------------------------------------------
// is_heap_until
template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
_RandomAccessIterator
__is_heap_until_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
- /* __is_vector = */ std::false_type) noexcept
+ /* __is_vector = */ std::false_type) noexcept
{
_DifferenceType __i = __begin;
for (; __i < __end; ++__i)
template <class _RandomAccessIterator, class _DifferenceType, class _Compare>
_RandomAccessIterator
__is_heap_until_local(_RandomAccessIterator __first, _DifferenceType __begin, _DifferenceType __end, _Compare __comp,
- /* __is_vector = */ std::true_type) noexcept
+ /* __is_vector = */ std::true_type) noexcept
{
return __unseq_backend::__simd_first(
__first, __begin, __end,
[&__comp](_RandomAccessIterator __it, _DifferenceType __i) { return __comp(__it[(__i - 1) / 2], __it[__i]); });
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator, class _Compare, class _IsVector>
_RandomAccessIterator
__pattern_is_heap_until(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last,
std::less<typename std::iterator_traits<_RandomAccessIterator>::difference_type>(), /*is_first=*/true);
});
}
-#endif
//------------------------------------------------------------------------
// min_element
__brick_min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp,
/* __is_vector = */ std::true_type) noexcept
{
-#if __PSTL_UDR_PRESENT
+#if _PSTL_UDR_PRESENT
return __unseq_backend::__simd_min_element(__first, __last - __first, __comp);
#else
return std::min_element(__first, __last, __comp);
return __internal::__brick_min_element(__first, __last, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <typename _ExecutionPolicy, typename _RandomAccessIterator, typename _Compare, typename _IsVector>
_RandomAccessIterator
__pattern_min_element(_ExecutionPolicy&& __exec, _RandomAccessIterator __first, _RandomAccessIterator __last,
std::forward<_ExecutionPolicy>(__exec), __first + 1, __last, __first,
[=](_RandomAccessIterator __begin, _RandomAccessIterator __end,
_RandomAccessIterator __init) -> _RandomAccessIterator {
- const _RandomAccessIterator subresult = __internal::__brick_min_element(__begin, __end, __comp, __is_vector);
+ const _RandomAccessIterator subresult =
+ __internal::__brick_min_element(__begin, __end, __comp, __is_vector);
return __internal::__cmp_iterators_by_values(__init, subresult, __comp);
},
[=](_RandomAccessIterator __it1, _RandomAccessIterator __it2) -> _RandomAccessIterator {
});
});
}
-#endif
//------------------------------------------------------------------------
// minmax_element
__brick_minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp,
/* __is_vector = */ std::true_type) noexcept
{
-#if __PSTL_UDR_PRESENT
+#if _PSTL_UDR_PRESENT
return __unseq_backend::__simd_minmax_element(__first, __last - __first, __comp);
#else
return std::minmax_element(__first, __last, __comp);
return __internal::__brick_minmax_element(__first, __last, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <typename _ExecutionPolicy, typename _ForwardIterator, typename _Compare, typename _IsVector>
std::pair<_ForwardIterator, _ForwardIterator>
__pattern_minmax_element(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Compare __comp,
std::forward<_ExecutionPolicy>(__exec), __first + 1, __last, std::make_pair(__first, __first),
[=](_ForwardIterator __begin, _ForwardIterator __end, _Result __init) -> _Result {
const _Result __subresult = __internal::__brick_minmax_element(__begin, __end, __comp, __is_vector);
- return std::make_pair(
- __internal::__cmp_iterators_by_values(__subresult.first, __init.first, __comp),
- __internal::__cmp_iterators_by_values(__init.second, __subresult.second, __not_pred<_Compare>(__comp)));
+ return std::make_pair(__internal::__cmp_iterators_by_values(__subresult.first, __init.first, __comp),
+ __internal::__cmp_iterators_by_values(__init.second, __subresult.second,
+ __not_pred<_Compare>(__comp)));
},
[=](_Result __p1, _Result __p2) -> _Result {
return std::make_pair(
});
});
}
-#endif
//------------------------------------------------------------------------
// mismatch
__mismatch_serial(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2,
_ForwardIterator2 __last2, _BinaryPredicate __pred)
{
-#if __PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT
+#if _PSTL_CPP14_2RANGE_MISMATCH_EQUAL_PRESENT
return std::mismatch(__first1, __last1, __first2, __last2, __pred);
#else
for (; __first1 != __last1 && __first2 != __last2 && __pred(*__first1, *__first2); ++__first1, ++__first2)
return __internal::__brick_mismatch(__first1, __last1, __first2, __last2, __pred, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _RandomAccessIterator1, class _RandomAccessIterator2, class _Predicate,
class _IsVector>
std::pair<_RandomAccessIterator1, _RandomAccessIterator2>
auto __result = __internal::__parallel_find(
std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
[__first1, __first2, __pred, __is_vector](_RandomAccessIterator1 __i, _RandomAccessIterator1 __j) {
- return __internal::__brick_mismatch(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1), __pred,
- __is_vector)
+ return __internal::__brick_mismatch(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
+ __pred, __is_vector)
.first;
},
std::less<typename std::iterator_traits<_RandomAccessIterator1>::difference_type>(), /*is_first=*/true);
return std::make_pair(__result, __first2 + (__result - __first1));
});
}
-#endif
//------------------------------------------------------------------------
// lexicographical_compare
return __internal::__brick_lexicographical_compare(__first1, __last1, __first2, __last2, __comp, __is_vector);
}
-#if __PSTL_USE_PAR_POLICIES
template <class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _Compare, class _IsVector>
bool
__pattern_lexicographical_compare(_ExecutionPolicy&& __exec, _ForwardIterator1 __first1, _ForwardIterator1 __last1,
std::forward<_ExecutionPolicy>(__exec), __first1, __first1 + __n,
[__first1, __first2, &__comp, __is_vector](_ForwardIterator1 __i, _ForwardIterator1 __j) {
return __internal::__brick_mismatch(__i, __j, __first2 + (__i - __first1), __first2 + (__j - __first1),
- [&__comp](const _RefType1 __x, const _RefType2 __y) {
- return !__comp(__x, __y) && !__comp(__y, __x);
- },
- __is_vector)
+ [&__comp](const _RefType1 __x, const _RefType2 __y) {
+ return !__comp(__x, __y) && !__comp(__y, __x);
+ },
+ __is_vector)
.first;
},
std::less<typename std::iterator_traits<_ForwardIterator1>::difference_type>(), /*is_first=*/true);
}
}
}
-#endif
} // namespace __internal
} // namespace __pstl
-#endif /* __PSTL_algorithm_impl_H */
+#endif /* _PSTL_ALGORITHM_IMPL_H */