|
2 | 2 | // This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl). |
3 | 3 | // Licensed under the MIT License. See the LICENSE file in the project root for full license information. |
4 | 4 |
|
| 5 | +/// @file gl/types/core.hpp |
| 6 | +/// @brief Core type definitions, traits, and utilities for the GL library. |
| 7 | + |
5 | 8 | #pragma once |
6 | 9 |
|
7 | 10 | #include "gl/attributes/force_inline.hpp" |
|
14 | 17 |
|
15 | 18 | namespace gl { |
16 | 19 |
|
| 20 | +/// @ingroup GL GL-Core |
| 21 | +/// @brief Type alias for the standard size type used throughout the library. |
| 22 | +/// |
| 23 | +/// Used primarily for indices, counts, and sizes of graph components. |
17 | 24 | using size_type = std::size_t; |
| 25 | + |
| 26 | +/// @ingroup GL GL-Core |
| 27 | +/// @brief The default unsigned integer type used for vertex and edge identifiers. |
18 | 28 | using default_id_type = std::uint32_t; |
19 | 29 |
|
| 30 | +/// @namespace gl::traits |
| 31 | +/// @brief Contains C++20 concepts and type traits used to constrain library templates. |
20 | 32 | namespace traits { |
21 | 33 |
|
| 34 | +/// @ingroup GL GL-Traits |
| 35 | +/// @brief Concept defining the requirements for an identifier type. |
| 36 | +/// |
| 37 | +/// Ensures that any custom ID type provided to the graph library is an |
| 38 | +/// unsigned integral type to guarantee safe indexing and representation. |
| 39 | +/// |
| 40 | +/// @tparam T The type to evaluate against the concept. |
22 | 41 | template <typename T> |
23 | 42 | concept c_id_type = std::unsigned_integral<T>; |
24 | 43 |
|
25 | 44 | } // namespace traits |
26 | 45 |
|
| 46 | +/// @ingroup GL GL-Util |
| 47 | +/// @brief Converts a valid identifier to a standard size type (index). |
| 48 | +/// |
| 49 | +/// Provides a safe, explicit cast from any unsigned integral ID type |
| 50 | +/// into a `size_type`, commonly used for array/vector lookups. |
| 51 | +/// |
| 52 | +/// @param id The identifier to convert. |
| 53 | +/// @return The identifier statically cast to `size_type`. |
27 | 54 | [[nodiscard]] gl_attr_force_inline constexpr size_type to_idx(traits::c_id_type auto id) noexcept { |
28 | 55 | return static_cast<size_type>(id); |
29 | 56 | } |
30 | 57 |
|
| 58 | +/// @ingroup GL GL-Util |
| 59 | +/// @brief Converts an integral value to a standard pointer difference type. |
| 60 | +/// |
| 61 | +/// Useful for safe pointer arithmetic and offset calculations within graph data structures. |
| 62 | +/// |
| 63 | +/// @param i The integral value to convert. |
| 64 | +/// @return The value statically cast to `std::ptrdiff_t`. |
31 | 65 | [[nodiscard]] gl_attr_force_inline constexpr std::ptrdiff_t to_diff(std::integral auto i) noexcept { |
32 | 66 | return static_cast<std::ptrdiff_t>(i); |
33 | 67 | } |
34 | 68 |
|
| 69 | +/// @ingroup GL GL-Types |
| 70 | +/// @brief A type alias for a `std::pair` where both elements are of the exact same type. |
| 71 | +/// @tparam `T` The type of both the `first` and `second` elements in the pair. |
35 | 72 | template <typename T> |
36 | 73 | using homogeneous_pair = std::pair<T, T>; |
37 | 74 |
|
|
0 commit comments