AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
parameter_pack.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#include <algorithm>
   15#include <AUI/Traits/concepts.h>
   16
   17namespace aui {
   18    namespace impl {
   19        template<typename First, typename... Up>
   20        struct first {
   21            using type = First;
   22        };
   23    }
   24
   63    namespace parameter_pack {
   64        template<typename Callable, typename... Args>
   65        static void for_each(Callable&& c, Args&&... args) requires (... && aui::invocable<Callable, Args>) {
   66            (..., [&] {
   67                c(std::forward<Args>(args));
   68            }());
   69        }
   70
   71        template<typename... Types>
   72        using first = typename impl::first<Types...>::type;
   73    };
   74
   75    template<typename... Args>
   76    struct tuple_visitor;
   77
   78    template<typename... Args>
   79    struct tuple_visitor<std::tuple<Args...>> {
   80
   93        template<typename Callable>
   94        static void for_each_single(Callable&& c) {
   95            (..., c.template operator()<Args>());
   96        }
   97
  110        template<typename Callable>
  111        static auto for_each_all(Callable&& c) {
  112            return c.template operator()<Args...>();
  113        }
  114
  127        template<typename Callable>
  128        static auto for_each_make_tuple(Callable&& c) {
  129            return for_each_make_tuple_impl<Callable&&, Args...>(std::forward<Callable>(c));
  130        }
  131
  132    private:
  133        template<typename Callable, typename First, typename... Remaining>
  134        static auto for_each_make_tuple_impl(Callable&& c) {
  135            auto x = c.template operator()<First>();
  136            return std::tuple_cat(std::make_tuple(std::move(x)),
  137                                  for_each_make_tuple_impl<Callable&&, Remaining...>(std::forward<Callable>(c)));
  138        }
  139        template<typename Callable>
  140        static auto for_each_make_tuple_impl(Callable&& c) {
  141            return std::make_tuple();
  142        }
  143    };
  144}
Invokable concept.
Definition concepts.h:37
API_AUI_CORE const ACommandLineArgs & args() noexcept
Provides an easy way to iterate over a parameter pack.
Definition parameter_pack.h:63
Definition parameter_pack.h:20
Definition parameter_pack.h:76
static auto for_each_make_tuple(Callable &&c)
Visit types (not values) of the tuple, passing each element as single template argument....
Definition parameter_pack.h:128
static auto for_each_all(Callable &&c)
Visit types (not values) of the tuple, passing each element as template arguments.
Definition parameter_pack.h:111
static void for_each_single(Callable &&c)
Visit types (not values) of the tuple, passing each element as single template arguments.
Definition parameter_pack.h:94