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