Helios Engine
A modular ECS based data-oriented C++23 game engine framework
Loading...
Searching...
No Matches
common_traits.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <concepts>
6#include <type_traits>
7
8namespace helios::utils {
9
10namespace details {
11
12// Helper: recursively check uniqueness after removing cv/ref.
13// Primary: empty pack => true
14template <typename...>
15struct UniqueTypesHelper : std::true_type {};
16
17// Recursive case
18template <typename T, typename... Rest>
19struct UniqueTypesHelper<T, Rest...>
20 : std::bool_constant<
21 // T must differ from every type in Rest (after remove_cvref)
22 (!(std::same_as<std::remove_cvref_t<T>, std::remove_cvref_t<Rest>> ||
23 ...))
24 // and Rest themselves must be unique
25 && UniqueTypesHelper<Rest...>::value> {};
26
27} // namespace details
28
29/**
30 * @brief Concept for arithmetic types (integral or floating-point).
31 */
32template <typename T>
33concept ArithmeticTrait = std::integral<T> || std::floating_point<T>;
34
35/**
36 * @brief Concept for lambda closure types.
37 * @details Detects lambdas via compiler-specific type-name heuristics (or
38 * C++26 reflection when available).
39 */
40template <typename T>
42
43/**
44 * @brief Concept for regular functor types (named structs/classes that are not
45 * lambda closures).
46 */
47template <typename T>
48concept FunctorTrait = std::is_class_v<T> && !LambdaTrait<T>;
49
50/**
51 * @brief Concept that checks if all types in a pack are unique (after removing
52 * cv/ref qualifiers).
53 */
54template <typename... Ts>
56
57/**
58 * @brief Concept to allow argument conversion with polymorphic relationships.
59 * @details Allows regular convertibility or base/derived relationship for
60 * polymorphic types. This is useful for type-erased containers and delegates to
61 * provide flexible argument handling.
62 *
63 * The concept is satisfied when:
64 * - From is convertible to To (standard conversion), OR
65 * - Both From and To are polymorphic types and one derives from the other
66 *
67 * @tparam From Source type.
68 * @tparam To Target type.
69 */
70template <typename From, typename To>
72 std::convertible_to<From, To> ||
73 (std::is_polymorphic_v<std::remove_reference_t<From>> &&
74 std::is_polymorphic_v<std::remove_reference_t<To>> &&
75 (std::derived_from<std::remove_cvref_t<From>, std::remove_cvref_t<To>> ||
76 std::derived_from<std::remove_cvref_t<To>, std::remove_cvref_t<From>>));
77
78} // namespace helios::utils
Concept for arithmetic types (integral or floating-point).
Concept for regular functor types (named structs/classes that are not lambda closures).
Concept for lambda closure types.
Concept to allow argument conversion with polymorphic relationships.
Concept that checks if all types in a pack are unique (after removing cv/ref qualifiers).
consteval bool IsLambdaType() noexcept
Detects whether T is a lambda closure type.