COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
detect.h
Go to the documentation of this file.
1//
2// Copyright 2017 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
10
11#pragma once
12
15
16#if COMMS_HAS_CPP20_SPAN
17#include <span>
18#endif // #if COMMS_HAS_CPP20_SPAN
19
20namespace comms
21{
22
23namespace util
24{
25
26namespace detect
27{
28
29namespace details
30{
31
32// MSVC2015 Is not working correctly with VoidT or any other workaround
33// suggested at https://en.cppreference.com/w/cpp/types/void_t
34
35// template <typename... TArgs>
36// using VoidT = void;
37
38// template <typename TVoid, template <class...> class TOp, typename... TArgs>
39// struct PresenceDetector
40// {
41// static const bool Value = false;
42// };
43
44// template <template <class...> class TOp, typename... TArgs>
45// struct PresenceDetector<VoidT<TOp<TArgs...> >, TOp, TArgs...>
46// {
47// static const bool Value = true;
48// };
49
50// template <template <class...> class TOp, typename... TArgs>
51// constexpr bool isDetected()
52// {
53// return PresenceDetector<void, TOp, TArgs...>::Value;
54// }
55
56// template <typename T>
57// using HasClearOp = decltype(std::declval<T&>().clear());
58
59// template <typename T>
60// using HasReserveOp = decltype(std::declval<T&>().reserve(std::declval<typename T::size_type>()));
61
62template <typename T>
63struct IsStdSpan
64{
65 static constexpr bool Value = false;
66};
67
68#if COMMS_HAS_CPP20_SPAN
69template <typename T, std::size_t TExt>
70struct IsStdSpan<std::span<T, TExt> >
71{
72 static constexpr bool Value = true;
73};
74#endif // #if COMMS_HAS_CPP20_SPAN
75
76template <typename T>
77class HasClearFunc
78{
79 using No = comms::util::EmptyStruct<>;
80
81protected:
82 template <typename C>
83 static auto test(std::nullptr_t) -> decltype(std::declval<C>().clear());
84
85 template <typename>
86 static No test(...);
87
88public:
89 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
90};
91
92template <typename T>
93class HasReserveFunc
94{
95 using No = comms::util::EmptyStruct<>;
96
97protected:
98 template <typename C>
99 static auto test(std::nullptr_t) -> decltype(std::declval<C>().reserve(0U));
100
101 template <typename>
102 static No test(...);
103
104public:
105 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
106};
107
108template <typename T>
109class HasResizeFunc
110{
111 using No = comms::util::EmptyStruct<>;
112
113protected:
114 template <typename C>
115 static auto test(std::nullptr_t) -> decltype(std::declval<C>().resize(0U));
116
117 template <typename>
118 static No test(...);
119
120public:
121 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
122};
123
124template <typename T>
125class HasRemoveSuffixFunc
126{
127 using No = comms::util::EmptyStruct<>;
128
129protected:
130 template <typename C>
131 static auto test(std::nullptr_t) -> decltype(std::declval<C>().remove_suffix(0U));
132
133 template <typename>
134 static No test(...);
135
136public:
137 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
138};
139
140template <typename T>
141class HasAssignFunc
142{
143 using No = comms::util::EmptyStruct<>;
144
145protected:
146 template <typename C>
147 static auto test(std::nullptr_t) -> decltype(std::declval<C>().assign(static_cast<typename C::const_pointer>(nullptr), static_cast<typename C::const_pointer>(nullptr)));
148
149 template <typename>
150 static No test(...);
151
152public:
153 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
154};
155
156template <typename T>
157class HasPtrSizeConstructor
158{
159 using No = comms::util::EmptyStruct<>;
160
161protected:
162 template <typename C>
163 static auto test(std::nullptr_t) -> decltype(C(static_cast<typename C::const_pointer>(nullptr), static_cast<typename C::size_type>(0U)));
164
165 template <typename>
166 static No test(...);
167
168public:
169 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
170};
171
172template <typename T>
173class HasMaxSizeFunc
174{
175 using No = comms::util::EmptyStruct<>;
176
177protected:
178 template <typename C>
179 static auto test(std::nullptr_t) -> decltype(std::declval<C>().max_size());
180
181 template <typename>
182 static No test(...);
183
184public:
185 static const bool Value = !std::is_same<No, decltype(test<T>(nullptr))>::value;
186};
187
188} // namespace details
189
190} // namespace detect
191
192} // namespace util
193
194} // namespace comms
Contains various compiler related definitions.
Main namespace for all classes / functions of COMMS library.
STL namespace.
Replacement to some types from standard type_traits.