Skip to content

Commit b8d3804

Browse files
committed
traits docs + mkdoxy update
1 parent 8c0a23a commit b8d3804

6 files changed

Lines changed: 151 additions & 14 deletions

File tree

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,33 @@ TAGS ?= dev
44
.PHONY: docs serve-docs clean-docs clean doxy clean-doxy
55

66
# Example usage: `make docs TAGS="v2.0.0 latest --update-aliases"`
7-
docs:
7+
docs: clean-docs
8+
@echo "==> Deploying MkDocs documentation locally via mike (Tags: $(TAGS))..."
9+
uv run mike deploy $(TAGS)
10+
@echo "==> Documentation deployed to local gh-pages branch."
11+
12+
serve-docs: docs
13+
@echo "==> Serving versioned MkDocs documentation locally via mike..."
14+
uv run mike serve
15+
16+
docs-concepts: clean-docs
817
@echo "==> Deploying MkDocs documentation locally via mike (Tags: $(TAGS))..."
918
doxygen Doxyfile
1019
uv run python scripts/gen_concept_docs.py --config docs/concepts_cfg.json --xml documentation/xml --out docs/cpp-gl
1120
uv run mike deploy $(TAGS)
1221
@echo "==> Documentation deployed to local gh-pages branch."
1322

14-
serve-docs: docs
23+
serve-docs-concepts: docs-concepts
1524
@echo "==> Serving versioned MkDocs documentation locally via mike..."
1625
uv run mike serve
1726

1827
clean-docs:
1928
@echo "==> Cleaning documentation build directories..."
29+
rm -rf docs/cpp-gl/
2030
rm -rf site/
21-
rm -rf documentation/
31+
rm -rf documentation/xml/
2232

23-
clean: clean-docs
33+
clean: clean-docs clean-doxy
2434

2535
doxy:
2636
@echo "==> Building Doxygen documentation..."

include/gl/traits.hpp

Lines changed: 133 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
33
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
44

5+
/// @file gl/traits.hpp
6+
/// @brief Contains C++20 concepts and type traits used to constrain library templates.
7+
58
#pragma once
69

710
#include "gl/types/core.hpp"
@@ -11,99 +14,225 @@
1114
#include <ranges>
1215
#include <type_traits>
1316

