From 532bcf9fbb6822dfba7c4c53b705e13572cd333d Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Wed, 30 Sep 2020 16:07:16 +0900 Subject: [PATCH] update ArxTypeTraits --- util/ArxTypeTraits/ArxTypeTraits.h | 8 ++-- util/ArxTypeTraits/ArxTypeTraits/functional.h | 2 +- .../ArxTypeTraits/ArxTypeTraits/has_include.h | 3 +- util/ArxTypeTraits/ArxTypeTraits/tuple.h | 2 +- .../ArxTypeTraits/ArxTypeTraits/type_traits.h | 45 +++++++++++++------ util/ArxTypeTraits/README.md | 5 ++- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/util/ArxTypeTraits/ArxTypeTraits.h b/util/ArxTypeTraits/ArxTypeTraits.h index 77b4d73..b0adb68 100644 --- a/util/ArxTypeTraits/ArxTypeTraits.h +++ b/util/ArxTypeTraits/ArxTypeTraits.h @@ -15,12 +15,12 @@ namespace std { } // Import everything from the std namespace into arx::std, so that // anything we import rather than define is also available through -// arx::arx_std. +// arx::stdx. // This includes everything yet to be defined, so we can do this early // (and must do so, to allow e.g. the C++14 additions in the arx::std // namespace to reference the C++11 stuff from the system headers. namespace arx { - namespace arx_std { + namespace stdx { using namespace ::std; } } @@ -30,9 +30,9 @@ namespace arx { // the standard library version if it is available, falling back to arx // versions for things not supplied by the standard library. Only when // you really need the arx version (e.g. for constexpr numeric_limits -// when also using ArduinoSTL), you need to qualify with arx::arx_std:: +// when also using ArduinoSTL), you need to qualify with arx::stdx:: namespace std { - using namespace ::arx::arx_std; + using namespace ::arx::stdx; } #include "ArxTypeTraits/replace_minmax_macros.h" diff --git a/util/ArxTypeTraits/ArxTypeTraits/functional.h b/util/ArxTypeTraits/ArxTypeTraits/functional.h index 06208de..ed25943 100644 --- a/util/ArxTypeTraits/ArxTypeTraits/functional.h +++ b/util/ArxTypeTraits/ArxTypeTraits/functional.h @@ -28,7 +28,7 @@ inline void* operator new (const size_t size, void* ptr) noexcept { (void)size; return ptr; } #endif -namespace arx { namespace arx_std { +namespace arx { namespace stdx { // reference: // stack overflow https://stackoverflow.com/questions/32074410/stdfunction-bind-like-type-erasure-without-standard-c-library diff --git a/util/ArxTypeTraits/ArxTypeTraits/has_include.h b/util/ArxTypeTraits/ArxTypeTraits/has_include.h index 76b39a9..d605d71 100644 --- a/util/ArxTypeTraits/ArxTypeTraits/has_include.h +++ b/util/ArxTypeTraits/ArxTypeTraits/has_include.h @@ -17,7 +17,8 @@ #define ARX_SYSTEM_HAS_INCLUDE(x) 1 #elif defined(ARDUINO_SAM_DUE) // Arduino DUE's GCC version is 4.8.3 (GCC < 5.0). - // And it has not libstdc++ + // If libstdc++ is used, std::function causes error + // so currently we disable libstdc++ and use ArxTypeTraits #define ARX_SYSTEM_HAS_INCLUDE(x) 0 #else #error "Compiler does not support __has_include, please report a bug against the ArxTypeTraits library about this." diff --git a/util/ArxTypeTraits/ArxTypeTraits/tuple.h b/util/ArxTypeTraits/ArxTypeTraits/tuple.h index 1489533..2c13d95 100644 --- a/util/ArxTypeTraits/ArxTypeTraits/tuple.h +++ b/util/ArxTypeTraits/ArxTypeTraits/tuple.h @@ -9,7 +9,7 @@ #else // Do not have libstdc++11 -namespace arx { namespace arx_std { +namespace arx { namespace stdx { // https://theolizer.com/cpp-school2/cpp-school2-15/ // https://wandbox.org/permlink/C0BWIzjqg4iO3kKZ diff --git a/util/ArxTypeTraits/ArxTypeTraits/type_traits.h b/util/ArxTypeTraits/ArxTypeTraits/type_traits.h index 7475830..a24c946 100644 --- a/util/ArxTypeTraits/ArxTypeTraits/type_traits.h +++ b/util/ArxTypeTraits/ArxTypeTraits/type_traits.h @@ -9,7 +9,7 @@ #else // Do not have libstdc++98 -namespace arx { namespace arx_std { +namespace arx { namespace stdx { template void swap(T& a, T& b) @@ -18,7 +18,7 @@ namespace arx { namespace arx_std { a = move(b); b = move(t); } -} } // namespace arx::arx_std +} } // namespace arx::stdx #endif // Do not have libstdc++98 @@ -34,7 +34,7 @@ namespace arx { namespace arx_std { #include #include -namespace arx { namespace arx_std { +namespace arx { namespace stdx { using nullptr_t = decltype(nullptr); @@ -145,10 +145,6 @@ namespace arx { namespace arx_std { template struct remove_extent { typedef T type; }; - template - T&& move(T& t){ return static_cast(t); } - - template constexpr T&& forward(typename remove_reference::type& t) noexcept { @@ -381,10 +377,31 @@ namespace arx { namespace arx_std { template using result_of = details::result_of; -} } // namespace arx::arx_std +} } // namespace arx::stdx #endif // Do not have libstdc++11 + +#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201402L // Have libstdc++14 + +#else // Do not have libstdc++14 + +namespace arx { namespace stdx { + + // `move` must be declared before including `functional.h` + // C++14 constexpr version should be inside of C++14, + // but moved before `functional.h` + template + constexpr typename remove_reference::type&& move(T&& t) noexcept + { + return static_cast::type&&>(t); + } + +} } // namespace arx::stdx + +#endif // Do not have libstdc++14 + + #include "initializer_list.h" #include "tuple.h" #include "functional.h" @@ -394,7 +411,7 @@ namespace arx { namespace arx_std { // for C++11 above. #else // Do not have libstdc++14 -namespace arx { namespace arx_std { +namespace arx { namespace stdx { template using enable_if_t = typename enable_if::type; @@ -448,7 +465,7 @@ namespace arx { namespace arx_std { template using index_sequence_for = make_index_sequence; -} } // namespace arx::arx_std +} } // namespace arx::stdx #endif // Do not have libstdc++14 @@ -458,7 +475,7 @@ namespace arx { namespace arx_std { // for C++11 above. #else // Do not have libstdc++17 -namespace arx { namespace arx_std { +namespace arx { namespace stdx { template struct Tester { using type = void; }; @@ -506,7 +523,7 @@ namespace arx { namespace arx_std { ); } -} } // namespace arx::arx_std +} } // namespace arx::stdx #endif // Do not have libstdc++17 @@ -516,7 +533,7 @@ namespace arx { namespace arx_std { // for C++11 above. #else // Do not have libstdc++2a -namespace arx { namespace arx_std { +namespace arx { namespace stdx { template struct remove_cvref @@ -527,7 +544,7 @@ namespace arx { namespace arx_std { template< class T > using remove_cvref_t = typename remove_cvref::type; -} } // namespace arx::arx_std +} } // namespace arx::stdx #endif // Do not have libstdc++2a diff --git a/util/ArxTypeTraits/README.md b/util/ArxTypeTraits/README.md index db6f74a..a36ee61 100644 --- a/util/ArxTypeTraits/README.md +++ b/util/ArxTypeTraits/README.md @@ -8,13 +8,13 @@ C++ type_traits for Arduino which cannot use it as default - automatically use standard library first if the boards can - if standard library is not enough (e.g. only C++11 is available), add missing parts listed below - works almost all Arduino platforms (Let me know if you have errors) -- compatible with [ArduinoSTL](https://github.com/mike-matera/ArduinoSTL) or other [uClibc++](https://www.uclibc.org/) libraries (include them before `ArxTypeTraits`) +- compatible with [ArduinoSTL](https://github.com/mike-matera/ArduinoSTL) or other [uClibc++](https://www.uclibc.org/) libraries - thx @matthijskooijman ## Supported Class Templates -### C++11 (defined only for platforms above which cannot use `type_traits`) +### C++11 (defined only for boards before C++11) - `std::integral_constant` - `std::true_type` @@ -102,6 +102,7 @@ C++ type_traits for Arduino which cannot use it as default - [PollingTimer](https://github.com/hideakitai/PollingTimer) - [Tween](https://github.com/hideakitai/Tween) - [ArxStringUtils](https://github.com/hideakitai/ArxStringUtils) +- [Filters](https://github.com/hideakitai/Filters) ## Contributors