AUI Framework  develop
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
callables.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//
   13// Created by Alex2772 on 11/19/2021.
   14//
   15
   16#pragma once
   17
   18#include "members.h"
   19
   20namespace aui {
   21
   22    template<typename F>
   23    concept not_overloaded_lambda = requires(F&& f) {
   24        // we can't 100% guarantee that T is actual lambda, but C++ lambdas have following traits:
   25        std::is_class_v<F>;
   26        { &std::decay_t<F>::operator() };
   27    };
   28
   29    static_assert(not_overloaded_lambda<decltype([]{})>, "aui::not_overloaded_lambda failed");
   30    static_assert(not_overloaded_lambda<decltype([](int v){})>, "aui::not_overloaded_lambda failed");
   31
   35    template<typename... Lambdas>
   36    struct lambda_overloaded : Lambdas... {
   37        using Lambdas::operator()...;
   38    };
   39
   40    // deduction guide
   41    template<typename... Lambdas>
   42    lambda_overloaded(Lambdas...) -> lambda_overloaded<Lambdas...>;
   43
   44    template<typename Return, typename... Args>
   45    struct function_info;
   46
   47    template<typename Return, typename... Args>
   48    struct function_info<Return(Args...)> {
   49        using return_t = Return;
   50        using args = std::tuple<Args...>;
   51    };
   52
   53    template<typename Return, typename... Args>
   54    struct function_info<Return(*)(Args...)> {
   55        using return_t = Return;
   56        using args = std::tuple<Args...>;
   57    };
   58
   59    template<typename Return, typename... Args>
   60    struct function_info<Return(&)(Args...)> {
   61        using return_t = Return;
   62        using args = std::tuple<Args...>;
   63    };
   64
   65    template<typename Return, typename... Args>
   66    struct function_info<Return(Args...) noexcept> {
   67        using return_t = Return;
   68        using args = std::tuple<Args...>;
   69    };
   70
   71    template<typename Return, typename... Args>
   72    struct function_info<Return(*)(Args...) noexcept> {
   73        using return_t = Return;
   74        using args = std::tuple<Args...>;
   75    };
   76
   77    template<typename Return, typename... Args>
   78    struct function_info<Return(&)(Args...) noexcept> {
   79        using return_t = Return;
   80        using args = std::tuple<Args...>;
   81    };
   82
   83    template<typename T>
   84    concept function_pointer = requires(T&& t) {
   85        typename function_info<T>::args;
   86    };
   87
   88    template<not_overloaded_lambda Lambda>
   89    using lambda_info = ::aui::reflect::member<decltype(&Lambda::operator())>;
   90
   96    struct identity
   97    {
   98        template<typename T>
   99        [[nodiscard]]
  100        constexpr T&& operator()(T&& t) const noexcept { return std::forward<T>(t); }
  101    };
  102}
Definition callables.h:84
Definition callables.h:23
Definition callables.h:45
Function object type whose operator() returns its argument unchanged.
Definition callables.h:97
Definition callables.h:36
Pointer to member type (not value) introspection.
Definition members.h:48