Skip to content

Commit cf4f12a

Browse files
committed
removed redundant gl utility
1 parent dc38849 commit cf4f12a

6 files changed

Lines changed: 125 additions & 180 deletions

File tree

include/gl/io/format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#pragma once
66

77
#include "gl/attributes/force_inline.hpp"
8-
#include "gl/types/traits/concepts.hpp"
8+
#include "gl/types/type_traits.hpp"
99

1010
namespace gl::io {
1111

include/gl/types/properties.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#pragma once
66

77
#include "gl/attributes/force_inline.hpp"
8-
#include "traits/concepts.hpp"
8+
#include "type_traits.hpp"
99

1010
#include <any>
1111
#include <iomanip>

include/gl/types/traits/cache_mode.hpp

Lines changed: 0 additions & 25 deletions
This file was deleted.

include/gl/types/traits/concepts.hpp

Lines changed: 0 additions & 123 deletions
This file was deleted.

include/gl/types/traits/type_extractors.hpp

Lines changed: 0 additions & 27 deletions
This file was deleted.

include/gl/types/type_traits.hpp

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,126 @@
44

55
#pragma once
66

7-
#include "traits/cache_mode.hpp"
8-
#include "traits/concepts.hpp"
9-
#include "traits/type_extractors.hpp"
7+
// Copyright (c) 2024-2026 Jakub Musiał
8+
// This file is part of the CPP-GL project (https://github.com/SpectraL519/cpp-gl).
9+
// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
10+
11+
#pragma once
12+
13+
#include "gl/types/types.hpp"
14+
15+
#include <concepts>
16+
#include <memory>
17+
#include <ranges>
18+
#include <type_traits>
19+
20+
namespace gl::type_traits {
21+
22+
template <typename T>
23+
concept c_properties =
24+
std::semiregular<T> and std::move_constructible<T> and std::assignable_from<T&, const T&>;
25+
26+
template <typename, template <typename...> typename>
27+
struct is_instantiation_of : std::false_type {};
28+
29+
template <template <typename...> typename U, typename... Args>
30+
struct is_instantiation_of<U<Args...>, U> : std::true_type {};
31+
32+
template <typename T, template <typename...> typename U>
33+
constexpr inline bool is_instantiation_of_v = is_instantiation_of<T, U>::value;
34+
35+
template <typename T, template <typename...> typename Template>
36+
concept c_instantiation_of = is_instantiation_of_v<T, Template>;
37+
38+
template <typename T, typename... Types>
39+
concept c_one_of = std::disjunction_v<std::is_same<T, Types>...>;
40+
41+
template <typename R>
42+
concept c_range = std::ranges::range<R>;
43+
44+
template <typename R>
45+
concept c_sized_range = std::ranges::sized_range<R>;
46+
47+
template <typename R>
48+
concept c_random_access_range = std::ranges::random_access_range<R>;
49+
50+
template <typename R, typename T>
51+
concept c_range_of =
52+
c_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
53+
54+
template <typename R, typename T>
55+
concept c_sized_range_of =
56+
c_sized_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
57+
58+
template <typename R, typename T>
59+
concept c_random_access_range_of =
60+
c_random_access_range<R> and std::same_as<T, std::remove_cv_t<std::ranges::range_value_t<R>>>;
61+
62+
// preserves cv qualifiers
63+
template <typename R, typename T>
64+
concept c_range_of_cv = c_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
65+
66+
// preserves cv qualifiers
67+
template <typename R, typename T>
68+
concept c_sized_range_of_cv = c_sized_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
69+
70+
template <typename R, typename T>
71+
concept c_random_access_range_of_cv =
72+
c_random_access_range<R> and std::same_as<T, std::ranges::range_value_t<R>>;
73+
74+
template <typename R>
75+
concept c_const_range = requires(R& r) {
76+
std::ranges::cbegin(r);
77+
std::ranges::cend(r);
78+
};
79+
80+
template <typename T>
81+
concept c_strong_smart_ptr =
82+
c_instantiation_of<T, std::unique_ptr> or c_instantiation_of<T, std::shared_ptr>;
83+
84+
template <typename T>
85+
concept c_strong_ptr = c_strong_smart_ptr<T> or std::is_pointer_v<T>;
86+
87+
template <typename T>
88+
concept c_const_iterator = requires(T iter) {
89+
{ *iter } -> std::same_as<const std::remove_cvref_t<decltype(*iter)>&>;
90+
};
91+
92+
template <typename T>
93+
concept c_comparable = requires(const T lhs, const T rhs) {
94+
{ lhs <=> rhs } -> std::convertible_to<std::partial_ordering>;
95+
{ lhs == rhs } -> std::convertible_to<bool>;
96+
};
97+
98+
// clang-format off
99+
// "a * b" formatted as "a* b"
100+
101+
template <typename T>
102+
concept c_basic_arithmetic =
103+
std::semiregular<T> and std::constructible_from<T, std::int64_t>
104+
and std::convertible_to<T, std::int64_t> and c_comparable<T>
105+
and requires(const T a, const T b, T c) {
106+
{ a + b } -> std::same_as<T>;
107+
{ a - b } -> std::same_as<T>;
108+
{ a * b } -> std::same_as<T>;
109+
{ a / b } -> std::same_as<T>;
110+
{ c += a } -> std::same_as<T&>;
111+
{ c -= a } -> std::same_as<T&>;
112+
{ c *= a } -> std::same_as<T&>;
113+
{ c /= a } -> std::same_as<T&>;
114+
};
115+
116+
// clang-format on
117+
118+
template <typename T>
119+
concept c_has_numeric_limits_max = requires {
120+
{ std::numeric_limits<T>::max() } -> std::same_as<T>;
121+
};
122+
123+
template <typename T>
124+
concept c_readable = requires(T value, std::istream& is) { is >> value; };
125+
126+
template <typename T>
127+
concept c_writable = requires(T value, std::ostream& os) { os << value; };
128+
129+
} // namespace gl::type_traits

0 commit comments

Comments
 (0)