AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
parallel.h
    1/*
    2 * AUI Framework - Declarative UI toolkit for modern C++20
    3 * Copyright (C) 2020-2025 Alex2772 and Contributors
    4 *
    5 * SPDX-License-Identifier: MPL-2.0
    6 *
    7 * This Source Code Form is subject to the terms of the Mozilla Public
    8 * License, v. 2.0. If a copy of the MPL was not distributed with this
    9 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
   10 */
   11
   12#pragma once
   13
   14
   15#include <AUI/Thread/AThreadPool.h>
   16#include <AUI/Traits/iterators.h>
   17
   18namespace aui {
   44    template<typename Iterator, typename Functor>
   45    auto parallel(Iterator begin, Iterator end, Functor&& functor) {
   46        return AThreadPool::global().parallel(begin, end, std::forward<Functor>(functor));
   47    }
   48
   49    namespace impl::parallel {
   50        template<typename Container>
   51        struct LambdaCapturer {
   52            using iterator = decltype(std::declval<Container>().begin());
   53            iterator begin, end;
   54            LambdaCapturer(Container& c):
   55                begin(c.begin()),
   56                end(c.end())
   57            {
   58
   59            }
   60
   61            template<typename Lambda>
   62            auto operator<<(Lambda&& lambda) {
   63                return aui::parallel(begin, end, std::forward<Lambda>(lambda));
   64            }
   65        };
   66    }
   67}
   68
   85#define AUI_PARALLEL_MP(...) aui::impl::parallel::LambdaCapturer(__VA_ARGS__) \
   86<< [&](const std::decay_t<decltype(aui::impl::parallel::LambdaCapturer(__VA_ARGS__))::iterator>& begin, \
   87       const std::decay_t<decltype(aui::impl::parallel::LambdaCapturer(__VA_ARGS__))::iterator>& end)
static AThreadPool & global()
Global thread pool created with the default constructor.
auto parallel(Iterator begin, Iterator end, Functor &&functor)
Definition AThreadPool.h:260