Embedded Template Library 1.0
Loading...
Searching...
No Matches
concepts.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2025 BMW AG
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_CONCEPTS_INCLUDED
32#define ETL_CONCEPTS_INCLUDED
33
34#include "platform.h"
35
36#include "type_traits.h"
37#include "utility.h"
38
39#if ETL_NOT_USING_CPP20 && !defined(ETL_IN_UNIT_TEST)
40 #error NOT SUPPORTED FOR BELOW C++20
41#endif
42
43#if ETL_USING_CPP20
44
45 #if ETL_USING_STL
46 #include <concepts>
47 #endif
48
49namespace etl
50{
51
52 #if ETL_USING_STL
53
54 using std::assignable_from;
55 using std::common_reference_with;
56 using std::common_with;
57 using std::convertible_to;
58 using std::derived_from;
59 using std::floating_point;
60 using std::integral;
61 using std::same_as;
62 using std::signed_integral;
63 using std::unsigned_integral;
64
65 #else // not ETL_USING_STL
66
67 namespace private_concepts
68 {
69 template <typename T, typename U>
70 concept same_as_helper = etl::is_same_v<T, U>;
71 }
72
73 //***************************************************************************
74 template <typename T, typename U>
75 concept same_as = private_concepts::same_as_helper<T, U> && private_concepts::same_as_helper<U, T>;
76
77 //***************************************************************************
78 template <typename Derived, typename Base>
79 concept derived_from = etl::is_base_of_v<Base, Derived> && etl::is_convertible_v<const volatile Derived*, const volatile Base*>;
80
81 //***************************************************************************
82 template <typename From, typename To>
83 concept convertible_to = etl::is_convertible_v<From, To> && requires { static_cast<To>(etl::declval<From>()); };
84
85 //***************************************************************************
86 template < class T, typename U >
87 concept common_reference_with = etl::same_as<etl::common_reference_t<T, U>, etl::common_reference_t<U, T> >
88 && etl::convertible_to<T, etl::common_reference_t<T, U> > && etl::convertible_to<U, etl::common_reference_t<T, U> >;
89
90 //***************************************************************************
91 template <typename T, typename U>
92 concept common_with = etl::same_as<etl::common_type_t<T, U>, etl::common_type_t<U, T> > && requires {
93 static_cast<etl::common_type_t<T, U> >(etl::declval<T>());
94 static_cast<etl::common_type_t<T, U> >(etl::declval<U>());
95 } && etl::common_reference_with< etl::add_lvalue_reference_t<const T>, etl::add_lvalue_reference_t<const U> > && etl::common_reference_with< etl::add_lvalue_reference_t<etl::common_type_t<T, U> >, etl::common_reference_t< etl::add_lvalue_reference_t<const T>, etl::add_lvalue_reference_t<const U> > >;
96
97 //***************************************************************************
98 template <typename T>
99 concept integral = etl::is_integral_v<T>;
100
101 //***************************************************************************
102 template <typename T>
103 concept signed_integral = etl::integral<T> && etl::is_signed_v<T>;
104
105 //***************************************************************************
106 template <typename T>
107 concept unsigned_integral = etl::integral<T> && !etl::signed_integral<T>;
108
109 //***************************************************************************
110 template <typename T>
111 concept floating_point = etl::is_floating_point_v<T>;
112
113 //***************************************************************************
114 template <typename LHS, typename RHS>
115 concept assignable_from =
116 etl::is_lvalue_reference_v<LHS> && etl::common_reference_with< const etl::remove_reference_t<LHS>&, const etl::remove_reference_t<RHS>&>
117 && requires(LHS lhs, RHS&& rhs) {
118 { lhs = etl::forward<RHS>(rhs) } -> etl::same_as<LHS>;
119 };
120
121 #endif
122} // namespace etl
123#endif
124#endif
bitset_ext
Definition absolute.h:40