ORIGINAL
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1#ifndef TYPES_H
2#define TYPES_H
3
4#include <type_traits>
5#include <concepts>
6#include <iosfwd>
7#include "config.h"
8
21namespace original {
22
23 // ==================== Fundamental Types ====================
24
32 class none {
33 public:
35 consteval explicit none() = default;
36
38 constexpr ~none() = default;
39
44 consteval explicit operator bool() const;
45
50 consteval bool operator!() const;
51 };
52
53 // ==================== Core Concepts ====================
54
67 template<typename... ARGS>
68 concept NotNull = sizeof...(ARGS) > 0;
69
75 template<typename TYPE>
76 concept EnumType = std::is_enum_v<TYPE>;
77
91 template <typename TYPE>
92 concept Comparable = requires(const TYPE& t1, const TYPE& t2) {
93 { t1 == t2 } -> std::same_as<bool>;
94 { t1 != t2 } -> std::same_as<bool>;
95 { t1 < t2 } -> std::same_as<bool>;
96 { t1 <= t2 } -> std::same_as<bool>;
97 { t1 > t2 } -> std::same_as<bool>;
98 { t1 >= t2 } -> std::same_as<bool>;
99 };
100
113 template <typename TYPE>
114 concept Printable = requires(std::ostream& os, const TYPE& t) {
115 { os << t } -> std::same_as<std::ostream&>;
116 };
117
118 // ==================== Callback Concepts ====================
119
135 template <typename Callback, typename ReturnType, typename... Args>
136 concept CallbackOf = requires(Callback callback, Args&&... args) {
137 { callback(std::forward<Args>(args)...) } -> std::same_as<ReturnType>;
138 };
139
158 template <typename Callback, typename TYPE>
161
180 template <typename Callback, typename TYPE>
182
201 template <typename Callback, typename TYPE>
203
204 // ==================== Type Relationship Concepts ====================
205
223 template <typename Base, typename Derive>
224 concept SuperOf = std::is_base_of_v<Base, Derive> || std::is_same_v<Base, Derive>;
225
243 template <typename Base, typename Derive>
244 concept ExtendsOf = std::derived_from<Derive, Base> || std::is_same_v<Base, Derive>;
245
246 // ==================== Compile-time Index Sequences ====================
247
254 template <u_integer... INTS>
256 static constexpr u_integer SIZE = sizeof...(INTS);
257 public:
262 static consteval u_integer size() noexcept;
263 };
264
271 template <u_integer NUM, u_integer... INTS>
272 class indexSequenceImpl;
273
274 template <u_integer... INTS>
275 class indexSequenceImpl<0, INTS...> {
276 public:
277 using type = indexSequence<INTS...>;
278 };
279
280 template <u_integer NUM, u_integer... INTS>
281 class indexSequenceImpl : public indexSequenceImpl<NUM - 1, NUM - 1, INTS...> {
282 public:
283 using type = indexSequenceImpl<NUM - 1, NUM - 1, INTS...>::type;
284 };
285 public:
286 template <u_integer NUM>
287 friend consteval auto makeSequence() noexcept;
288 };
289
295 template <u_integer NUM>
296 consteval auto makeSequence() noexcept; // NOLINT: Forward declaration for makeReverseSequence
297
304 template<u_integer... Indices>
305 consteval auto reverseIndexSequenceImpl(indexSequence<Indices...> seq);
306
312 template<u_integer N>
313 using makeReverseSequence = decltype(
315 );
316
317 // ==================== Function Traits ====================
318
329 template <typename Callback>
330 struct functionTraits;
331
333 template <typename R, typename... Args>
334 struct functionTraits<R(*)(Args...)> {
335 using ReturnType = R;
336 using Signature = R(Args...);
337 };
338
340 template <typename R, typename... Args>
341 struct functionTraits<R(Args...)> {
342 using ReturnType = R;
343 using Signature = R(Args...);
344 };
345
347 template <typename C>
349 private:
350 using CallType = functionTraits<decltype(&C::operator())>;
351 public:
352 using ReturnType = CallType::ReturnType;
353 using Signature = CallType::Signature;
354 };
355
357 template <typename C, typename R, typename... Args>
358 struct functionTraits<R(C::*)(Args...) const> {
359 using ReturnType = R;
360 using Signature = R(Args...);
361 };
362
364 template <typename C, typename R, typename... Args>
365 struct functionTraits<R(C::*)(Args...)> {
366 using ReturnType = R;
367 using Signature = R(Args...);
368 };
369
370} // namespace original
371
372consteval original::none::operator bool() const {
373 return false;
374}
375
376consteval bool original::none::operator!() const {
377 return true;
378}
379
380template<original::u_integer... INTS>
382 return SIZE;
383}
384
385template<original::u_integer NUM>
386consteval auto original::makeSequence() noexcept {
387 using sequence = makeIndexSequence::indexSequenceImpl<NUM>::type;
388 return sequence{};
389}
390
391template <original::u_integer... Indices>
393{
394 return indexSequence<sizeof...(Indices) - 1 - Indices...>{};
395}
396
397#endif // TYPES_H
Compile-time sequence of unsigned integers.
Definition types.h:255
static consteval u_integer size() noexcept
Gets the size of the sequence.
Definition types.h:381
Utility for generating index sequences.
Definition types.h:270
friend consteval auto makeSequence() noexcept
Creates an index sequence of given length.
A placeholder type representing the absence of a value.
Definition types.h:32
constexpr ~none()=default
Default destructor (constexpr)
consteval none()=default
Default constructor (consteval)
consteval bool operator!() const
Logical NOT operator.
Definition types.h:376
Validates callback signature compatibility.
Definition types.h:136
Requires type to support all comparison operators.
Definition types.h:92
Combines Comparable and CallbackOf for comparison callbacks.
Definition types.h:159
Constraint for predicate callbacks.
Definition types.h:181
Requires type to be an enumeration.
Definition types.h:76
Checks derivation or type identity using std::derived_from.
Definition types.h:244
Ensures the parameter pack is not empty.
Definition types.h:68
Constraint for mutating operations.
Definition types.h:202
Requires type to support output stream insertion.
Definition types.h:114
Checks inheritance or type equality.
Definition types.h:224
Platform-independent type definitions and compiler/platform detection.
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
Main namespace for the project Original.
Definition algorithms.h:21
consteval auto makeSequence() noexcept
Creates an index sequence of given length.
Definition types.h:386
consteval auto reverseIndexSequenceImpl(indexSequence< Indices... > seq)
Implementation detail for reversing an index sequence.
Definition types.h:392
decltype(reverseIndexSequenceImpl(makeSequence< N >())) makeReverseSequence
Creates a reversed index sequence.
Definition types.h:315
Primary template for general callable types.
Definition types.h:348