update ArxTypeTraits

master
Hideaki Tai 4 years ago
parent 4d7678dd9b
commit 532bcf9fbb

@ -15,12 +15,12 @@ namespace std { }
// Import everything from the std namespace into arx::std, so that // Import everything from the std namespace into arx::std, so that
// anything we import rather than define is also available through // 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 // 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 // (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 to reference the C++11 stuff from the system headers.
namespace arx { namespace arx {
namespace arx_std { namespace stdx {
using namespace ::std; using namespace ::std;
} }
} }
@ -30,9 +30,9 @@ namespace arx {
// the standard library version if it is available, falling back to arx // the standard library version if it is available, falling back to arx
// versions for things not supplied by the standard library. Only when // versions for things not supplied by the standard library. Only when
// you really need the arx version (e.g. for constexpr numeric_limits // 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 { namespace std {
using namespace ::arx::arx_std; using namespace ::arx::stdx;
} }
#include "ArxTypeTraits/replace_minmax_macros.h" #include "ArxTypeTraits/replace_minmax_macros.h"

@ -28,7 +28,7 @@
inline void* operator new (const size_t size, void* ptr) noexcept { (void)size; return ptr; } inline void* operator new (const size_t size, void* ptr) noexcept { (void)size; return ptr; }
#endif #endif
namespace arx { namespace arx_std { namespace arx { namespace stdx {
// reference: // reference:
// stack overflow https://stackoverflow.com/questions/32074410/stdfunction-bind-like-type-erasure-without-standard-c-library // stack overflow https://stackoverflow.com/questions/32074410/stdfunction-bind-like-type-erasure-without-standard-c-library

@ -17,7 +17,8 @@
#define ARX_SYSTEM_HAS_INCLUDE(x) 1 #define ARX_SYSTEM_HAS_INCLUDE(x) 1
#elif defined(ARDUINO_SAM_DUE) #elif defined(ARDUINO_SAM_DUE)
// Arduino DUE's GCC version is 4.8.3 (GCC < 5.0). // 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 #define ARX_SYSTEM_HAS_INCLUDE(x) 0
#else #else
#error "Compiler does not support __has_include, please report a bug against the ArxTypeTraits library about this." #error "Compiler does not support __has_include, please report a bug against the ArxTypeTraits library about this."

@ -9,7 +9,7 @@
#else // Do not have libstdc++11 #else // Do not have libstdc++11
namespace arx { namespace arx_std { namespace arx { namespace stdx {
// https://theolizer.com/cpp-school2/cpp-school2-15/ // https://theolizer.com/cpp-school2/cpp-school2-15/
// https://wandbox.org/permlink/C0BWIzjqg4iO3kKZ // https://wandbox.org/permlink/C0BWIzjqg4iO3kKZ

@ -9,7 +9,7 @@
#else // Do not have libstdc++98 #else // Do not have libstdc++98
namespace arx { namespace arx_std { namespace arx { namespace stdx {
template <class T> template <class T>
void swap(T& a, T& b) void swap(T& a, T& b)
@ -18,7 +18,7 @@ namespace arx { namespace arx_std {
a = move(b); a = move(b);
b = move(t); b = move(t);
} }
} } // namespace arx::arx_std } } // namespace arx::stdx
#endif // Do not have libstdc++98 #endif // Do not have libstdc++98
@ -34,7 +34,7 @@ namespace arx { namespace arx_std {
#include <limits.h> #include <limits.h>
#include <stdint.h> #include <stdint.h>
namespace arx { namespace arx_std { namespace arx { namespace stdx {
using nullptr_t = decltype(nullptr); using nullptr_t = decltype(nullptr);
@ -145,10 +145,6 @@ namespace arx { namespace arx_std {
template<class T, size_t N> struct remove_extent<T[N]> { typedef T type; }; template<class T, size_t N> struct remove_extent<T[N]> { typedef T type; };
template<class T>
T&& move(T& t){ return static_cast<T&&>(t); }
template <class T> template <class T>
constexpr T&& forward(typename remove_reference<T>::type& t) noexcept constexpr T&& forward(typename remove_reference<T>::type& t) noexcept
{ {
@ -381,10 +377,31 @@ namespace arx { namespace arx_std {
template<class Sig> template<class Sig>
using result_of = details::result_of<Sig>; using result_of = details::result_of<Sig>;
} } // namespace arx::arx_std } } // namespace arx::stdx
#endif // Do not have libstdc++11 #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 <class T>
constexpr typename remove_reference<T>::type&& move(T&& t) noexcept
{
return static_cast<typename remove_reference<T>::type&&>(t);
}
} } // namespace arx::stdx
#endif // Do not have libstdc++14
#include "initializer_list.h" #include "initializer_list.h"
#include "tuple.h" #include "tuple.h"
#include "functional.h" #include "functional.h"
@ -394,7 +411,7 @@ namespace arx { namespace arx_std {
// for C++11 above. // for C++11 above.
#else // Do not have libstdc++14 #else // Do not have libstdc++14
namespace arx { namespace arx_std { namespace arx { namespace stdx {
template <bool B, typename T = void> template <bool B, typename T = void>
using enable_if_t = typename enable_if<B, T>::type; using enable_if_t = typename enable_if<B, T>::type;
@ -448,7 +465,7 @@ namespace arx { namespace arx_std {
template<typename... Ts> template<typename... Ts>
using index_sequence_for = make_index_sequence<sizeof...(Ts)>; using index_sequence_for = make_index_sequence<sizeof...(Ts)>;
} } // namespace arx::arx_std } } // namespace arx::stdx
#endif // Do not have libstdc++14 #endif // Do not have libstdc++14
@ -458,7 +475,7 @@ namespace arx { namespace arx_std {
// for C++11 above. // for C++11 above.
#else // Do not have libstdc++17 #else // Do not have libstdc++17
namespace arx { namespace arx_std { namespace arx { namespace stdx {
template <class... Ts> template <class... Ts>
struct Tester { using type = void; }; 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 #endif // Do not have libstdc++17
@ -516,7 +533,7 @@ namespace arx { namespace arx_std {
// for C++11 above. // for C++11 above.
#else // Do not have libstdc++2a #else // Do not have libstdc++2a
namespace arx { namespace arx_std { namespace arx { namespace stdx {
template<class T> template<class T>
struct remove_cvref struct remove_cvref
@ -527,7 +544,7 @@ namespace arx { namespace arx_std {
template< class T > template< class T >
using remove_cvref_t = typename remove_cvref<T>::type; using remove_cvref_t = typename remove_cvref<T>::type;
} } // namespace arx::arx_std } } // namespace arx::stdx
#endif // Do not have libstdc++2a #endif // Do not have libstdc++2a

@ -8,13 +8,13 @@ C++ type_traits for Arduino which cannot use it as default
- automatically use standard library first if the boards can - 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 - 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) - 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 - thx @matthijskooijman
## Supported Class Templates ## 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::integral_constant`
- `std::true_type` - `std::true_type`
@ -102,6 +102,7 @@ C++ type_traits for Arduino which cannot use it as default
- [PollingTimer](https://github.com/hideakitai/PollingTimer) - [PollingTimer](https://github.com/hideakitai/PollingTimer)
- [Tween](https://github.com/hideakitai/Tween) - [Tween](https://github.com/hideakitai/Tween)
- [ArxStringUtils](https://github.com/hideakitai/ArxStringUtils) - [ArxStringUtils](https://github.com/hideakitai/ArxStringUtils)
- [Filters](https://github.com/hideakitai/Filters)
## Contributors ## Contributors

Loading…
Cancel
Save