17+
/// @namespace gl::traits
18+
/// @brief Contains C++20 concepts and type traits used to constrain library templates.
1419
namespace gl::traits {
1520

16-
template <typename, template <typename...> typename>
21+
/// @ingroup GL GL-Traits
22+
/// @brief Type trait to check if a type is an instantiation of a specific class template.
23+
/// @tparam T The type to check.
24+
/// @tparam Template The class template to match against.
25+
template <typename T, template <typename...> typename Template>
1726
struct is_instantiation_of : std::false_type {};
1827

28+
/// @ingroup GL GL-Traits
29+
/// @brief Specialization of the @ref gl::traits::is_instantiation_of "is_instantiation_of" trait
30+
/// for when the type is an instantiation of the provided class template.
1931
template <template <typename...> typename U, typename... Args>
2032
struct is_instantiation_of<U<Args...>, U> : std::true_type {};
2133

34+
/// @ingroup GL GL-Traits
35+
/// @brief Helper variable template for @ref gl::traits::is_instantiation_of "is_instantiation_of" trait.
36+
/// @tparam T The type to check.
37+
/// @tparam U The class template to match against.
2238
template <typename T, template <typename...> typename U>
2339
constexpr inline bool is_instantiation_of_v = is_instantiation_of<T, U>::value;
2440

41+
/// @ingroup GL GL-Traits
42+
/// @brief Concept checking if a type is an instantiation of a specific class template.
43+
/// @tparam T The type to check.
44+
/// @tparam Template The class template to match against.
2545
template <typename T, template <typename...> typename Template>
2646
concept c_instantiation_of = is_instantiation_of_v<T, Template>;
2747

48+
/// @ingroup GL GL-Traits
49+
/// @brief Concept checking if a type is exactly one of the specified types.
50+
/// @tparam T The type to check.
51+
/// @tparam Types The parameter pack of valid types.
2852
template <typename T, typename... Types>
2953
concept c_one_of = std::disjunction_v<std::is_same<T, Types>...>;
3054

55+
/// @ingroup GL GL-Traits
56+
/// @brief Concept checking if a type satisfies `std::ranges::range`.
57+
/// @tparam R The type to check.
3158
template <typename R>
3259
concept c_range = std::ranges::range<R>;
3360

61+
/// @ingroup GL GL-Traits
62+
/// @brief Concept checking if a type satisfies `std::ranges::forward_range`.
63+
/// @tparam R The type to check.
3464
template <typename R>
3565
concept c_forward_range = std::ranges::forward_range<R>;
3666

67+
/// @ingroup GL GL-Traits
68+
/// @brief Concept checking if a type satisfies `std::ranges::sized_range`.
69+
/// @tparam R The type to check.
3770
template <typename R>
3871
concept c_sized_range = std::ranges::sized_range<R>;
3972

73+
/// @ingroup GL GL-Traits
74+
/// @brief Concept checking if a type satisfies `std::ranges::random_access_range`.
75+
/// @tparam R The type to check.
4076
template <typename R>
4177
concept c_random_access_range = std::ranges::random_access_range<R>;
4278

79+
/// @ingroup GL GL-Traits
80+
/// @brief Concept checking if a type is a range containing a specific value type.
81+
///
82+
/// > [!NOTE] CV qualifiers
83+
/// >
84+
/// > This concept strips cv-qualifiers from the range's value type before comparison.
85+
///
86+
/// @tparam R The type of the range.
87+
/// @tparam T The expected value type.
4388
template <typename R, typename T>
4489
concept c_range_of =
4590
c_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
4691

92+
/// @ingroup GL GL-Traits
93+
/// @brief Concept checking if a type is a forward range containing a specific value type.
94+
///
95+
/// > [!NOTE] CV qualifiers
96+
/// >
97+
/// > This concept strips cv-qualifiers from the range's value type before comparison.
98+
///
99+
/// @tparam R The type of the range.
100+
/// @tparam T The expected value type.
47101
template <typename R, typename T>
48102
concept c_forward_range_of =
49103
c_forward_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
50104

105+
/// @ingroup GL GL-Traits
106+
/// @brief Concept checking if a type is a sized range containing a specific value type.
107+
///
108+
/// > [!NOTE] CV qualifiers
109+
/// >
110+
/// > This concept strips cv-qualifiers from the range's value type before comparison.
111+
///
112+
/// @tparam R The type of the range.
113+
/// @tparam T The expected value type.
51114
template <typename R, typename T>
52115
concept c_sized_range_of =
53116
c_sized_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
54117

118+
/// @ingroup GL GL-Traits
119+
/// @brief Concept checking if a type is a random access range containing a specific value type.
120+
///
121+
/// > [!NOTE] CV qualifiers
122+
/// >
123+
/// > This concept strips cv-qualifiers from the range's value type before comparison.
124+
///
125+
/// @tparam R The type of the range.
126+
/// @tparam T The expected value type.
55127
template <typename R, typename T>
56128
concept c_random_access_range_of =
57129
c_random_access_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
58130

59-
// preserves cv qualifiers
131+
/// @ingroup GL GL-Traits
132+
/// @brief Concept checking if a type is a range containing a specific value type, strictly matching cv-qualifiers.
133+
///
134+
/// > [!NOTE] CV qualifiers
135+
/// >
136+
/// > This concept preserves cv-qualifiers. The value type of the range must match `T` exactly.
137+
///
138+
/// @tparam R The type of the range.
139+
/// @tparam T The expected value type.
60140
template <typename R, typename T>
61141
concept c_range_of_cv = c_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
62142

63-
// preserves cv qualifiers
143+
/// @ingroup GL GL-Traits
144+
/// @brief Concept checking if a type is a forward range containing a specific value type, strictly matching cv-qualifiers.
145+
///
146+
/// > [!NOTE] CV qualifiers
147+
/// >
148+
/// > This concept preserves cv-qualifiers. The value type of the range must match `T` exactly.
149+
///
150+
/// @tparam R The type of the range.
151+
/// @tparam T The expected value type.
64152
template <typename R, typename T>
65153
concept c_forward_range_of_cv =
66154
c_forward_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
67155

68-
// preserves cv qualifiers
156+
/// @ingroup GL GL-Traits
157+
/// @brief Concept checking if a type is a sized range containing a specific value type, strictly matching cv-qualifiers.
158+
///
159+
/// > [!NOTE] CV qualifiers
160+
/// >
161+
/// > This concept preserves cv-qualifiers. The value type of the range must match `T` exactly.
162+
///
163+
/// @tparam R The type of the range.
164+
/// @tparam T The expected value type.
69165
template <typename R, typename T>
70166
concept c_sized_range_of_cv = c_sized_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
71167

168+
/// @ingroup GL GL-Traits
169+
/// @brief Concept checking if a type is a random access range containing a specific value type, strictly matching cv-qualifiers.
170+
///
171+
/// > [!NOTE] CV qualifiers
172+
/// >
173+
/// > This concept preserves cv-qualifiers. The value type of the range must match `T` exactly.
174+
///
175+
/// @tparam R The type of the range.
176+
/// @tparam T The expected value type.
72177
template <typename R, typename T>
73178
concept c_random_access_range_of_cv =
74179
c_random_access_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
75180

181+
/// @ingroup GL GL-Traits
182+
/// @brief Concept checking if a range provides valid const iterators via `cbegin()` and `cend()`.
183+
/// @tparam R The type of the range.
76184
template <typename R>
77185
concept c_const_range = requires(R& r) {
78186
std::ranges::cbegin(r);
79187
std::ranges::cend(r);
80188
};
81189

190+
/// @ingroup GL GL-Traits
191+
/// @brief Concept checking if dereferencing an iterator yields a const reference.
192+
/// @tparam T The iterator type to check.
82193
template <typename T>
83194
concept c_const_iterator = requires(T iter) {
84195
{ *iter } -> std::same_as<const std::remove_cvref_t<decltype(*iter)>&>;
85196
};
86197

198+
/// @ingroup GL GL-Traits
199+
/// @brief Concept checking if a type supports three-way comparison and equality operators.
200+
/// @tparam T The type to check.
87201
template <typename T>
88202
concept c_comparable = requires(const T lhs, const T rhs) {
89203
{ lhs <=> rhs } -> std::convertible_to<std::partial_ordering>;
90204
{ lhs == rhs } -> std::convertible_to<bool>;
91205
};
92206

207+
/// @ingroup GL GL-Traits
208+
/// @brief Concept checking if a type is an arithmetic type (integral or floating-point).
209+
/// @tparam T The type to check.
93210
template <typename T>
94211
concept c_arithmetic = std::is_arithmetic_v<T>;
95212

213+
/// @ingroup GL GL-Traits
214+
/// @brief Concept checking if a type provides a valid `std::numeric_limits<T>::max()` value.
215+
/// @tparam T The type to check.
96216
template <typename T>
97217
concept c_has_numeric_limits_max = requires {
98218
{ std::numeric_limits<T>::max() } -> std::same_as<T>;
99219
};
100220

221+
/// @ingroup GL GL-Traits
222+
/// @brief Concept checking if a type can be extracted from a `std::istream`.
223+
/// @tparam T The type to check.
101224
template <typename T>
102225
concept c_readable = requires(T value, std::istream& is) { is >> value; };
103226

227+
/// @ingroup GL GL-Traits
228+
/// @brief Concept checking if a type can be inserted into a `std::ostream`.
229+
/// @tparam T The type to check.
104230
template <typename T>
105231
concept c_writable = requires(T value, std::ostream& os) { os << value; };
106232

233+
/// @ingroup GL GL-Traits
234+
/// @brief Concept checking if a type is an enumeration.
235+
/// @tparam T The type to check.
107236
template <typename T>
108237
concept c_enum = std::is_enum_v<T>;
109238

include/gl/types/core.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ using size_type = std::size_t;
2727
/// @brief The default unsigned integer type used for vertex and edge identifiers.
2828
using default_id_type = std::uint32_t;
2929

30-
/// @namespace gl::traits
31-
/// @brief Contains C++20 concepts and type traits used to constrain library templates.
3230
namespace traits {
3331

3432
/// @ingroup GL GL-Traits

include/gl/util/math.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace gl::util {
4444
///
4545
/// > [!INFO] Time Complexity
4646
/// >
47-
/// > $O(\log(\text{max}(\text{i\_begin}, \text{i\_end})))$ due to the use of the closed-form formula for geometric series.
47+
/// > \f$O(\log(\text{max}(\text{i_begin}, \text{i_end})))\f$ due to the use of the closed-form formula for geometric series.
4848
[[nodiscard]] inline constexpr size_type upow_sum(
4949
const size_type base, size_type i_begin, size_type i_end
5050
) {

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ dependencies = [
1515
]
1616

1717
[tool.uv.sources]
18-
mkdoxy = { git = "https://github.com/SpectraL519/MkDoxy.git" }
18+
mkdoxy = { git = "https://github.com/SpectraL519/MkDoxy.git", rev = "cpp20-concepts" }

uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)