Embedded Template Library 1.0
Loading...
Searching...
No Matches
platform.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) 2016 John Wellbelove
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_PLATFORM_INCLUDED
32#define ETL_PLATFORM_INCLUDED
33
34//*************************************
35// Enable all limit macros
36// Note: This macro must be defined before the first include of stdint.h
37#if !defined(__STDC_LIMIT_MACROS)
38 #define __STDC_LIMIT_MACROS
39#endif
40
41//*************************************
42// Enable all constant macros
43// Note: This macro must be defined before the first include of stdint.h
44#if !defined(__STDC_CONSTANT_MACROS)
45 #define __STDC_CONSTANT_MACROS
46#endif
47
48#include <limits.h>
49#include <stddef.h>
50#include <stdint.h>
51
52#include "file_error_numbers.h"
53
54//*************************************
55// Include the user's profile definition.
56#if !defined(ETL_NO_PROFILE_HEADER) && defined(__has_include)
57 #if !__has_include("etl_profile.h")
58 #define ETL_NO_PROFILE_HEADER
59 #endif
60#endif
61
62#if !defined(ETL_NO_PROFILE_HEADER)
63 #include "etl_profile.h"
64#endif
65
66// Null statement
67#define ETL_DO_NOTHING static_cast<void>(0)
68
69// Determine the bit width of the platform.
70#define ETL_PLATFORM_16BIT (UINT16_MAX == UINTPTR_MAX)
71#define ETL_PLATFORM_32BIT (UINT32_MAX == UINTPTR_MAX)
72#define ETL_PLATFORM_64BIT (UINT64_MAX == UINTPTR_MAX)
73
74//*************************************
75// Define debug macros.
76#if (defined(_DEBUG) || defined(DEBUG)) && !defined(ETL_DEBUG)
77 #define ETL_DEBUG
78#endif
79
80#if defined(ETL_DEBUG)
81 #define ETL_IS_DEBUG_BUILD 1
82#else
83 #define ETL_IS_DEBUG_BUILD 0
84#endif
85
86//*************************************
87// Do a validity check for error settings, only one is allowed.
88#if defined(ETL_VERBOSE_ERRORS) && defined(ETL_MINIMAL_ERRORS)
89 #error "ETL_VERBOSE_ERRORS and ETL_MINIMAL_ERRORS are mutually exclusive"
90#endif
91
92//*************************************
93// Helper macros, so we don't have to use double negatives.
94// The ETL will use the STL, unless ETL_NO_STL is defined.
95// With this macro we can use '#if ETL_USING_STL' instead of '#if !ETL_NO_STL'
96// in the code.
97#if defined(ETL_NO_STL)
98 #define ETL_USING_STL 0
99 #define ETL_NOT_USING_STL 1
100#else
101 #define ETL_USING_STL 1
102 #define ETL_NOT_USING_STL 0
103#endif
104
105//*************************************
106// Helper macros for ETL_NO_STD_MUTEX.
107#if defined(ETL_NO_STD_MUTEX)
108 #define ETL_USING_STD_MUTEX 0
109 #define ETL_NOT_USING_STD_MUTEX 1
110#else
111 #define ETL_USING_STD_MUTEX 1
112 #define ETL_NOT_USING_STD_MUTEX 0
113#endif
114
115//*************************************
116// Helper macros for ETL_STLPORT.
117#if defined(ETL_STLPORT)
118 #define ETL_USING_STLPORT 1
119 #define ETL_NOT_USING_STLPORT 0
120#else
121 #define ETL_USING_STLPORT 0
122 #define ETL_NOT_USING_STLPORT 1
123#endif
124
125//*************************************
126// Some targets do not support 8bit types.
127#if (CHAR_BIT == 8)
128 #define ETL_USING_8BIT_TYPES 1
129 #define ETL_NOT_USING_8BIT_TYPES 0
130#else
131 #define ETL_USING_8BIT_TYPES 0
132 #define ETL_NOT_USING_8BIT_TYPES 1
133#endif
134
135#define ETL_8BIT_SUPPORT (CHAR_BIT == 8) // Deprecated
136
137//*************************************
138// Some targets support 20bit types.
139#if defined(ETL_USE_20BIT_TYPES)
140 #define ETL_USING_20BIT_TYPES 1
141 #define ETL_NOT_USING_20BIT_TYPES 0
142#else
143 #define ETL_USING_20BIT_TYPES 0
144 #define ETL_NOT_USING_20BIT_TYPES 1
145#endif
146
147//*************************************
148// Helper macro for ETL_NO_64BIT_TYPES.
149#if defined(ETL_NO_64BIT_TYPES)
150 #define ETL_USING_64BIT_TYPES 0
151 #define ETL_NOT_USING_64BIT_TYPES 1
152#else
153 #define ETL_USING_64BIT_TYPES 1
154 #define ETL_NOT_USING_64BIT_TYPES 0
155#endif
156
157//*************************************
158// For when the runtime library is compiled without wchar_t support.
159#if defined(ETL_NO_WIDE_CHARACTERS)
160 #define ETL_USING_WIDE_CHARACTERS 0
161 #define ETL_NOT_USING_WIDE_CHARACTERS 1
162#else
163 #define ETL_USING_WIDE_CHARACTERS 1
164 #define ETL_NOT_USING_WIDE_CHARACTERS 0
165#endif
166
167//*************************************
168// Helper macro for ETL_FORMAT_NO_FLOATING_POINT.
169#if defined(ETL_FORMAT_NO_FLOATING_POINT)
170 #define ETL_USING_FORMAT_FLOATING_POINT 0
171 #define ETL_NOT_USING_FORMAT_FLOATING_POINT 1
172#else
173 #define ETL_USING_FORMAT_FLOATING_POINT 1
174 #define ETL_NOT_USING_FORMAT_FLOATING_POINT 0
175#endif
176
177//*************************************
178// Helper macro for ETL_FORMAT_NO_LONG_DOUBLE_MATH.
179// Define ETL_FORMAT_NO_LONG_DOUBLE_MATH if the toolchain does not provide
180// long double math functions (log10l, floorl, powl, modfl, roundl).
181// When defined, long double arguments are cast to double for math operations.
182#if defined(ETL_FORMAT_NO_LONG_DOUBLE_MATH)
183 #define ETL_USING_FORMAT_LONG_DOUBLE_MATH 0
184 #define ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH 1
185#else
186 #define ETL_USING_FORMAT_LONG_DOUBLE_MATH 1
187 #define ETL_NOT_USING_FORMAT_LONG_DOUBLE_MATH 0
188#endif
189
190//*************************************
191// Figure out things about the compiler, if haven't already done so in
192// etl_profile.h
195
196//*************************************
197// See if we can determine the OS we're compiling on, if haven't already done so
198// in etl_profile.h
200
201//*************************************
202// Helper macro for choosing the variant type.
203#if !ETL_USING_CPP11 || defined(ETL_USE_LEGACY_VARIANT)
204 #define ETL_USING_LEGACY_VARIANT 1
205 #define ETL_NOT_USING_LEGACY_VARIANT 0
206#else
207 #define ETL_USING_LEGACY_VARIANT 0
208 #define ETL_NOT_USING_LEGACY_VARIANT 1
209#endif
210
211//*************************************
212// Check WCHAR_MIN and WCHAR_MAX
213#if !defined(WCHAR_MIN)
214 #define WCHAR_MIN 0x0000
215#endif
216
217#if !defined(WCHAR_MAX)
218 #define WCHAR_MAX 0xFFFF
219#endif
220
221//*************************************
222// Option to force string construction from a character pointer to be explicit.
223#if defined(ETL_FORCE_EXPLICIT_STRING_CONVERSION_FROM_CHAR)
224 #define ETL_EXPLICIT_STRING_FROM_CHAR explicit
225#else
226 #define ETL_EXPLICIT_STRING_FROM_CHAR
227#endif
228
229//*************************************
230// Option to disable truncation checks for strings.
231#if defined(ETL_DISABLE_STRING_TRUNCATION_CHECKS)
232 #define ETL_HAS_STRING_TRUNCATION_CHECKS 0
233#else
234 #define ETL_HAS_STRING_TRUNCATION_CHECKS 1
235#endif
236
237//*************************************
238// Option to disable clear-after-use functionality for strings.
239#if defined(ETL_DISABLE_STRING_CLEAR_AFTER_USE)
240 #define ETL_HAS_STRING_CLEAR_AFTER_USE 0
241#else
242 #define ETL_HAS_STRING_CLEAR_AFTER_USE 1
243#endif
244
245//*************************************
246// Option to make string truncation an error.
247#if defined(ETL_ENABLE_ERROR_ON_STRING_TRUNCATION)
248 #define ETL_HAS_ERROR_ON_STRING_TRUNCATION 1
249#else
250 #define ETL_HAS_ERROR_ON_STRING_TRUNCATION 0
251#endif
252
253//*************************************
254// Option to enable repair-after-memcpy for istrings.
255#if defined(ETL_ISTRING_REPAIR_ENABLE)
256 #define ETL_HAS_ISTRING_REPAIR 1
257#else
258 #define ETL_HAS_ISTRING_REPAIR 0
259#endif
260
261//*************************************
262// Option to enable repair-after-memcpy for ivector.
263#if defined(ETL_IVECTOR_REPAIR_ENABLE)
264 #define ETL_HAS_IVECTOR_REPAIR 1
265#else
266 #define ETL_HAS_IVECTOR_REPAIR 0
267#endif
268
269//*************************************
270// Option to enable repair-after-memcpy for ideque.
271#if defined(ETL_IDEQUE_REPAIR_ENABLE)
272 #define ETL_HAS_IDEQUE_REPAIR 1
273#else
274 #define ETL_HAS_IDEQUE_REPAIR 0
275#endif
276
277//*************************************
278// Option to enable repair-after-memcpy for icircular_buffer.
279#if defined(ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE)
280 #define ETL_HAS_ICIRCULAR_BUFFER_REPAIR 1
281#else
282 #define ETL_HAS_ICIRCULAR_BUFFER_REPAIR 0
283#endif
284
285//*************************************
286// Indicate if C++ exceptions within the ETL are enabled.
287#if defined(ETL_THROW_EXCEPTIONS)
288 #define ETL_USING_EXCEPTIONS 1
289 #define ETL_NOT_USING_EXCEPTIONS 0
290#else
291 #define ETL_USING_EXCEPTIONS 0
292 #define ETL_NOT_USING_EXCEPTIONS 1
293#endif
294
295//*************************************
296// Indicate if C++ exceptions are enabled for debug asserts.
297#if ETL_IS_DEBUG_BUILD && defined(ETL_DEBUG_THROW_EXCEPTIONS)
298 #define ETL_DEBUG_USING_EXCEPTIONS 1
299 #define ETL_DEBUG_NOT_USING_EXCEPTIONS 0
300#else
301 #define ETL_DEBUG_USING_EXCEPTIONS 0
302 #define ETL_DEBUG_NOT_USING_EXCEPTIONS 1
303#endif
304
305//*************************************
306// Indicate if nullptr is used.
307#if ETL_NO_NULLPTR_SUPPORT
308 #define ETL_HAS_NULLPTR 0
309#else
310 #define ETL_HAS_NULLPTR 1
311#endif
312
313//*************************************
314// Indicate if legacy bitset is used.
315#if defined(ETL_USE_LEGACY_BITSET)
316 #define ETL_USING_LEGACY_BITSET 1
317#else
318 #define ETL_USING_LEGACY_BITSET 0
319#endif
320
321//*************************************
322// Indicate if array_view is mutable.
323#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
324 #define ETL_HAS_MUTABLE_ARRAY_VIEW 1
325#else
326 #define ETL_HAS_MUTABLE_ARRAY_VIEW 0
327#endif
328
329//*************************************
330// Indicate if etl::imassage is to be non-virtual.
331#if defined(ETL_MESSAGES_ARE_NOT_VIRTUAL)
332 #define ETL_HAS_VIRTUAL_MESSAGES 0
333#else
334 #define ETL_HAS_VIRTUAL_MESSAGES 1
335#endif
336
337//*************************************
338// Indicate if etl::exception is to be derived from std::exception.
339#if defined(ETL_USE_STD_EXCEPTION)
340 #if ETL_NOT_USING_STL
341 #error "Requested std base for etl::exception, but STL is not used"
342 #endif
343 #define ETL_USING_STD_EXCEPTION 1
344#else
345 #define ETL_USING_STD_EXCEPTION 0
346#endif
347
348//*************************************
349// Indicate if etl::literals::chrono_literals uses ETL verbose style.
350#if defined(ETL_USE_VERBOSE_CHRONO_LITERALS) && ETL_USING_CPP11
351 #define ETL_USING_VERBOSE_CHRONO_LITERALS 1
352#else
353 #define ETL_USING_VERBOSE_CHRONO_LITERALS 0
354#endif
355
356//*************************************
357// Indicate if etl::literals::chrono_literals has days (_days)
358#if defined(ETL_DISABLE_CHRONO_LITERALS_DAY) && ETL_USING_CPP11
359 #define ETL_HAS_CHRONO_LITERALS_DAY 0
360#else
361 #define ETL_HAS_CHRONO_LITERALS_DAY 1
362#endif
363
364//*************************************
365// Indicate if etl::literals::chrono_literals has year (_years)
366#if defined(ETL_DISABLE_CHRONO_LITERALS_YEAR) && ETL_USING_CPP11
367 #define ETL_HAS_CHRONO_LITERALS_YEAR 0
368#else
369 #define ETL_HAS_CHRONO_LITERALS_YEAR 1
370#endif
371
372//*************************************
373// Indicate if etl::literals::chrono_literals has year (_hours, _minutes,
374// _seconds, _milliseconds, _microseconds, _nanoseconds)
375#if defined(ETL_DISABLE_CHRONO_LITERALS_DURATION) && ETL_USING_CPP11
376 #define ETL_HAS_CHRONO_LITERALS_DURATION 0
377#else
378 #define ETL_HAS_CHRONO_LITERALS_DURATION 1
379#endif
380
381//*************************************
382// Indicate if noexcept is part of the function type.
383#if !defined(ETL_HAS_NOEXCEPT_FUNCTION_TYPE)
384 #if defined(__cpp_noexcept_function_type) && (__cpp_noexcept_function_type >= 201510)
385 #define ETL_HAS_NOEXCEPT_FUNCTION_TYPE 1
386 #else
387 #define ETL_HAS_NOEXCEPT_FUNCTION_TYPE 0
388 #endif
389#endif
390
391//*************************************
392// The macros below are dependent on the profile.
393// C++11
394#if ETL_USING_CPP11
395 #define ETL_CONSTEXPR constexpr
396 #define ETL_CONSTEXPR11 constexpr // Synonym for ETL_CONSTEXPR
397 #define ETL_CONSTANT constexpr
398 #define ETL_DELETE = delete
399 #define ETL_EXPLICIT explicit
400 #define ETL_OVERRIDE override
401 #define ETL_FINAL final
402 #define ETL_NORETURN [[noreturn]]
403 #define ETL_MOVE(x) etl::move(x)
404 #define ETL_ENUM_CLASS(name) enum class name
405 #define ETL_ENUM_CLASS_TYPE(name, type) enum class name : type
406 #define ETL_LVALUE_REF_QUALIFIER &
407 #define ETL_RVALUE_REF_QUALIFIER &&
408 #if ETL_USING_EXCEPTIONS
409 #define ETL_NOEXCEPT noexcept
410 #define ETL_NOEXCEPT_EXPR(...) noexcept(__VA_ARGS__)
411 #define ETL_NOEXCEPT_IF(b) noexcept((b))
412 #define ETL_NOEXCEPT_FROM(x) noexcept(noexcept(x))
413 #else
414 #define ETL_NOEXCEPT
415 #define ETL_NOEXCEPT_EXPR(...)
416 #define ETL_NOEXCEPT_IF(b)
417 #define ETL_NOEXCEPT_FROM(x)
418 #endif
419#else
420 #define ETL_CONSTEXPR
421 #define ETL_CONSTEXPR11
422 #define ETL_CONSTANT const
423 #define ETL_DELETE
424 #define ETL_EXPLICIT
425 #define ETL_OVERRIDE
426 #define ETL_FINAL
427 #define ETL_NORETURN
428 #define ETL_NOEXCEPT
429 #define ETL_NOEXCEPT_EXPR(...)
430 #define ETL_NOEXCEPT_IF(b)
431 #define ETL_NOEXCEPT_FROM(x)
432 #define ETL_MOVE(x) x
433 #define ETL_ENUM_CLASS(name) enum name
434 #define ETL_ENUM_CLASS_TYPE(name, type) enum name
435 #define ETL_LVALUE_REF_QUALIFIER
436 #define ETL_RVALUE_REF_QUALIFIER
437#endif
438
439//*************************************
440// C++14
441#if ETL_USING_CPP14
442 #define ETL_CONSTEXPR14 constexpr
443
444 #if !defined(ETL_IN_UNIT_TEST)
445 #define ETL_DEPRECATED [[deprecated]]
446 #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]]
447 #else
448 #define ETL_DEPRECATED
449 #define ETL_DEPRECATED_REASON(reason)
450 #endif
451#else
452 #define ETL_CONSTEXPR14
453 #define ETL_DEPRECATED
454 #define ETL_DEPRECATED_REASON(reason)
455#endif
456
457//*************************************
458// C++17
459#if ETL_USING_CPP17
460 #define ETL_CONSTEXPR17 constexpr
461 #define ETL_IF_CONSTEXPR constexpr
462 #define ETL_NODISCARD [[nodiscard]]
463 #define ETL_MAYBE_UNUSED [[maybe_unused]]
464 #define ETL_FALLTHROUGH [[fallthrough]]
465 #define ETL_INLINE_VAR inline
466#else
467 #define ETL_CONSTEXPR17
468 #define ETL_IF_CONSTEXPR
469 #define ETL_NODISCARD
470 #define ETL_MAYBE_UNUSED
471 #define ETL_FALLTHROUGH
472 #define ETL_INLINE_VAR
473#endif
474
475//*************************************
476// C++20
477#if ETL_USING_CPP20
478 #define ETL_LIKELY [[likely]]
479 #define ETL_UNLIKELY [[unlikely]]
480 #define ETL_CONSTEXPR20 constexpr
481 #define ETL_CONSTEVAL consteval
482 #define ETL_CONSTINIT constinit
483 #define ETL_NO_UNIQUE_ADDRESS [[no_unique_address]]
484 #define ETL_EXPLICIT_EXPR(...) explicit(__VA_ARGS__)
485#else
486 #define ETL_LIKELY
487 #define ETL_UNLIKELY
488 #define ETL_CONSTEXPR20
489 #define ETL_CONSTEVAL
490 #if ETL_USING_CLANG_COMPILER && ETL_COMPILER_FULL_VERSION >= 40000
491 #define ETL_CONSTINIT __attribute__((require_constant_initialization))
492 #elif ETL_USING_GCC_COMPILER && ETL_COMPILER_FULL_VERSION >= 100000
493 #define ETL_CONSTINIT __constinit
494 #else
495 #define ETL_CONSTINIT
496 #endif
497 #define ETL_NO_UNIQUE_ADDRESS
498 #define ETL_EXPLICIT_EXPR(...) explicit
499#endif
500
501#if ETL_USING_CPP20 && ETL_USING_STL
502 #define ETL_CONSTEXPR20_STL constexpr
503#else
504 #define ETL_CONSTEXPR20_STL
505#endif
506
507//*************************************
508// C++23
509#if ETL_USING_CPP23
510 #define ETL_ASSUME(expression) [[assume(expression)]]
511#else
512 #define ETL_ASSUME ETL_DO_NOTHING
513#endif
514
515//*************************************
516// C++26
517#if defined(__has_cpp_attribute)
518 #if __has_cpp_attribute(indeterminate)
519 #define ETL_INDETERMINATE [[indeterminate]]
520 #else
521 #define ETL_INDETERMINATE
522 #endif
523#else
524 #define ETL_INDETERMINATE
525#endif
526
527//*************************************
528// Determine if the ETL can use char8_t type.
529#if ETL_NO_SMALL_CHAR_SUPPORT
531typedef uint_least8_t char8_t;
532 #define ETL_HAS_CHAR8_T 1
533 #define ETL_HAS_NATIVE_CHAR8_T 0
534 #include "private/diagnostic_pop.h"
535#else
536 #define ETL_HAS_CHAR8_T 1
537 #define ETL_HAS_NATIVE_CHAR8_T 1
538#endif
539
540//*************************************
541// Define the large character types if necessary.
542#if ETL_NO_LARGE_CHAR_SUPPORT
543typedef uint_least16_t char16_t;
544typedef uint_least32_t char32_t;
545 #define ETL_HAS_NATIVE_CHAR16_T 0
546 #define ETL_HAS_NATIVE_CHAR32_T 0
547#else
548 #define ETL_HAS_NATIVE_CHAR16_T 1
549 #define ETL_HAS_NATIVE_CHAR32_T 1
550#endif
551
552//*************************************
553// Determine if the ETL can use std::array
554#if !defined(ETL_HAS_STD_ARRAY)
555 #if ETL_USING_STL && ETL_USING_CPP11
556 #define ETL_HAS_STD_ARRAY 1
557 #else
558 #define ETL_HAS_STD_ARRAY 0
559 #endif
560#endif
561
562//*************************************
563// Determine if the ETL can use libc's wchar.h
564#if !defined(ETL_NO_LIBC_WCHAR_H)
565 #if defined(__has_include)
566 #if !__has_include(<wchar.h>)
567 #define ETL_NO_LIBC_WCHAR_H
568 #endif
569 #endif
570#endif
571
572#if defined(ETL_NO_LIBC_WCHAR_H)
573 #define ETL_USING_LIBC_WCHAR_H 0
574 #define ETL_NOT_USING_LIBC_WCHAR_H 1
575#else
576 #define ETL_USING_LIBC_WCHAR_H 1
577 #define ETL_NOT_USING_LIBC_WCHAR_H 0
578#endif
579
580//*************************************
581// Determine if the ETL can use STL ostream
582#if !defined(ETL_NO_STD_OSTREAM) && ETL_USING_STL
583 #if defined(__has_include)
584 #if !__has_include(<ostream>)
585 #define ETL_NO_STD_OSTREAM
586 #endif
587 #endif
588#endif
589
590#if defined(ETL_NO_STD_OSTREAM) || (ETL_NOT_USING_STL && !defined(ETL_IN_UNIT_TEST))
591 #define ETL_USING_STD_OSTREAM 0
592 #define ETL_NOT_USING_STD_OSTREAM 1
593#else
594 #define ETL_USING_STD_OSTREAM 1
595 #define ETL_NOT_USING_STD_OSTREAM 0
596#endif
597
598//*************************************
599// Determine if the ETL should support atomics.
600#if defined(ETL_NO_ATOMICS) || defined(ETL_TARGET_DEVICE_ARM_CORTEX_M0) || defined(ETL_TARGET_DEVICE_ARM_CORTEX_M0_PLUS) \
601 || defined(__STDC_NO_ATOMICS__)
602 #define ETL_HAS_ATOMIC 0
603 #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0
604#else
605 #if ((ETL_USING_CPP11 && ETL_USING_STL) || defined(ETL_COMPILER_ARM5) || defined(ETL_COMPILER_ARM6) || defined(ETL_COMPILER_GCC) \
606 || defined(ETL_COMPILER_CLANG))
607 #define ETL_HAS_ATOMIC 1
608 #else
609 #define ETL_HAS_ATOMIC 0
610 #endif
611 #if ((ETL_USING_CPP17 && ETL_USING_STL) || defined(ETL_COMPILER_ARM5) || defined(ETL_COMPILER_ARM6) || defined(ETL_COMPILER_GCC) \
612 || defined(ETL_COMPILER_CLANG))
613 #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 1
614 #else
615 #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0
616 #endif
617#endif
618
619//*************************************
620// Determine if the ETL should use std::initializer_list.
621#if (defined(ETL_FORCE_ETL_INITIALIZER_LIST) && defined(ETL_FORCE_STD_INITIALIZER_LIST))
622 #error ETL_FORCE_ETL_INITIALIZER_LIST and ETL_FORCE_STD_INITIALIZER_LIST both been defined. Choose one or neither.
623#endif
624
625#if (ETL_USING_CPP11 && !defined(ETL_NO_INITIALIZER_LIST))
626 // Use the compiler's std::initializer_list?
627 #if (ETL_USING_STL && ETL_NOT_USING_STLPORT && !defined(ETL_FORCE_ETL_INITIALIZER_LIST)) || defined(ETL_IN_UNIT_TEST) \
628 || defined(ETL_FORCE_STD_INITIALIZER_LIST)
629 #define ETL_HAS_INITIALIZER_LIST 1
630 #else
631 // Use the ETL's compatible version?
632 #if defined(ETL_COMPILER_MICROSOFT) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_ARM6) \
633 || defined(ETL_COMPILER_ARM7) || defined(ETL_COMPILER_IAR) || defined(ETL_COMPILER_TEXAS_INSTRUMENTS) || defined(ETL_COMPILER_INTEL)
634 #define ETL_HAS_INITIALIZER_LIST 1
635 #else
636 #define ETL_HAS_INITIALIZER_LIST 0
637 #endif
638 #endif
639#else
640 #define ETL_HAS_INITIALIZER_LIST 0
641#endif
642
643//*************************************
644// Determine if the ETL should use __attribute__((packed).
645#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) || defined(ETL_COMPILER_ARM6)
646 #define ETL_PACKED_CLASS(class_type) class __attribute__((packed)) class_type
647 #define ETL_PACKED_STRUCT(struct_type) struct __attribute__((packed)) struct_type
648 #define ETL_END_PACKED
649 #define ETL_HAS_PACKED 1
650#elif defined(ETL_COMPILER_MICROSOFT)
651 #define ETL_PACKED_CLASS(class_type) __pragma(pack(push, 1)) class class_type
652 #define ETL_PACKED_STRUCT(struct_type) __pragma(pack(push, 1)) struct struct_type
653 #define ETL_PACKED
654 #define ETL_END_PACKED __pragma(pack(pop))
655 #define ETL_HAS_PACKED 1
656#else
657 #define ETL_PACKED_CLASS(class_type) class class_type
658 #define ETL_PACKED_STRUCT(struct_type) struct struct_type
659 #define ETL_END_PACKED
660 #define ETL_HAS_PACKED 0
661#endif
662
663//*************************************
664// Check for availability of certain builtins
666
667//*************************************
668// Sort out namespaces for STL/No STL options.
670
671namespace etl
672{
673 namespace traits
674 {
675 // Documentation: https://www.etlcpp.com/etl_traits.html
676 // General
677 static ETL_CONSTANT long cplusplus = __cplusplus;
678 static ETL_CONSTANT int language_standard = ETL_LANGUAGE_STANDARD;
679
680 // Using...
681 static ETL_CONSTANT bool using_stl = (ETL_USING_STL == 1);
682 static ETL_CONSTANT bool using_stlport = (ETL_USING_STLPORT == 1);
683 static ETL_CONSTANT bool using_cpp11 = (ETL_USING_CPP11 == 1);
684 static ETL_CONSTANT bool using_cpp14 = (ETL_USING_CPP14 == 1);
685 static ETL_CONSTANT bool using_cpp17 = (ETL_USING_CPP17 == 1);
686 static ETL_CONSTANT bool using_cpp20 = (ETL_USING_CPP20 == 1);
687 static ETL_CONSTANT bool using_cpp23 = (ETL_USING_CPP23 == 1);
688 static ETL_CONSTANT bool using_cpp26 = (ETL_USING_CPP26 == 1);
689 static ETL_CONSTANT bool using_gcc_compiler = (ETL_USING_GCC_COMPILER == 1);
690 static ETL_CONSTANT bool using_microsoft_compiler = (ETL_USING_MICROSOFT_COMPILER == 1);
691 static ETL_CONSTANT bool using_arm5_compiler = (ETL_USING_ARM5_COMPILER == 1);
692 static ETL_CONSTANT bool using_arm6_compiler = (ETL_USING_ARM6_COMPILER == 1);
693 static ETL_CONSTANT bool using_arm7_compiler = (ETL_USING_ARM7_COMPILER == 1);
694 static ETL_CONSTANT bool using_clang_compiler = (ETL_USING_CLANG_COMPILER == 1);
695 static ETL_CONSTANT bool using_green_hills_compiler = (ETL_USING_GREEN_HILLS_COMPILER == 1);
696 static ETL_CONSTANT bool using_iar_compiler = (ETL_USING_IAR_COMPILER == 1);
697 static ETL_CONSTANT bool using_intel_compiler = (ETL_USING_INTEL_COMPILER == 1);
698 static ETL_CONSTANT bool using_texas_instruments_compiler = (ETL_USING_TEXAS_INSTRUMENTS_COMPILER == 1);
699 static ETL_CONSTANT bool using_generic_compiler = (ETL_USING_GENERIC_COMPILER == 1);
700 static ETL_CONSTANT bool using_legacy_bitset = (ETL_USING_LEGACY_BITSET == 1);
701 static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1);
702 static ETL_CONSTANT bool using_libc_wchar_h = (ETL_USING_LIBC_WCHAR_H == 1);
703 static ETL_CONSTANT bool using_std_exception = (ETL_USING_STD_EXCEPTION == 1);
704 static ETL_CONSTANT bool using_format_floating_point = (ETL_USING_FORMAT_FLOATING_POINT == 1);
705
706 // Has...
707 static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1);
708 static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1);
709 static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1);
710 static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1);
711 static ETL_CONSTANT bool has_atomic_always_lock_free = (ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE == 1);
712 static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1);
713 static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1);
714 static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1);
715 static ETL_CONSTANT bool has_native_char16_t = (ETL_HAS_NATIVE_CHAR16_T == 1);
716 static ETL_CONSTANT bool has_native_char32_t = (ETL_HAS_NATIVE_CHAR32_T == 1);
717 static ETL_CONSTANT bool has_string_truncation_checks = (ETL_HAS_STRING_TRUNCATION_CHECKS == 1);
718 static ETL_CONSTANT bool has_error_on_string_truncation = (ETL_HAS_ERROR_ON_STRING_TRUNCATION == 1);
719 static ETL_CONSTANT bool has_string_clear_after_use = (ETL_HAS_STRING_CLEAR_AFTER_USE == 1);
720 static ETL_CONSTANT bool has_istring_repair = (ETL_HAS_ISTRING_REPAIR == 1);
721 static ETL_CONSTANT bool has_ivector_repair = (ETL_HAS_IVECTOR_REPAIR == 1);
722 static ETL_CONSTANT bool has_icircular_buffer_repair = (ETL_HAS_ICIRCULAR_BUFFER_REPAIR == 1);
723 static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1);
724 static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1);
725 static ETL_CONSTANT bool has_virtual_messages = (ETL_HAS_VIRTUAL_MESSAGES == 1);
726 static ETL_CONSTANT bool has_packed = (ETL_HAS_PACKED == 1);
727 static ETL_CONSTANT bool has_chrono_literals_day = (ETL_HAS_CHRONO_LITERALS_DAY == 1);
728 static ETL_CONSTANT bool has_chrono_literals_year = (ETL_HAS_CHRONO_LITERALS_YEAR == 1);
729 static ETL_CONSTANT bool has_chrono_literals_hours = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
730 static ETL_CONSTANT bool has_chrono_literals_minutes = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
731 static ETL_CONSTANT bool has_chrono_literals_seconds = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
732 static ETL_CONSTANT bool has_chrono_literals_milliseconds = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
733 static ETL_CONSTANT bool has_chrono_literals_microseconds = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
734 static ETL_CONSTANT bool has_chrono_literals_nanoseconds = (ETL_HAS_CHRONO_LITERALS_DURATION == 1);
735 static ETL_CONSTANT bool has_std_byteswap = (ETL_HAS_STD_BYTESWAP == 1);
736 static ETL_CONSTANT bool has_std_is_virtual_base_of = (ETL_HAS_STD_IS_VIRTUAL_BASE_OF == 1);
737 static ETL_CONSTANT bool has_std_trivially_relocatable = (ETL_HAS_STD_TRIVIALLY_RELOCATABLE == 1);
738 static ETL_CONSTANT bool has_std_atomic_min_max = (ETL_HAS_STD_ATOMIC_MIN_MAX == 1);
739 static ETL_CONSTANT bool has_noexcept_function_type = (ETL_HAS_NOEXCEPT_FUNCTION_TYPE == 1);
740
741 // Is...
742 static ETL_CONSTANT bool is_debug_build = (ETL_IS_DEBUG_BUILD == 1);
743 } // namespace traits
744} // namespace etl
745
746#endif
Definition absolute.h:40