1#ifndef MSTL_CORE_ALGORITHM_PARALLEL_HPP__
2#define MSTL_CORE_ALGORITHM_PARALLEL_HPP__
35template <
typename Iterator,
typename BinaryOperation,
typename Result,
37void reduce(Iterator first, Iterator last, BinaryOperation op, Result& res) {
39 if (dist <= Threshhold) {
40 for (Iterator it = first; it != last; ++it)
44 Iterator mid =
_MSTL next(first, dist / 2);
45 Result l_res = res, r_res = res;
49 res = op(l_res, r_res);
69template <
typename Iterator,
typename UnaryOperation,
typename BinaryOp,
typename Result,
73 if (dist <= Threshhold) {
74 for (Iterator it = first; it != last; ++it)
78 Iterator mid =
_MSTL next(first, dist / 2);
constexpr Iterator next(Iterator iter, iter_difference_t< Iterator > n=1)
获取迭代器的后一个位置
constexpr iter_difference_t< Iterator > distance(Iterator first, Iterator last)
计算两个迭代器之间的距离
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
void reduce(Iterator first, Iterator last, BinaryOperation op, Result &res)
并行归约操作
void transform_reduce(Iterator first, Iterator last, UnaryOperation transform, BinaryOp reduce, Result &res)
并行变换归约操作
MSTL_NODISCARD constexpr reference_wrapper< T > ref(T &val) noexcept
创建引用包装器
constexpr Iterator2 transform(Iterator1 first, Iterator1 last, Iterator2 result, UnaryOperation op) noexcept(noexcept(++first) &&noexcept(++result) &&noexcept(*result=op(*first)))
对范围元素应用一元变换
constexpr T initialize() noexcept(is_nothrow_default_constructible< T >::value)
返回类型T的默认初始化值
typename enable_if< Test, T >::type enable_if_t
enable_if的便捷别名