From bce8ef3ed0e168ba7f43f570b07634bc248917c7 Mon Sep 17 00:00:00 2001 From: Adam Demuri Date: Sat, 8 Feb 2020 11:12:07 -0700 Subject: [PATCH] Implement std::is_integral I tested that this compiles for Arduino UNO, including vectors with integral and non-integral types. --- src/type_traits | 115 +++++++++++++++++++++++++----------------------- src/vector | 6 +-- 2 files changed, 63 insertions(+), 58 deletions(-) diff --git a/src/type_traits b/src/type_traits index fa1de40c..885cbfa7 100644 --- a/src/type_traits +++ b/src/type_traits @@ -28,61 +28,66 @@ #pragma GCC visibility push(default) namespace std{ - - struct _UCXXEXPORT __true_type{}; - struct _UCXXEXPORT __false_type{}; - - template class _UCXXEXPORT __is_integer{ - public: - typedef __false_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - template <> class _UCXXEXPORT __is_integer { - public: - typedef __true_type value; - }; - - + template + struct integral_constant + { + static constexpr _Tp value = __v; + typedef _Tp value_type; + typedef integral_constant<_Tp, __v> type; + constexpr operator value_type() const { return value; } + }; + + template + constexpr _Tp integral_constant<_Tp, __v>::value; + + typedef integral_constant true_type; + + typedef integral_constant false_type; + + template + class _UCXXEXPORT __is_integral_helper + : public false_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template <> + class _UCXXEXPORT __is_integral_helper + : public true_type { }; + + template + struct is_integral + : public __is_integral_helper<_Tp>::type + { }; } diff --git a/src/vector b/src/vector index 1c113e37..7fd38e2c 100644 --- a/src/vector +++ b/src/vector @@ -292,13 +292,13 @@ namespace std{ } template - inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __true_type) + inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, true_type) { _insert_fill(position, first, last); } template - inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, __false_type) + inline void _dispatch_insert(iterator position, InputIterator first, InputIterator last, false_type) { _insert_from_iterator(position, first, last); } @@ -308,7 +308,7 @@ namespace std{ } template inline void insert(iterator position, InputIterator first, InputIterator last){ - typedef typename __is_integer::value __some_type; + typedef typename is_integral::value __some_type; _dispatch_insert(position, first, last, __some_type()); }