AUI Framework  master
Cross-platform base for C++ UI apps
Loading...
Searching...
No Matches
members.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 <tuple>
   16#include <string_view>
   17
   18#ifndef AUI_REFLECT_FIELD_NAMES_ENABLED
   19#if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L))
   20#if (defined(__cpp_nontype_template_args) && __cpp_nontype_template_args >= 201911) || \
   21    (defined(__clang_major__) && __clang_major__ >= 12)
   22#define AUI_REFLECT_FIELD_NAMES_ENABLED 1
   23#else
   24#define AUI_REFLECT_FIELD_NAMES_ENABLED 0
   25#endif
   26#else
   27#define AUI_REFLECT_FIELD_NAMES_ENABLED 0
   28#endif
   29#endif
   30
   31namespace aui::reflect {
   47template <typename Type>
   49
   54template <typename Type, typename Clazz>
   55struct member<Type(Clazz::*)> {
   56    using type = Type;     // field type
   57    using clazz = Clazz;   // class type that owns the field
   58};
   59
   60
   64template <typename Type, typename Clazz, typename... Args>
   65struct member<Type (Clazz::*)(Args...) const> {
   66    using return_t = Type;
   67    using clazz = Clazz;
   68
   69    using args = std::tuple<Args...>;
   70
   71    static constexpr bool is_const = true;
   72    static constexpr bool is_noexcept = false;
   73};
   74
   79template <typename Type, typename Clazz, typename... Args>
   80struct member<Type (Clazz::*)(Args...)> {
   81    using return_t = Type;   // function return type
   82    using clazz = Clazz;     // class type that owns the fields
   83
   84    using args = std::tuple<Args...>;   // function args (see note)
   85
   86    static constexpr bool is_const = false;      // whether is const
   87    static constexpr bool is_noexcept = false;   // whether is noexcept
   88};
   89
   90
   94template <typename Type, typename Clazz, typename... Args>
   95struct member<Type (Clazz::*)(Args...) noexcept> {
   96    using return_t = Type;
   97    using clazz = Clazz;
   98
   99    using args = std::tuple<Args...>;
  100
  101    static constexpr bool is_const = false;
  102    static constexpr bool is_noexcept = true;
  103};
  104
  108template <typename Type, typename Clazz, typename... Args>
  109struct member<Type (Clazz::*)(Args...) const noexcept> {
  110    using return_t = Type;
  111    using clazz = Clazz;
  112
  113    using args = std::tuple<Args...>;
  114
  115    static constexpr bool is_const = true;
  116    static constexpr bool is_noexcept = true;
  117};
  118
  123template <typename T>
  124concept pointer_to_member = requires(T &&) { typename aui::reflect::member<T>::clazz; };
  125}   // namespace aui::reflect
Concept of a pointer-to-member.
Definition members.h:124
Pointer to member type (not value) introspection.
Definition members.h:48