diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 67917e26..a45f66cd 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -36,11 +36,11 @@ SOFTWARE. /// Additional new variants of certain algorithms. ///\ingroup utilities -#include -#include -#include -#include -#include +#include "stl/algorithm.h" +#include "stl/utility.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include #include "platform.h" @@ -1113,6 +1113,39 @@ namespace etl return std::pair(destination_true, destination_false); } + + //*************************************************************************** + /// Sorts the elements using shell sort. + /// Uses users defined comparison. + ///\ingroup algorithm + //*************************************************************************** + template ::value_type> > + void sort(TIterator first, TIterator last, TCompare compare = TCompare()) + { + typedef typename std::iterator_traits::difference_type difference_t; + + difference_t n = std::distance(first, last); + + for (difference_t i = n / 2; i > 0; i /= 2) + { + for (difference_t j = i; j < n; ++j) + { + for (difference_t k = j - i; k >= 0; k -= i) + { + TIterator itr1 = first; + TIterator itr2 = first; + + std::advance(itr1, k); + std::advance(itr2, k + i); + + if (compare(*itr2, *itr1)) + { + std::iter_swap(itr1, itr2); + } + } + } + } + } } #endif diff --git a/include/etl/array.h b/include/etl/array.h index 05393422..2c0e854d 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -31,12 +31,14 @@ SOFTWARE. #ifndef ETL_ARRAY_INCLUDED #define ETL_ARRAY_INCLUDED -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "exception.h" #include "type_traits.h" #include "parameter_type.h" @@ -97,8 +99,8 @@ namespace etl }; typedef T value_type; - typedef std::size_t size_type; - typedef std::ptrdiff_t difference_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; typedef T& reference; typedef const T& const_reference; typedef T* pointer; @@ -569,7 +571,7 @@ namespace etl ///\param rhs The second array. ///\return true if the arrays are equal, otherwise false //************************************************************************* - template + template bool operator ==(const etl::array& lhs, const etl::array& rhs) { return std::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin()); @@ -581,7 +583,7 @@ namespace etl ///\param rhs The second array. ///\return true if the arrays are not equal, otherwise false //************************************************************************* - template + template bool operator !=(const etl::array& lhs, const etl::array& rhs) { return !(lhs == rhs); @@ -593,7 +595,7 @@ namespace etl ///\param rhs The second array. ///\return true if the first array is lexicographically less than the second, otherwise false //************************************************************************* - template + template bool operator <(const etl::array& lhs, const etl::array& rhs) { return std::lexicographical_compare(lhs.cbegin(), @@ -608,7 +610,7 @@ namespace etl ///\param rhs The second array. ///\return true if the first array is lexicographically less than or equal to the second, otherwise false //************************************************************************* - template + template bool operator <=(const etl::array& lhs, const etl::array& rhs) { return !(lhs > rhs); @@ -619,7 +621,7 @@ namespace etl ///\param lhs The first array. ///\param rhs The second array. ///\return true if the first array is lexicographically greater than the second, otherwise false - template + template //************************************************************************* bool operator >(const etl::array& lhs, const etl::array& rhs) { @@ -632,7 +634,7 @@ namespace etl ///\param rhs The second array. ///\return true if the first array is lexicographically greater than or equal to the second, otherwise false //************************************************************************* - template + template bool operator >=(const etl::array& lhs, const etl::array& rhs) { return !(lhs < rhs); @@ -646,7 +648,7 @@ namespace etl ///\param a The array. ///\return A reference to the element //************************************************************************* - template + template inline T& get(array& a) { ETL_STATIC_ASSERT(I < MAXN, "Index out of bounds"); @@ -661,7 +663,7 @@ namespace etl ///\param a The array. ///\return A const reference to the element //************************************************************************* - template + template inline const T& get(const array& a) { ETL_STATIC_ASSERT(I < MAXN, "Index out of bounds"); diff --git a/include/etl/array_view.h b/include/etl/array_view.h index b56e21e5..ec46d96c 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -38,8 +38,9 @@ SOFTWARE. #include "exception.h" #include "nullptr.h" #include "hash.h" +#include "algorithm.h" -#include +#include "stl/algorithm.h" ///\defgroup array array /// A wrapper for arrays @@ -100,7 +101,7 @@ namespace etl public: typedef T value_type; - typedef std::size_t size_type; + typedef size_t size_type; typedef T& reference; typedef const T& const_reference; typedef T* pointer; @@ -494,7 +495,7 @@ namespace etl public: typedef T value_type; - typedef std::size_t size_type; + typedef size_t size_type; typedef const T& const_reference; typedef const T* const_pointer; typedef const T* const_iterator; diff --git a/include/etl/array_wrapper.h b/include/etl/array_wrapper.h index ec840350..caf73404 100644 --- a/include/etl/array_wrapper.h +++ b/include/etl/array_wrapper.h @@ -39,7 +39,7 @@ SOFTWARE. #include "container.h" #include "parameter_type.h" -#include +#include "algorithm.h" ///\defgroup array array /// A wrapper for arrays @@ -80,13 +80,13 @@ namespace etl //*************************************************************************** /// Array wrapper. //*************************************************************************** - template + template class array_wrapper { public: typedef T value_type; - typedef std::size_t size_type; + typedef size_t size_type; typedef T& reference; typedef const T& const_reference; typedef T* pointer; @@ -330,7 +330,7 @@ namespace etl //************************************************************************* /// Equality for array wrappers. //************************************************************************* - template + template bool operator == (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -340,7 +340,7 @@ namespace etl //************************************************************************* /// Inequality for array wrapper. //************************************************************************* - template + template bool operator != (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -350,7 +350,7 @@ namespace etl //************************************************************************* /// Less-than for array wrapper. //************************************************************************* - template + template bool operator < (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -360,7 +360,7 @@ namespace etl //************************************************************************* /// Greater-than for array wrapper. //************************************************************************* - template + template bool operator > (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -370,7 +370,7 @@ namespace etl //************************************************************************* /// Less-than-equal for array wrapper. //************************************************************************* - template + template bool operator <= (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -380,7 +380,7 @@ namespace etl //************************************************************************* /// Greater-than-equal for array wrapper. //************************************************************************* - template + template bool operator >= (const etl::array_wrapper& lhs, const etl::array_wrapper& rhs) { @@ -391,7 +391,7 @@ namespace etl /// Hash function. //************************************************************************* #if ETL_8BIT_SUPPORT - template + template struct hash > { size_t operator()(const etl::array_wrapper& aw) const @@ -406,7 +406,7 @@ namespace etl //************************************************************************* /// Swap. //************************************************************************* -template +template void swap(etl::array_wrapper& lhs, etl::array_wrapper& rhs) { diff --git a/include/etl/atomic.h b/include/etl/atomic.h index 166c3e0b..5d247356 100644 --- a/include/etl/atomic.h +++ b/include/etl/atomic.h @@ -31,7 +31,7 @@ SOFTWARE. #include "platform.h" -#if ETL_CPP11_SUPPORTED == 1 +#if ETL_CPP11_SUPPORTED == 1 && !defined(ETL_NO_STL) #include "atomic/atomic_std.h" #define ETL_HAS_ATOMIC 1 #elif defined(ETL_COMPILER_ARM) diff --git a/include/etl/atomic/atomic_gcc_sync.h b/include/etl/atomic/atomic_gcc_sync.h index 2bdcea49..d26005b2 100644 --- a/include/etl/atomic/atomic_gcc_sync.h +++ b/include/etl/atomic/atomic_gcc_sync.h @@ -507,23 +507,23 @@ namespace etl } // Add - T* operator +=(std::ptrdiff_t v) + T* operator +=(ptrdiff_t v) { return fetch_add(v) + v; } - T* operator +=(std::ptrdiff_t v) volatile + T* operator +=(ptrdiff_t v) volatile { return fetch_add(v) + v; } // Subtract - T* operator -=(std::ptrdiff_t v) + T* operator -=(ptrdiff_t v) { return fetch_sub(v) - v; } - T* operator -=(std::ptrdiff_t v) volatile + T* operator -=(ptrdiff_t v) volatile { return fetch_sub(v) - v; } @@ -573,23 +573,23 @@ namespace etl } // Fetch add - T* fetch_add(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) + T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) { return __sync_fetch_and_add(&value, v); } - T* fetch_add(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile + T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile { return __sync_fetch_and_add(&value, v); } // Fetch subtract - T* fetch_sub(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) + T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) { return __sync_fetch_and_sub(&value, v); } - T* fetch_sub(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile + T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile { return __sync_fetch_and_sub(&value, v); } diff --git a/include/etl/atomic/atomic_std.h b/include/etl/atomic/atomic_std.h index fe663ff1..eb3cd146 100644 --- a/include/etl/atomic/atomic_std.h +++ b/include/etl/atomic/atomic_std.h @@ -407,23 +407,23 @@ namespace etl } // Add - T* operator +=(std::ptrdiff_t v) + T* operator +=(ptrdiff_t v) { return value += v; } - T* operator +=(std::ptrdiff_t v) volatile + T* operator +=(ptrdiff_t v) volatile { return value += v; } // Subtract - T* operator -=(std::ptrdiff_t v) + T* operator -=(ptrdiff_t v) { return value -= v; } - T* operator -=(std::ptrdiff_t v) volatile + T* operator -=(ptrdiff_t v) volatile { return value -= v; } @@ -473,23 +473,23 @@ namespace etl } // Fetch add - T* fetch_add(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) + T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) { return value.fetch_add(v, order); } - T* fetch_add(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile + T* fetch_add(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile { return value.fetch_add(v, order); } // Fetch subtract - T* fetch_sub(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) + T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) { return value.fetch_sub(v, order); } - T* fetch_sub(std::ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile + T* fetch_sub(ptrdiff_t v, etl::memory_order order = etl::memory_order_seq_cst) volatile { return value.fetch_sub(v, order); } diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 17ee2480..b87f989b 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -33,12 +33,14 @@ SOFTWARE. #include #include -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "char_traits.h" #include "container.h" #include "alignment.h" diff --git a/include/etl/binary.h b/include/etl/binary.h index cf2a80ef..82bbbaeb 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -35,8 +35,6 @@ SOFTWARE. /// Binary utilities ///\ingroup utilities -#include - #include "platform.h" #include "type_traits.h" #include "integral_limits.h" @@ -47,6 +45,8 @@ SOFTWARE. #include "exception.h" #include "error_handler.h" +#include "stl/limits.h" + #undef ETL_FILE #define ETL_FILE "50" diff --git a/include/etl/bitset.h b/include/etl/bitset.h index ae328129..2b0b6abe 100644 --- a/include/etl/bitset.h +++ b/include/etl/bitset.h @@ -31,13 +31,15 @@ SOFTWARE. #ifndef ETL_BITSET_INCLUDED #define ETL_BITSET_INCLUDED -#include -#include #include #include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" + #include "integral_limits.h" #include "algorithm.h" #include "nullptr.h" diff --git a/include/etl/callback_timer.h b/include/etl/callback_timer.h index 3a829833..a57f9d5d 100644 --- a/include/etl/callback_timer.h +++ b/include/etl/callback_timer.h @@ -30,7 +30,7 @@ SOFTWARE. #define ETL_CALLBACK_TIMER_INCLUDED #include -#include +#include "algorithm.h" #include "platform.h" #include "nullptr.h" diff --git a/include/etl/char_traits.h b/include/etl/char_traits.h index 25ee662b..ef5d2e74 100644 --- a/include/etl/char_traits.h +++ b/include/etl/char_traits.h @@ -31,12 +31,13 @@ SOFTWARE. #ifndef ETL_CHAR_TRAITS_INCLUDED #define ETL_CHAR_TRAITS_INCLUDED -#include - #include "platform.h" #include "stdint.h" #include "algorithm.h" +#include "stl/algorithm.h" +#include "stl/iterator.h" + //***************************************************************************** ///\defgroup char_traits char_traits /// Character traits diff --git a/include/etl/compare.h b/include/etl/compare.h index fdf864ce..5550dfbf 100644 --- a/include/etl/compare.h +++ b/include/etl/compare.h @@ -31,11 +31,11 @@ SOFTWARE. #ifndef ETL_COMPARE_INCLUDED #define ETL_COMPARE_INCLUDED -#include - #include "platform.h" #include "parameter_type.h" +#include "stl/functional.h" + //***************************************************************************** ///\defgroup compare compare /// Comparisons only using less than operator diff --git a/include/etl/container.h b/include/etl/container.h index 51d66c30..c7cbfe3a 100644 --- a/include/etl/container.h +++ b/include/etl/container.h @@ -32,10 +32,11 @@ SOFTWARE. #define ETL_CONTAINER_INCLUDED #include -#include #include "platform.h" +#include "stl/iterator.h" + ///\defgroup container container ///\ingroup utilities diff --git a/include/etl/crc16.h b/include/etl/crc16.h index 1f535d1d..9fa21d8b 100644 --- a/include/etl/crc16.h +++ b/include/etl/crc16.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC16_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc16_ccitt.h b/include/etl/crc16_ccitt.h index 90ce365e..28ef7054 100644 --- a/include/etl/crc16_ccitt.h +++ b/include/etl/crc16_ccitt.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC16_CCITT_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc16_kermit.h b/include/etl/crc16_kermit.h index 4691c9ab..dffc6ed2 100644 --- a/include/etl/crc16_kermit.h +++ b/include/etl/crc16_kermit.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC16_KERMIT_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc32.h b/include/etl/crc32.h index 35af1545..8f78e429 100644 --- a/include/etl/crc32.h +++ b/include/etl/crc32.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC32_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc32_c.h b/include/etl/crc32_c.h index cd47c145..e24cf45c 100644 --- a/include/etl/crc32_c.h +++ b/include/etl/crc32_c.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC32_C_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc64_ecma.h b/include/etl/crc64_ecma.h index a1532ddc..98bc3c3b 100644 --- a/include/etl/crc64_ecma.h +++ b/include/etl/crc64_ecma.h @@ -32,11 +32,12 @@ SOFTWARE. #define ETL_CRC64_ECMA_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/crc8_ccitt.h b/include/etl/crc8_ccitt.h index 61c3a140..68853a14 100644 --- a/include/etl/crc8_ccitt.h +++ b/include/etl/crc8_ccitt.h @@ -32,11 +32,13 @@ SOFTWARE. #define ETL_CRC8_CCITT_INCLUDED #include -#include #include "platform.h" #include "frame_check_sequence.h" +#include "stl/algorithm.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/cstring.h b/include/etl/cstring.h index 567561e9..87ab5d5a 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -35,7 +35,7 @@ SOFTWARE. #include "basic_string.h" #include "hash.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -141,7 +141,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/cyclic_value.h b/include/etl/cyclic_value.h index 9df9efb6..e1fdd12d 100644 --- a/include/etl/cyclic_value.h +++ b/include/etl/cyclic_value.h @@ -37,14 +37,14 @@ SOFTWARE. /// Provides a value that cycles between two limits. /// \ingroup utilities -#include - #include "platform.h" #include "static_assert.h" #include "exception.h" #include "static_assert.h" #include "type_traits.h" +#include "stl/algorithm.h" + namespace etl { //*************************************************************************** diff --git a/include/etl/deque.h b/include/etl/deque.h index ccccff02..a9ed9301 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -33,10 +33,12 @@ SOFTWARE. #include #include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" + #include "container.h" #include "alignment.h" #include "array.h" @@ -48,7 +50,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -2066,7 +2068,7 @@ namespace etl this->assign(n, value); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/fixed_iterator.h b/include/etl/fixed_iterator.h index c981320b..e756b734 100644 --- a/include/etl/fixed_iterator.h +++ b/include/etl/fixed_iterator.h @@ -31,10 +31,10 @@ SOFTWARE. #ifndef ETL_FIXED_ITERATOR_INCLUDED #define ETL_FIXED_ITERATOR_INCLUDED -#include - #include "platform.h" +#include "stl/iterator.h" + ///\defgroup iterator Iterator types namespace etl diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index d12f1f0e..d2c78810 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_map.h" #include "pool.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -854,7 +854,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index 1545eeea..e2b9a8c4 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_multimap.h" #include "pool.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -735,7 +735,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 5858c211..023a526a 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_multiset.h" #include "pool.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -694,7 +694,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index ab6a4cd2..d4dd28c0 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_set.h" #include "pool.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -760,7 +760,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 619547a1..35d3a2d4 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -31,12 +31,14 @@ SOFTWARE. #ifndef ETL_FORWARD_LIST_INCLUDED #define ETL_FORWARD_LIST_INCLUDED -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "pool.h" #include "container.h" #include "exception.h" @@ -46,7 +48,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1415,7 +1417,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/ihash.h b/include/etl/ihash.h index e0ccf2b5..8d47a8e1 100644 --- a/include/etl/ihash.h +++ b/include/etl/ihash.h @@ -32,9 +32,11 @@ SOFTWARE. #define ETL_IHASH_INCLUDED #include -#include #include "platform.h" + +#include "stl/utility.h" + #include "exception.h" #include "error_handler.h" diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index bcc24ddd..3f6394c3 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -33,11 +33,12 @@ SOFTWARE. #include "platform.h" +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "private/minmax_push.h" -#include -#include -#include #include #include "platform.h" diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 65353e7b..5a04169f 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -32,7 +32,6 @@ SOFTWARE. #define ETL_INTRUSIVE_LINKS_INCLUDED #include -#include #include "platform.h" #include "nullptr.h" @@ -40,6 +39,8 @@ SOFTWARE. #include "exception.h" #include "error_handler.h" +#include "stl/utility.h" + #undef ETL_FILE #define ETL_FILE "22" diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6e4494d0..9c5c2ef0 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -35,9 +35,6 @@ SOFTWARE. #include "private/minmax_push.h" -#include -#include -#include #include #include "platform.h" @@ -49,6 +46,10 @@ SOFTWARE. #include "static_assert.h" #include "algorithm.h" +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #undef ETL_FILE #define ETL_FILE "21" diff --git a/include/etl/io_port.h b/include/etl/io_port.h index 053a1f78..3fc39d00 100644 --- a/include/etl/io_port.h +++ b/include/etl/io_port.h @@ -36,11 +36,12 @@ SOFTWARE. ///\ingroup utilities #include -#include #include "platform.h" #include "nullptr.h" +#include "stl/iterator.h" + namespace etl { //*************************************************************************** diff --git a/include/etl/iterator.h b/include/etl/iterator.h index 3e1e2a0b..b1ebb5cd 100644 --- a/include/etl/iterator.h +++ b/include/etl/iterator.h @@ -31,9 +31,10 @@ SOFTWARE. #ifndef ETL_ITERATOR_INCLUDED #define ETL_ITERATOR_INCLUDED -#include - #include "platform.h" + +#include "stl/iterator.h" + #include "type_traits.h" ///\defgroup iterator iterator diff --git a/include/etl/jenkins.h b/include/etl/jenkins.h index 7135b685..2217b775 100644 --- a/include/etl/jenkins.h +++ b/include/etl/jenkins.h @@ -32,7 +32,6 @@ SOFTWARE. #define ETL_JENKINS_INCLUDED #include -#include #include "platform.h" #include "static_assert.h" @@ -41,6 +40,8 @@ SOFTWARE. #include "ihash.h" #include "frame_check_sequence.h" +#include "stl/iterator.h" + #if defined(ETL_COMPILER_KEIL) #pragma diag_suppress 1300 #endif diff --git a/include/etl/list.h b/include/etl/list.h index 242ac520..a95e9f78 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -31,12 +31,14 @@ SOFTWARE. #ifndef ETL_LIST_INCLUDED #define ETL_LIST_INCLUDED -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "container.h" #include "pool.h" #include "exception.h" @@ -47,7 +49,7 @@ SOFTWARE. #include "parameter_type.h" #include "algorithm.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1655,7 +1657,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/map.h b/include/etl/map.h index de8d73a3..d1eb6d93 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -32,12 +32,13 @@ SOFTWARE. #define ETL_MAP_INCLUDED #include -#include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "container.h" #include "pool.h" #include "exception.h" @@ -47,7 +48,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -2063,7 +2064,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* diff --git a/include/etl/memory.h b/include/etl/memory.h index 941b841f..0d06a1f0 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -31,12 +31,13 @@ SOFTWARE. #ifndef ETL_MEMORY_INCLUDED #define ETL_MEMORY_INCLUDED -#include -#include +#include "algorithm.h" #include "platform.h" #include "type_traits.h" +#include "stl/iterator.h" + ///\defgroup memory memory ///\ingroup etl namespace etl diff --git a/include/etl/message_bus.h b/include/etl/message_bus.h index 25046dda..90d9b01f 100644 --- a/include/etl/message_bus.h +++ b/include/etl/message_bus.h @@ -30,7 +30,7 @@ SOFTWARE. #define ETL_MESSAGE_BUS_ #include -#include +#include "algorithm.h" #include "platform.h" #include "algorithm.h" diff --git a/include/etl/message_timer.h b/include/etl/message_timer.h index a6051396..1da2f363 100644 --- a/include/etl/message_timer.h +++ b/include/etl/message_timer.h @@ -30,7 +30,7 @@ SOFTWARE. #define ETL_MESSAGE_TIMER_INCLUDED #include -#include +#include "algorithm.h" #include "platform.h" #include "nullptr.h" diff --git a/include/etl/multimap.h b/include/etl/multimap.h index 2653eb88..b03dfdf6 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -32,11 +32,13 @@ SOFTWARE. #define ETL_MULTIMAP_INCLUDED #include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "container.h" #include "pool.h" #include "exception.h" @@ -46,7 +48,7 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1948,7 +1950,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 2cecb26b..5c2b23d9 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -32,11 +32,13 @@ SOFTWARE. #define ETL_MULTISET_INCLUDED #include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + #include "parameter_type.h" #include "container.h" #include "pool.h" @@ -46,7 +48,7 @@ SOFTWARE. #include "nullptr.h" #include "type_traits.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1928,7 +1930,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* diff --git a/include/etl/mutex.h b/include/etl/mutex.h index 0fb1ec10..4c0e1562 100644 --- a/include/etl/mutex.h +++ b/include/etl/mutex.h @@ -31,7 +31,7 @@ SOFTWARE. #include "platform.h" -#if ETL_CPP11_SUPPORTED == 1 +#if ETL_CPP11_SUPPORTED == 1 && !defined(ETL_NO_STL) #include "mutex/mutex_std.h" #define ETL_HAS_MUTEX 1 #elif defined(ETL_COMPILER_ARM) diff --git a/include/etl/observer.h b/include/etl/observer.h index 1cd9b3f0..06d07dfc 100644 --- a/include/etl/observer.h +++ b/include/etl/observer.h @@ -51,7 +51,7 @@ SOFTWARE. ///\ingroup patterns //***************************************************************************** -#include +#include "algorithm.h" #include "platform.h" #include "vector.h" diff --git a/include/etl/platform.h b/include/etl/platform.h index 655f78bb..0034c1cc 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -29,6 +29,7 @@ SOFTWARE. ******************************************************************************/ #include +#include #ifndef ETL_PLATFORM_INCLUDED #define ETL_PLATFORM_INCLUDED diff --git a/include/etl/pool.h b/include/etl/pool.h index 57ad5940..a79f04bf 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -32,6 +32,10 @@ SOFTWARE. #define ETL_POOL_INCLUDED #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" + #include "error_handler.h" #include "alignment.h" #include "array.h" @@ -40,9 +44,7 @@ SOFTWARE. #include "nullptr.h" #include "alignment.h" #include "static_assert.h" - -#include -#include +#include "algorithm.h" #undef ETL_FILE #define ETL_FILE "11" @@ -134,7 +136,7 @@ namespace etl return reinterpret_cast(allocate_item()); } -#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) +#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) || defined(ETL_NO_STL) //************************************************************************* /// Allocate storage for an object from the pool and create default. /// If asserts or exceptions are enabled and there are no more free items an @@ -499,7 +501,7 @@ namespace etl return ipool::allocate(); } -#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) +#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) || defined(ETL_NO_STL) //************************************************************************* /// Allocate storage for an object from the pool and create with default. /// If asserts or exceptions are enabled and there are no more free items an @@ -650,7 +652,7 @@ namespace etl return base_t::template allocate(); } -#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) +#if !ETL_CPP11_SUPPORTED || ETL_POOL_CPP03_CODE || defined(ETL_STLPORT) || defined(ETL_NO_STL) //************************************************************************* /// Allocate storage for an object from the pool and create with default. /// If asserts or exceptions are enabled and there are no more free items an diff --git a/include/etl/priority_queue.h b/include/etl/priority_queue.h index 54bcd779..6e0474b3 100644 --- a/include/etl/priority_queue.h +++ b/include/etl/priority_queue.h @@ -32,10 +32,12 @@ SOFTWARE. #define ETL_PRIORITY_QUEUE_INCLUDED #include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/functional.h" + #include "container.h" #include "vector.h" #include "type_traits.h" diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index b6f8e61a..07692a61 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -33,9 +33,6 @@ SOFTWARE. #define ETL_IN_PVOIDVECTOR -#include -#include -#include #include #include "../platform.h" @@ -44,6 +41,9 @@ SOFTWARE. #include "../type_traits.h" #include "../error_handler.h" +#include "../stl/functional.h" +#include "../stl/iterator.h" + #ifdef ETL_COMPILER_GCC #pragma GCC diagnostic ignored "-Wunused-variable" #endif diff --git a/include/etl/profiles/arduino_arm.h b/include/etl/profiles/arduino_arm.h index ca43b901..70ba8b27 100644 --- a/include/etl/profiles/arduino_arm.h +++ b/include/etl/profiles/arduino_arm.h @@ -35,8 +35,6 @@ SOFTWARE. // Arduino //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_ARM #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GCC diff --git a/include/etl/profiles/armv5.h b/include/etl/profiles/armv5.h index cf9d601f..6d8f8746 100644 --- a/include/etl/profiles/armv5.h +++ b/include/etl/profiles/armv5.h @@ -35,8 +35,6 @@ SOFTWARE. // ARM Compiler Version 5 //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_ARM #define ETL_TARGET_OS_NONE #define ETL_COMPILER_ARM diff --git a/src/profiles/etl_profile.h b/include/etl/profiles/armv5_no_stl.h similarity index 61% rename from src/profiles/etl_profile.h rename to include/etl/profiles/armv5_no_stl.h index 45596b1a..d69fcbf6 100644 --- a/src/profiles/etl_profile.h +++ b/include/etl/profiles/armv5_no_stl.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2017 jwellbelove, scott-eddy +Copyright(c) 2018 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -27,34 +27,23 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef __ETL_PROFILE_H__ -#define __ETL_PROFILE_H__ -#ifdef PROFILE_MSVC - #include "msvc_x86.h" -#elif PROFILE_GCC_GENERIC - #include "gcc_generic.h" -#elif PROFILE_GCC_LINUX_X86 - #include "gcc_linux_x86.h" -#elif PROFILE_GCC_WINDOWS_X86 - #include "gcc_windows_x86.h" -#elif PROFILE_ARM_V5_GENERIC - #include "armv5.h" -#elif PROFILE_ARM_V6_GENERIC - #include "armv6.h" -#elif PROFILE_ARDUINO - #include "arduino_arm.h" -#elif PROFILE_TICC - #include "ticc.h" -#elif PROFILE_CPP03_GENERIC - #include "cpp03.h" -#elif PROFILE_CPP11_GENERIC - #include "cpp11.h" -#elif PROFILE_CPP14_GENERIC - #include "cpp14.h" -#elif PROFILE_CUSTOM - #include "custom_profile.h" -#else - #error Must provide a profile header file when buiding ETL. See https://www.etlcpp.com/setup.html -#endif -#endif // __ETL_PROFILE_H_ +#ifndef ETL_ARMV5_NO_STL_INCLUDED +#define ETL_ARMV5_NO_STL_INCLUDED + +//***************************************************************************** +// ARM Compiler Version 5 +//***************************************************************************** + +#define ETL_TARGET_DEVICE_ARM +#define ETL_TARGET_OS_NONE +#define ETL_COMPILER_ARM +#define ETL_CPP11_SUPPORTED 0 +#define ETL_CPP14_SUPPORTED 0 +#define ETL_CPP17_SUPPORTED 0 +#define ETL_NO_NULLPTR_SUPPORT 1 +#define ETL_NO_LARGE_CHAR_SUPPORT 1 +#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 +#define ETL_NO_STL + +#endif diff --git a/include/etl/profiles/armv6.h b/include/etl/profiles/armv6.h index 3cafec46..f8f59ad4 100644 --- a/include/etl/profiles/armv6.h +++ b/include/etl/profiles/armv6.h @@ -35,8 +35,6 @@ SOFTWARE. // ARM Compiler Version 6 //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_ARM #define ETL_TARGET_OS_NONE #define ETL_COMPILER_LLVM diff --git a/include/etl/profiles/armv6_no_stl.h b/include/etl/profiles/armv6_no_stl.h new file mode 100644 index 00000000..0c25c3c1 --- /dev/null +++ b/include/etl/profiles/armv6_no_stl.h @@ -0,0 +1,49 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_ARMV6_NO_STL_INCLUDED +#define ETL_ARMV6_NO_STL_INCLUDED + +//***************************************************************************** +// ARM Compiler Version 6 +//***************************************************************************** + +#define ETL_TARGET_DEVICE_ARM +#define ETL_TARGET_OS_NONE +#define ETL_COMPILER_LLVM +#define ETL_CPP11_SUPPORTED 1 +#define ETL_CPP14_SUPPORTED 0 +#define ETL_CPP17_SUPPORTED 0 +#define ETL_NO_NULLPTR_SUPPORT 0 +#define ETL_NO_LARGE_CHAR_SUPPORT 0 +#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 1 +#define ETL_NO_STL + +#endif diff --git a/include/etl/profiles/cpp03.h b/include/etl/profiles/cpp03.h index 79379628..391af458 100644 --- a/include/etl/profiles/cpp03.h +++ b/include/etl/profiles/cpp03.h @@ -35,8 +35,6 @@ SOFTWARE. // Generic C++03 //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GENERIC diff --git a/include/etl/profiles/cpp03_no_stl.h b/include/etl/profiles/cpp03_no_stl.h new file mode 100644 index 00000000..3a42a6a1 --- /dev/null +++ b/include/etl/profiles/cpp03_no_stl.h @@ -0,0 +1,49 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CPP03_NO_STL_INCLUDED +#define ETL_CPP03_NO_STL_INCLUDED + +//***************************************************************************** +// Generic C++03 +//***************************************************************************** + +#define ETL_TARGET_DEVICE_GENERIC +#define ETL_TARGET_OS_NONE +#define ETL_COMPILER_GENERIC +#define ETL_CPP11_SUPPORTED 0 +#define ETL_CPP14_SUPPORTED 0 +#define ETL_CPP17_SUPPORTED 0 +#define ETL_NO_NULLPTR_SUPPORT 1 +#define ETL_NO_LARGE_CHAR_SUPPORT 1 +#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 +#define ETL_NO_STL + +#endif diff --git a/include/etl/profiles/cpp11.h b/include/etl/profiles/cpp11.h index 3faaa1db..6487ecb3 100644 --- a/include/etl/profiles/cpp11.h +++ b/include/etl/profiles/cpp11.h @@ -35,8 +35,6 @@ SOFTWARE. // Generic C++11 //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GENERIC diff --git a/include/etl/profiles/cpp11_no_stl.h b/include/etl/profiles/cpp11_no_stl.h new file mode 100644 index 00000000..a7255134 --- /dev/null +++ b/include/etl/profiles/cpp11_no_stl.h @@ -0,0 +1,49 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CPP11_NO_STL_INCLUDED +#define ETL_CPP11_NO_STL_INCLUDED + +//***************************************************************************** +// Generic C++11 +//***************************************************************************** + +#define ETL_TARGET_DEVICE_GENERIC +#define ETL_TARGET_OS_NONE +#define ETL_COMPILER_GENERIC +#define ETL_CPP11_SUPPORTED 1 +#define ETL_CPP14_SUPPORTED 0 +#define ETL_CPP17_SUPPORTED 0 +#define ETL_NO_NULLPTR_SUPPORT 0 +#define ETL_NO_LARGE_CHAR_SUPPORT 0 +#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 +#define ETL_NO_STL + +#endif diff --git a/include/etl/profiles/cpp14.h b/include/etl/profiles/cpp14.h index 28bc9988..5f8bf7fd 100644 --- a/include/etl/profiles/cpp14.h +++ b/include/etl/profiles/cpp14.h @@ -35,8 +35,6 @@ SOFTWARE. // Generic C++14 //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GENERIC diff --git a/include/etl/profiles/cpp14_no_stl.h b/include/etl/profiles/cpp14_no_stl.h new file mode 100644 index 00000000..e92acf84 --- /dev/null +++ b/include/etl/profiles/cpp14_no_stl.h @@ -0,0 +1,49 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CPP14_NO_STL_INCLUDED +#define ETL_CPP14_NO_STL_INCLUDED + +//***************************************************************************** +// Generic C++14 +//***************************************************************************** + +#define ETL_TARGET_DEVICE_GENERIC +#define ETL_TARGET_OS_NONE +#define ETL_COMPILER_GENERIC +#define ETL_CPP11_SUPPORTED 1 +#define ETL_CPP14_SUPPORTED 1 +#define ETL_CPP17_SUPPORTED 0 +#define ETL_NO_NULLPTR_SUPPORT 0 +#define ETL_NO_LARGE_CHAR_SUPPORT 0 +#define ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED 0 +#define ETL_NO_STL + +#endif diff --git a/include/etl/profiles/gcc_generic.h b/include/etl/profiles/gcc_generic.h index 68a54123..39826014 100644 --- a/include/etl/profiles/gcc_generic.h +++ b/include/etl/profiles/gcc_generic.h @@ -28,15 +28,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_GCC_INCLUDED -#define ETL_GCC_INCLUDED +#ifndef ETL_GCC_GENERIC_INCLUDED +#define ETL_GCC_GENERIC_INCLUDED //***************************************************************************** // GCC //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GCC diff --git a/include/etl/profiles/gcc_linux_x86.h b/include/etl/profiles/gcc_linux_x86.h index 2435658a..c9a3c9cc 100644 --- a/include/etl/profiles/gcc_linux_x86.h +++ b/include/etl/profiles/gcc_linux_x86.h @@ -28,15 +28,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_GCC_INCLUDED -#define ETL_GCC_INCLUDED +#ifndef ETL_GCC_LINUX_X86_INCLUDED +#define ETL_GCC_LINUX_X86_INCLUDED //***************************************************************************** // GCC //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_X86 #define ETL_TARGET_OS_LINUX #define ETL_COMPILER_GCC diff --git a/include/etl/profiles/gcc_windows_x86.h b/include/etl/profiles/gcc_windows_x86.h index 5fa06f48..a5a83349 100644 --- a/include/etl/profiles/gcc_windows_x86.h +++ b/include/etl/profiles/gcc_windows_x86.h @@ -28,15 +28,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_GCC_INCLUDED -#define ETL_GCC_INCLUDED +#ifndef ETL_GCC_WINDOWS_X86_INCLUDED +#define ETL_GCC_WINDOWS_X86_INCLUDED //***************************************************************************** // GCC //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_X86 #define ETL_TARGET_OS_WINDOWS #define ETL_COMPILER_GCC diff --git a/include/etl/profiles/msvc_x86.h b/include/etl/profiles/msvc_x86.h index 37910922..d4286277 100644 --- a/include/etl/profiles/msvc_x86.h +++ b/include/etl/profiles/msvc_x86.h @@ -28,15 +28,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_MSVC_INCLUDED -#define ETL_MSVC_INCLUDED +#ifndef ETL_MSVC_X86_INCLUDED +#define ETL_MSVC_X86_INCLUDED //***************************************************************************** // Microsoft Visual Studio //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_X86 #define ETL_TARGET_OS_WINDOWS #define ETL_COMPILER_MICROSOFT diff --git a/include/etl/profiles/segger_gcc_stlport.h b/include/etl/profiles/segger_gcc_stlport.h index 095f4601..c626bb29 100644 --- a/include/etl/profiles/segger_gcc_stlport.h +++ b/include/etl/profiles/segger_gcc_stlport.h @@ -28,15 +28,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_GCC_INCLUDED -#define ETL_GCC_INCLUDED +#ifndef ETL_SEGGER_GCC_INCLUDED +#define ETL_SEGGER_GCC_INCLUDED //***************************************************************************** // GCC //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_GCC diff --git a/include/etl/profiles/ticc.h b/include/etl/profiles/ticc.h index 11a8b583..72489442 100644 --- a/include/etl/profiles/ticc.h +++ b/include/etl/profiles/ticc.h @@ -35,8 +35,6 @@ SOFTWARE. // Texas Instruments Code Composer //***************************************************************************** -#include - #define ETL_TARGET_DEVICE_GENERIC #define ETL_TARGET_OS_NONE #define ETL_COMPILER_TI diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 4a502e65..11f89c8f 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -31,13 +31,15 @@ SOFTWARE. #ifndef ETL_REFERENCE_FLAT_MULTISET_INCLUDED #define ETL_REFERENCE_FLAT_MULTISET_INCLUDED -#include -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "type_traits.h" #include "vector.h" #include "pool.h" diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index c7c866b8..bcb5a5df 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -31,13 +31,15 @@ SOFTWARE. #ifndef ETL_REFERENCE_FLAT_SET_INCLUDED #define ETL_REFERENCE_FLAT_SET_INCLUDED -#include -#include -#include -#include #include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "type_traits.h" #include "pool.h" #include "error_handler.h" diff --git a/include/etl/set.h b/include/etl/set.h index a6df4f39..31f0ff7d 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -32,9 +32,6 @@ SOFTWARE. #define ETL_SET_INCLUDED #include -#include -#include -#include #include "platform.h" #include "container.h" @@ -46,7 +43,11 @@ SOFTWARE. #include "type_traits.h" #include "parameter_type.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1986,7 +1987,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* diff --git a/include/etl/stack.h b/include/etl/stack.h index 497390df..e085a231 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -33,9 +33,11 @@ SOFTWARE. #include #include -#include #include "platform.h" + +#include "stl/algorithm.h" + #include "container.h" #include "alignment.h" #include "array.h" diff --git a/include/etl/stl/algorithm.h b/include/etl/stl/algorithm.h new file mode 100644 index 00000000..43c1aaa7 --- /dev/null +++ b/include/etl/stl/algorithm.h @@ -0,0 +1,42 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ALGORITHM_INCLUDED +#define ETL_STL_ALGORITHM_INCLUDED + +#include "../platform.h" + +#if defined(ETL_NO_STL) + #include "alternate/algorithm.h" +#else + #include +#endif + +#endif diff --git a/include/etl/stl/alternate/algorithm.h b/include/etl/stl/alternate/algorithm.h new file mode 100644 index 00000000..74291034 --- /dev/null +++ b/include/etl/stl/alternate/algorithm.h @@ -0,0 +1,626 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ALTERNATE_ALGORITHM_INCLUDED +#define ETL_STL_ALTERNATE_ALGORITHM_INCLUDED + +#include "../../platform.h" + +#include + +#include "../../type_traits.h" + +#include "iterator.h" +#include "functional.h" + +#if defined(ETL_IN_UNIT_TEST) +#define ETLSTD etlstd +namespace etlstd +#else +#define ETLSTD std +namespace std +#endif +{ + //*************************************************************************** + // distance + template + typename etl::enable_if::iterator_category, std::random_access_iterator_tag>::value, + typename std::iterator_traits::difference_type>::type + distance(TIterator first, TIterator last) + { + typename std::iterator_traits::difference_type count = 0; + + while (first != last) + { + ++count; + ++first; + } + + return count; + } + + template + typename etl::enable_if::iterator_category, std::random_access_iterator_tag>::value, + typename std::iterator_traits::difference_type>::type + distance(TIterator first, TIterator last) + { + return last - first; + } + + //*************************************************************************** + // advance + template + typename etl::enable_if::iterator_tag, std::random_access_iterator_tag>::value, void>::type + advance(TIterator itr, TDistance distance) + { + while (distance-- != 0) + { + ++itr; + } + } + + template + typename etl::enable_if::iterator_tag, std::random_access_iterator_tag>::value, void>::type + advance(TIterator itr, TDistance distance) + { + return itr += distance; + } + + //*************************************************************************** + // copy + // Pointer + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_pod::value_type>::value, TIterator2>::type + copy(TIterator1 sb, TIterator1 se, TIterator2 db) + { + typedef typename std::iterator_traits::value_type value_t; + + return TIterator2(memcpy(db, sb, sizeof(value_t) * (se - sb))); + } + + // Other iterator + template + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_pod::value_type>::value, TIterator2>::type + copy(TIterator1 sb, TIterator1 se, TIterator2 db) + { + while (sb != se) + { + *db++ = *sb++; + } + + return db; + } + + //*************************************************************************** + // copy_n + // Pointer + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_pod::value_type>::value, TIterator2>::type + copy_n(TIterator1 sb, TSize count, TIterator2 db) + { + typedef typename std::iterator_traits::value_type value_t; + + return TIterator2(memcpy(db, sb, sizeof(value_t) * count)); + } + + // Other iterator + template + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_pod::value_type>::value, TIterator2>::type + copy_n(TIterator1 sb, TSize count, TIterator2 db) + { + while (count != 0) + { + *db++ = *sb++; + --count; + } + + return db; + } + + //*************************************************************************** + // copy_backward + // Pointer + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_pod::value_type>::value, TIterator2>::type + copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + { + typedef typename std::iterator_traits::value_type value_t; + + const size_t length = (se - sb); + + return TIterator2(memmove(de - length, sb, sizeof(value_t) * length)); + } + + // Other iterator + template + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_pod::value_type>::value, TIterator2>::type + copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + { + while (se != sb) + { + *(--de) = *(--se); + } + + return de; + } + + //*************************************************************************** + // lower_bound + template + TIterator lower_bound(TIterator first, TIterator last, const TValue& value, TCompare compare) + { + typedef typename std::iterator_traits::difference_type difference_t; + + difference_t count = std::distance(first, last); + + while (count > 0) + { + TIterator itr = first; + difference_t step = count / 2; + + std::advance(itr, step); + + if (compare(*itr, value)) + { + first = ++itr; + count -= step + 1; + } + else + { + count = step; + } + } + + return first; + } + + template + TIterator lower_bound(TIterator first, TIterator last, const TValue& value) + { + typedef std::less::value_type> compare; + + return ETLSTD::lower_bound(first, last, value, compare()); + } + + //*************************************************************************** + // upper_bound + template + TIterator upper_bound(TIterator first, TIterator last, const TValue& value, TCompare compare) + { + typedef typename std::iterator_traits::difference_type difference_t; + + difference_t count = std::distance(first, last); + + while (count > 0) + { + TIterator itr = first; + difference_t step = count / 2; + + std::advance(itr, step); + + if (!compare(value, *itr)) + { + first = ++itr; + count -= step + 1; + } + else + { + count = step; + } + } + + return first; + } + + template + TIterator upper_bound(TIterator first, TIterator last, const TValue& value) + { + typedef std::less::value_type> compare; + + return ETLSTD::upper_bound(first, last, value, compare()); + } + + //*************************************************************************** + // equal_range + template + std::pair equal_range(TIterator first, TIterator last, const TValue& value, TCompare compare) + { + return std::make_pair(ETLSTD::lower_bound(first, last, value, compare), + ETLSTD::upper_bound(first, last, value, compare)); + } + + template + std::pair equal_range(TIterator first, TIterator last, const TValue& value) + { + typedef std::less::value_type> compare; + + return std::make_pair(ETLSTD::lower_bound(first, last, value, compare()), + ETLSTD::upper_bound(first, last, value, compare())); + } + + //*************************************************************************** + // fill + template + typename etl::enable_if::value || etl::is_same::value) || !etl::is_pointer::value, void>::type + fill(TIterator first, TIterator last, const TValue& value) + { + while (first != last) + { + *first++ = value; + } + } + + template + typename etl::enable_if<(etl::is_same::value || etl::is_same::value) && etl::is_pointer::value, void>::type + fill(TIterator first, TIterator last, const TValue& value) + { + memset(first, value, last - first); + } + + //*************************************************************************** + // swap + template + void swap(T& a, T& b) + { + T c = a; + a = b; + b = c; + } + + //*************************************************************************** + // iter_swap + template + void iter_swap(TIterator1 a, TIterator2 b) + { + typename std::iterator_traits::value_type c = *a; + *a = *b; + *b = c; + } + + //*************************************************************************** + // equal + template + typename etl::enable_if::value || !etl::is_pointer::value || !etl::is_pod::value_type>::value, bool>::type + equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) + { + while (first1 != last1) + { + if (*first1++ != *first2++) + { + return false; + } + } + + return true; + } + + template + typename etl::enable_if::value && etl::is_pointer::value && etl::is_pod::value_type>::value, bool>::type + equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) + { + typedef typename std::iterator_traits::value_type value_t; + + return (memcmp(first1, first2, sizeof(value_t) * (last1 - last1)) == 0); + } + + //*************************************************************************** + // lexicographical_compare + template + bool lexicographical_compare(TIterator1 first1, TIterator1 last1, + TIterator2 first2, TIterator2 last2, + TCompare compare) + { + while ((first1 != last1) && (first2 != last2)) + { + if (compare(*first1, *first2)) + { + return true; + } + + if (compare(*first2, *first1)) + { + return false; + } + + ++first1; + ++first2; + } + + return (first1 == last1) && (first2 != last2); + } + + //*************************************************************************** + // lexicographical_compare + template + bool lexicographical_compare(TIterator1 first1, TIterator1 last1, + TIterator2 first2, TIterator2 last2) + { + typedef std::less::value_type> compare; + + return ETLSTD::lexicographical_compare(first1, last1, first2, last2, compare()); + } + + //*************************************************************************** + // min + template + const T& min(const T& a, const T& b, TCompare compare) + { + return (compare(a, b)) ? a : b; + } + + template + const T& min(const T& a, const T& b) + { + typedef std::less compare; + + return ETLSTD::min(a, b, compare()); + } + + //*************************************************************************** + // max + template + const T& max(const T& a, const T& b, TCompare compare) + { + return (compare(a, b)) ? b : a; + } + + template + const T& max(const T& a, const T& b) + { + typedef std::less compare; + + return ETLSTD::max(a, b, compare()); + } + + //*************************************************************************** + // Heap + namespace private_heap + { + // Push Heap Helper + template + void push_heap(TIterator first, TDistance value_index, TDistance top_index, TValue value, TCompare compare) + { + TDistance parent = (value_index - 1) / 2; + + while ((value_index > top_index) && compare(first[parent], value)) + { + first[value_index] = first[parent]; + value_index = parent; + parent = (value_index - 1) / 2; + } + + first[value_index] = value; + } + + // Adjust Heap Helper + template + void adjust_heap(TIterator first, TDistance value_index, TDistance length, TValue value, TCompare compare) + { + TDistance top_index = value_index; + TDistance child2nd = (2 * value_index) + 2; + + while (child2nd < length) + { + if (compare(first[child2nd], first[child2nd - 1])) + { + child2nd--; + } + + first[value_index] = first[child2nd]; + value_index = child2nd; + child2nd = 2 * (child2nd + 1); + } + + if (child2nd == length) + { + first[value_index] = first[child2nd - 1]; + value_index = child2nd - 1; + } + + push_heap(first, value_index, top_index, value, compare); + } + + // Is Heap Helper + template + bool is_heap(const TIterator first, const TDistance n, TCompare compare) + { + TDistance parent = 0; + + for (TDistance child = 1; child < n; ++child) + { + if (compare(first[parent], first[child])) + { + return false; + } + + if ((child & 1) == 0) + { + ++parent; + } + } + + return true; + } + } + + // Pop Heap + template + void pop_heap(TIterator first, TIterator last, TCompare compare) + { + typedef typename std::iterator_traits::value_type value_t; + typedef typename std::iterator_traits::difference_type distance_t; + + value_t value = last[-1]; + last[-1] = first[0]; + + private_heap::adjust_heap(first, distance_t(0), distance_t(last - first - 1), value, compare); + } + + // Pop Heap + template + void pop_heap(TIterator first, TIterator last) + { + typedef std::less::value_type> compare; + + ETLSTD::pop_heap(first, last, compare()); + } + + // Push Heap + template + void push_heap(TIterator first, TIterator last, TCompare compare) + { + typedef typename std::iterator_traits::difference_type difference_t; + typedef typename std::iterator_traits::value_type value_t; + + private_heap::push_heap(first, difference_t(last - first - 1), difference_t(0), value_t(*(last - 1)), compare); + } + + // Push Heap + template + void push_heap(TIterator first, TIterator last) + { + typedef std::less::value_type> compare; + + ETLSTD::push_heap(first, last, compare()); + } + + // Make Heap + template + void make_heap(TIterator first, TIterator last, TCompare compare) + { + typedef typename std::iterator_traits::difference_type difference_t; + + if ((last - first) < 2) + { + return; + } + + difference_t length = last - first; + difference_t parent = (length - 2) / 2; + + while (true) + { + private_heap::adjust_heap(first, parent, length, *(first + parent), compare); + + if (parent == 0) + { + return; + } + + --parent; + } + } + + // Make Heap + template + void make_heap(TIterator first, TIterator last) + { + typedef std::less::value_type> compare; + + ETLSTD::make_heap(first, last, compare()); + } + + // Is Heap + template + bool is_heap(TIterator first, TIterator last) + { + typedef std::less::value_type> compare; + + return private_heap::is_heap(first, last - first, compare()); + } + + // Is Heap + template + bool is_heap(TIterator first, TIterator last, TCompare compare) + { + return private_heap::is_heap(first, last - first, compare); + } + + // Search + template + TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last, TCompare compare) + { + if (search_first == search_last) + { + return first; + } + + while (first != last) + { + TIterator1 itr1 = first; + TIterator2 itr2 = search_first; + + while (compare(*itr1,*itr2)) + { + if (itr2 == search_last) + { + return first; + } + + if (itr1 == last) + { + return last; + } + + ++itr1; + ++itr2; + } + + ++first; + } + + return last; + } + + // Search + template + TIterator1 search(TIterator1 first, TIterator1 last, TIterator2 search_first, TIterator2 search_last) + { + typedef std::equal_to::value_type> compare; + + return ETLSTD::search(first, last, search_first, search_last, compare()); + } +} + +#endif + + diff --git a/include/etl/stl/alternate/functional.h b/include/etl/stl/alternate/functional.h new file mode 100644 index 00000000..5dd58506 --- /dev/null +++ b/include/etl/stl/alternate/functional.h @@ -0,0 +1,54 @@ + +#ifndef ETL_STL_ALTERNATE_FUNCTIONAL_INCLUDED +#define ETL_STL_ALTERNATE_FUNCTIONAL_INCLUDED + +#include "../../platform.h" + +#if defined(ETL_IN_UNIT_TEST) +namespace etlstd +#else +namespace std +#endif +{ + //*************************************************************************** + template + struct less + { + ETL_CONSTEXPR bool operator()(const T &lhs, const T &rhs) const + { + return lhs < rhs; + } + }; + + //*************************************************************************** + template + struct greater + { + ETL_CONSTEXPR bool operator()(const T &lhs, const T &rhs) const + { + return lhs > rhs; + } + }; + + //*************************************************************************** + template + struct equal_to + { + ETL_CONSTEXPR bool operator()(const T &lhs, const T &rhs) const + { + return lhs == rhs; + } + }; + + //*************************************************************************** + template + struct not_equal_to + { + ETL_CONSTEXPR bool operator()(const T &lhs, const T &rhs) const + { + return lhs != rhs; + } + }; +} + +#endif \ No newline at end of file diff --git a/include/etl/stl/alternate/iterator.h b/include/etl/stl/alternate/iterator.h new file mode 100644 index 00000000..45ea129a --- /dev/null +++ b/include/etl/stl/alternate/iterator.h @@ -0,0 +1,347 @@ + +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ALTERNATE_ITERATOR_INCLUDED +#define ETL_STL_ALTERNATE_ITERATOR_INCLUDED + +#include "../../platform.h" + +#include +#include "../../type_traits.h" + +#if defined(ETL_IN_UNIT_TEST) +namespace etlstd +#else +namespace std +#endif +{ + //*************************************************************************** + // iterator + template + struct iterator + { + typedef T value_type; + typedef TDistance difference_type; + typedef TPointer pointer; + typedef TReference reference; + typedef TCategory iterator_category; + }; + + //*************************************************************************** + // iterator tags + struct input_iterator_tag {}; + struct output_iterator_tag {}; + struct forward_iterator_tag : public input_iterator_tag {}; + struct bidirectional_iterator_tag : public forward_iterator_tag {}; + struct random_access_iterator_tag : public bidirectional_iterator_tag {}; + + //*************************************************************************** + // iterator_traits + template + struct iterator_traits + { + typedef typename TIterator::difference_type difference_type; + typedef typename TIterator::value_type value_type; + typedef typename TIterator::pointer pointer; + typedef typename TIterator::reference reference; + typedef typename TIterator::iterator_category iterator_category; + }; + + template + struct iterator_traits + { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category ; + }; + + template + struct iterator_traits + { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category ; + }; + + //*************************************************************************** + // advance + template + typename etl::enable_if::iterator_catagory, input_iterator_tag>::value, void>::type + advance(TIterator& itr, TDistance n) + { + while (n--) + { + ++itr; + } + } + + template + typename etl::enable_if::iterator_catagory, output_iterator_tag>::value, void>::type + advance(TIterator& itr, TDistance n) + { + while (n--) + { + ++itr; + } + } + + template + typename etl::enable_if::iterator_catagory, forward_iterator_tag>::value, void>::type + advance(TIterator& itr, TDistance n) + { + while (n--) + { + ++itr; + } + } + + template + typename etl::enable_if::iterator_catagory, bidirectional_iterator_tag>::value, void>::type + advance(TIterator& itr, TDistance n) + { + if (n > 0) + { + while (n--) + { + ++itr; + } + } + else + { + while (n--) + { + --itr; + } + } + } + + template + typename etl::enable_if::iterator_catagory, random_access_iterator_tag>::value, void>::type + advance(TIterator& itr, TDistance n) + { + itr += n; + } + + //*************************************************************************** + // distance + template + typename etl::enable_if::iterator_catagory, random_access_iterator_tag>::value, + typename iterator_traits::difference_type>::type + distance(TIterator first, TIterator last) + { + typename iterator_traits::difference_type d = 0; + + while (first != last) + { + ++d; + } + + return d; + } + + template + typename etl::enable_if::iterator_catagory, random_access_iterator_tag>::value, + typename iterator_traits::difference_type>::type + distance(TIterator first, TIterator last) + { + return last - first; + } + + //*************************************************************************** + // reverse_iterator + template + struct reverse_iterator + { + public: + + typedef typename iterator_traits::difference_type difference_type; + typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::pointer pointer; + typedef typename iterator_traits::reference reference; + typedef typename iterator_traits::iterator_category iterator_category; + + reverse_iterator() + { + } + + explicit reverse_iterator(TIterator itr) : current(itr) + { + } + + reverse_iterator(const reverse_iterator& itr) + : current(itr.current) + { + } + + template + reverse_iterator(const reverse_iterator& itr) + : current(itr.base()) + { + } + + reverse_iterator& operator = (const reverse_iterator& itr) + { + current = itr.base(); + return *this; + } + + template + reverse_iterator& operator = (const reverse_iterator& itr) + { + current = itr.base(); + return *this; + } + + TIterator base() const + { + return current; + } + + ETL_CONSTEXPR reference operator *() const + { + TIterator temp = current; + --temp; + return *temp; + } + + ETL_CONSTEXPR pointer operator ->() const + { + TIterator temp = current; + --temp; + return &(*temp); + } + + ETL_CONSTEXPR reverse_iterator& operator ++() + { + --current; + return *this; + } + + ETL_CONSTEXPR reverse_iterator operator ++(int) + { + reverse_iterator temp = *this; + --current; + return temp; + } + + ETL_CONSTEXPR reverse_iterator& operator --() + { + ++current; + return *this; + } + + ETL_CONSTEXPR reverse_iterator operator --(int) + { + reverse_iterator temp = *this; + ++current; + return temp; + } + + ETL_CONSTEXPR reverse_iterator operator +(difference_type n) const + { + return reverse_iterator(current - n); + } + + ETL_CONSTEXPR reverse_iterator& operator +=(difference_type n) + { + current -= n; + return *this; + } + + ETL_CONSTEXPR reverse_iterator operator -(difference_type n) const + { + return reverse_iterator(current + n); + } + + ETL_CONSTEXPR reverse_iterator& operator -=(difference_type n) + { + current += n; + return *this; + } + + ETL_CONSTEXPR reference operator [](difference_type n) const + { + return *(*this + n); + } + + protected: + + TIterator current; + }; + + template + inline ETL_CONSTEXPR bool operator <(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return rhs.base() < lhs.base(); + } + + template + inline ETL_CONSTEXPR bool operator !=(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return !(lhs == rhs); + } + + template + inline ETL_CONSTEXPR bool operator >(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return rhs < lhs; + } + + template + inline ETL_CONSTEXPR bool operator <=(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return !(rhs < lhs); + } + + template + inline ETL_CONSTEXPR bool operator >=(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return !(lhs < rhs); + } + + template + inline ETL_CONSTEXPR typename reverse_iterator::difference_type operator -(const reverse_iterator& lhs, const reverse_iterator& rhs) + { + return rhs.base() - lhs.base(); + } + + template + inline ETL_CONSTEXPR reverse_iterator operator +(TDifference n, const reverse_iterator& itr) + { + return itr.operator +(n); + } +} + +#endif diff --git a/include/etl/stl/alternate/limits.h b/include/etl/stl/alternate/limits.h new file mode 100644 index 00000000..b8bf99a4 --- /dev/null +++ b/include/etl/stl/alternate/limits.h @@ -0,0 +1,533 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ALTERNATE_LIMITS_INCLUDED +#define ETL_STL_ALTERNATE_LIMITS_INCLUDED + +#include "../../platform.h" +#include "../../type_traits.h" +#include "../../char_traits.h" + +#include +#include +#include + +#define ETL_LOG2(x) (((x) * 301) / 1000) + +#if defined(ETL_IN_UNIT_TEST) +#define ETLSTD etlstd +namespace etlstd +#else +#define ETLSTD std +namespace std +#endif +{ + template class numeric_limits; + + enum float_round_style + { + round_indeterminate = -1, + round_toward_zero = 0, + round_to_nearest = 1, + round_toward_infinity = 2, + round_toward_neg_infinity = 3, + }; + + enum float_denorm_style + { + denorm_indeterminate = -1, + denorm_absent = 0, + denorm_present = 1 + }; + + //*************************************************************************** + // Base for integral types. + template + class etl_integral_type + { + public: + static const bool is_specialized; + + static const int max_digits10; + + static const bool is_integer; + static const bool is_exact; + + static const int radix; + static ETL_CONSTEXPR T epsilon() { return 0; } + static ETL_CONSTEXPR T round_error() { return 0; } + + static const int digits; + static const int digits10; + + static const bool is_signed; + + static const int min_exponent; + static const int min_exponent10; + static const int max_exponent; + static const int max_exponent10; + + static const bool has_infinity; + static const bool has_quiet_NaN; + static const bool has_signaling_NaN; + static const float_denorm_style has_denorm; + static const bool has_denorm_loss; + + static ETL_CONSTEXPR T infinity() { return 0; } + static ETL_CONSTEXPR T quiet_NaN() { return 0; } + static ETL_CONSTEXPR T signaling_NaN() { return 0; } + static ETL_CONSTEXPR T denorm_min() { return 0; } + + static const bool is_iec559; + static const bool is_bounded; + static const bool is_modulo; + + static const bool traps; + static const bool tinyness_before; + static const float_round_style round_style; + }; + + template const bool etl_integral_type::is_specialized = true; + template const int etl_integral_type::digits = (CHAR_BIT * sizeof(T)) - (etl::is_signed::value ? 1 : 0); + template const int etl_integral_type::digits10 = ETL_LOG2(digits);; + template const int etl_integral_type::max_digits10 = 0; + template const bool etl_integral_type::is_signed = etl::is_signed::value; + template const bool etl_integral_type::is_integer = true; + template const bool etl_integral_type::is_exact = true; + template const int etl_integral_type::radix = 2; + template const int etl_integral_type::min_exponent = 0; + template const int etl_integral_type::min_exponent10 = 0; + template const int etl_integral_type::max_exponent = 0; + template const int etl_integral_type::max_exponent10 = 0; + template const bool etl_integral_type::has_infinity = false; + template const bool etl_integral_type::has_quiet_NaN = false; + template const bool etl_integral_type::has_signaling_NaN = false; + template const float_denorm_style etl_integral_type::has_denorm = denorm_absent; + template const bool etl_integral_type::has_denorm_loss = false; + template const bool etl_integral_type::is_iec559 = false; + template const bool etl_integral_type::is_bounded = true; + template const bool etl_integral_type::is_modulo = etl::is_unsigned::value; + template const bool etl_integral_type::traps = false; + template const bool etl_integral_type::tinyness_before = false; + template const float_round_style etl_integral_type::round_style = round_toward_zero; + + //*************************************************************************** + // Base for floating point types. + template + class etl_floating_point_type + { + public: + static const bool is_specialized; + + static const bool is_signed; + static const bool is_integer; + static const bool is_exact; + + static const int radix; + + static const bool has_infinity; + static const bool has_quiet_NaN; + static const bool has_signaling_NaN; + static const float_denorm_style has_denorm; + static const bool has_denorm_loss; + + static const bool is_iec559; + static const bool is_bounded; + static const bool is_modulo; + + static ETL_CONSTEXPR T round_error() { return T(0.5); } + static ETL_CONSTEXPR T infinity() { return 0; } + static ETL_CONSTEXPR T quiet_NaN() { return 0; } + static ETL_CONSTEXPR T signaling_NaN() { return 0; } + + static const bool traps; + static const bool tinyness_before; + static const float_round_style round_style; + }; + + template const bool etl_floating_point_type::is_specialized = true; + template const bool etl_floating_point_type::is_signed = true; + template const bool etl_floating_point_type::is_integer = false; + template const bool etl_floating_point_type::is_exact = false; + template const int etl_floating_point_type::radix = 2; + template const bool etl_floating_point_type::has_infinity = false; + template const bool etl_floating_point_type::has_quiet_NaN = false; + template const bool etl_floating_point_type::has_signaling_NaN = false; + template const float_denorm_style etl_floating_point_type::has_denorm = denorm_present; + template const bool etl_floating_point_type::has_denorm_loss = true; + template const bool etl_floating_point_type::is_iec559 = true; + template const bool etl_floating_point_type::is_bounded = true; + template const bool etl_floating_point_type::is_modulo = false; + template const bool etl_floating_point_type::traps = false; + template const bool etl_floating_point_type::tinyness_before = true; + template const float_round_style etl_floating_point_type::round_style = round_to_nearest; + + //*************************************************************************** + // Default + template + class numeric_limits; + + //*************************************************************************** + // bool + template<> + class numeric_limits + { + public: + + static const bool is_specialized; + + static ETL_CONSTEXPR bool min() { return false; } + static ETL_CONSTEXPR bool max() { return true; } + static ETL_CONSTEXPR bool lowest() { return false; } + + static const int digits; + static const int digits10; + static const int max_digits10; + + static const bool is_signed; + static const bool is_integer; + static const bool is_exact; + + static const int radix; + static const bool epsilon() { return 0; } + static const bool round_error() { return 0; } + + static const int min_exponent; + static const int min_exponent10; + static const int max_exponent; + static const int max_exponent10; + + static const bool has_infinity; + static const bool has_quiet_NaN; + static const bool has_signaling_NaN; + static const float_denorm_style has_denorm; + static const bool has_denorm_loss; + + static ETL_CONSTEXPR bool infinity() { return 0; } + static ETL_CONSTEXPR bool quiet_NaN() { return 0; } + static ETL_CONSTEXPR bool signaling_NaN() { return 0; } + static ETL_CONSTEXPR bool denorm_min() { return 0; } + + static const bool is_iec559; + static const bool is_bounded; + static const bool is_modulo; + + static const bool traps; + static const bool tinyness_before; + static const float_round_style round_style; + }; + + const bool numeric_limits::is_specialized = true; + const int numeric_limits::digits = 1; + const int numeric_limits::digits10 = 0; + const int numeric_limits::max_digits10 = 0; + const bool numeric_limits::is_signed = false; + const bool numeric_limits::is_integer = true; + const bool numeric_limits::is_exact = true; + const int numeric_limits::radix = 2; + const int numeric_limits::min_exponent = 0; + const int numeric_limits::min_exponent10 = 0; + const int numeric_limits::max_exponent = 0; + const int numeric_limits::max_exponent10 = 0; + const bool numeric_limits::has_infinity = false; + const bool numeric_limits::has_quiet_NaN = false; + const bool numeric_limits::has_signaling_NaN = false; + const float_denorm_style numeric_limits::has_denorm = denorm_absent; + const bool numeric_limits::has_denorm_loss = false; + const bool numeric_limits::is_iec559 = false; + const bool numeric_limits::is_bounded = true; + const bool numeric_limits::is_modulo = false; + const bool numeric_limits::traps = false; + const bool numeric_limits::tinyness_before = false; + const float_round_style numeric_limits::round_style = round_toward_zero; + + //*************************************************************************** + // char + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR char min() { return CHAR_MIN; } + static ETL_CONSTEXPR char max() { return CHAR_MAX; } + static ETL_CONSTEXPR char lowest() { return CHAR_MIN; } + }; + + //*************************************************************************** + // unsigned char + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR unsigned char min() { return 0; } + static ETL_CONSTEXPR unsigned char max() { return UCHAR_MAX; } + static ETL_CONSTEXPR unsigned char lowest() { return 0; } + }; + + //*************************************************************************** + // signed char + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR signed char min() { return SCHAR_MIN; } + static ETL_CONSTEXPR signed char max() { return SCHAR_MAX; } + static ETL_CONSTEXPR signed char lowest() { return SCHAR_MIN; } + }; + + //*************************************************************************** + // char16_t + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR char16_t min() { return 0; } + static ETL_CONSTEXPR char16_t max() { return UINT_LEAST16_MAX; } + static ETL_CONSTEXPR char16_t lowest() { return 0; } + }; + + //*************************************************************************** + // char32_t + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR char32_t min() { return 0; } + static ETL_CONSTEXPR char32_t max() { return UINT_LEAST32_MAX; } + static ETL_CONSTEXPR char32_t lowest() { return 0; } + }; + + //*************************************************************************** + // wchar_t + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR wchar_t min() { return WCHAR_MIN; } + static ETL_CONSTEXPR wchar_t max() { return WCHAR_MAX; } + static ETL_CONSTEXPR wchar_t lowest() { return WCHAR_MIN; } + }; + + //*************************************************************************** + // short + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR short min() { return SHRT_MIN; } + static ETL_CONSTEXPR short max() { return SHRT_MAX; } + static ETL_CONSTEXPR short lowest() { return SHRT_MIN; } + }; + + //*************************************************************************** + // unsigned short + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR unsigned short min() { return 0; } + static ETL_CONSTEXPR unsigned short max() { return USHRT_MAX; } + static ETL_CONSTEXPR unsigned short lowest() { return 0; } + }; + + //*************************************************************************** + // int + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR int min() { return INT_MIN; } + static ETL_CONSTEXPR int max() { return INT_MAX; } + static ETL_CONSTEXPR int lowest() { return INT_MIN; } + }; + + //*************************************************************************** + // unsigned int + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR unsigned int min() { return 0; } + static ETL_CONSTEXPR unsigned int max() { return UINT_MAX; } + static ETL_CONSTEXPR unsigned int lowest() { return 0; } + }; + + //*************************************************************************** + // long + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR long min() { return LONG_MIN; } + static ETL_CONSTEXPR long max() { return LONG_MAX; } + static ETL_CONSTEXPR long lowest() { return LONG_MIN; } + }; + + //*************************************************************************** + // unsigned long + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR unsigned long min() { return 0; } + static ETL_CONSTEXPR unsigned long max() { return ULONG_MAX; } + static ETL_CONSTEXPR unsigned long lowest() { return 0; } + }; + + //*************************************************************************** + // long long + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR long long min() { return LLONG_MIN; } + static ETL_CONSTEXPR long long max() { return LLONG_MAX; } + static ETL_CONSTEXPR long long lowest() { return LLONG_MIN; } + }; + + //*************************************************************************** + // unsigned long long + template<> + class numeric_limits : public etl_integral_type + { + public: + + static ETL_CONSTEXPR unsigned long long min() { return 0; } + static ETL_CONSTEXPR unsigned long long max() { return ULLONG_MAX; } + static ETL_CONSTEXPR unsigned long long lowest() { return 0; } + }; + + //*************************************************************************** + // float + template<> + class numeric_limits : public etl_floating_point_type + { + public: + + static ETL_CONSTEXPR float min() { return FLT_MIN; } + static ETL_CONSTEXPR float max() { return FLT_MAX; } + static ETL_CONSTEXPR float lowest() { return -FLT_MAX; } + static ETL_CONSTEXPR float epsilon() { return FLT_EPSILON; } + static ETL_CONSTEXPR float denorm_min() { return FLT_MIN; } + + static const int digits; + static const int digits10; + static const int max_digits10; + + static const int min_exponent; + static const int min_exponent10; + static const int max_exponent; + static const int max_exponent10; + }; + + const int numeric_limits::digits = FLT_MANT_DIG; + const int numeric_limits::max_digits10 = ETL_LOG2(FLT_MANT_DIG) + 2; + const int numeric_limits::digits10 = FLT_DIG; + const int numeric_limits::min_exponent = FLT_MIN_EXP; + const int numeric_limits::min_exponent10 = FLT_MIN_10_EXP; + const int numeric_limits::max_exponent = FLT_MAX_EXP; + const int numeric_limits::max_exponent10 = FLT_MAX_10_EXP; + + //*************************************************************************** + // double + template<> + class numeric_limits : public etl_floating_point_type + { + public: + + static ETL_CONSTEXPR double min() { return DBL_MIN; } + static ETL_CONSTEXPR double max() { return DBL_MAX; } + static ETL_CONSTEXPR double lowest() { return -DBL_MAX; } + static ETL_CONSTEXPR double epsilon() { return DBL_EPSILON; } + static ETL_CONSTEXPR double denorm_min() { return DBL_MIN; } + + static const int digits; + static const int digits10; + static const int max_digits10; + + static const int min_exponent; + static const int min_exponent10; + static const int max_exponent; + static const int max_exponent10; + }; + + const int numeric_limits::digits = DBL_MANT_DIG; + const int numeric_limits::max_digits10 = ETL_LOG2(DBL_MANT_DIG) + 2; + const int numeric_limits::digits10 = DBL_DIG; + const int numeric_limits::min_exponent = DBL_MIN_EXP; + const int numeric_limits::min_exponent10 = DBL_MIN_10_EXP; + const int numeric_limits::max_exponent = DBL_MAX_EXP; + const int numeric_limits::max_exponent10 = DBL_MAX_10_EXP; + + //*************************************************************************** + // long double + template<> + class numeric_limits : public etl_floating_point_type + { + public: + + static ETL_CONSTEXPR long double min() { return LDBL_MIN; } + static ETL_CONSTEXPR long double max() { return LDBL_MAX; } + static ETL_CONSTEXPR long double lowest() { return -LDBL_MAX; } + static ETL_CONSTEXPR long double epsilon() { return LDBL_EPSILON; } + static ETL_CONSTEXPR long double denorm_min() { return LDBL_MIN; } + + static const int digits; + static const int digits10; + static const int max_digits10; + + static const int min_exponent; + static const int min_exponent10; + static const int max_exponent; + static const int max_exponent10; + }; + + const int numeric_limits::digits = LDBL_MANT_DIG; + const int numeric_limits::max_digits10 = ETL_LOG2(LDBL_MANT_DIG) + 2; + const int numeric_limits::digits10 = LDBL_DIG; + const int numeric_limits::min_exponent = LDBL_MIN_EXP; + const int numeric_limits::min_exponent10 = LDBL_MIN_10_EXP; + const int numeric_limits::max_exponent = LDBL_MAX_EXP; + const int numeric_limits::max_exponent10 = LDBL_MAX_10_EXP; +} + +#endif diff --git a/include/etl/stl/alternate/utility.h b/include/etl/stl/alternate/utility.h new file mode 100644 index 00000000..4fe77726 --- /dev/null +++ b/include/etl/stl/alternate/utility.h @@ -0,0 +1,140 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ALTERNATE_UTILITY_INCLUDED +#define ETL_STL_ALTERNATE_UTILITY_INCLUDED + +#include "../../platform.h" +#include "algorithm.h" + +#if defined(ETL_IN_UNIT_TEST) +#define ETLSTD etlstd +namespace etlstd +#else +#define ETLSTD std +namespace std +#endif +{ + //****************************************************************************** + template + struct pair + { + typedef T1 first_type; + typedef T2 second_type; + + T1 first; + T2 second; + + pair() + : first(T1()), + second(T2()) + { + } + + pair(const T1& a, const T2& b) + : first(a), + second(b) + { + } + + template + pair(const pair& other) + : first(other.first), + second(other.second) + { + } + + pair(const pair& other) + : first(other.first), + second(other.second) + { + } + + void swap(pair& other) + { + ETLSTD::swap(first, other.first); + ETLSTD::swap(second, other.second); + } + }; + + //****************************************************************************** + template + inline pair make_pair(T1 a, T2 b) + { + return pair(a, b); + } + + //****************************************************************************** + template + inline void swap(pair& a, pair& b) + { + a.swap(b); + } + + //****************************************************************************** + template + inline bool operator ==(const pair& a, const pair& b) + { + return (a.first == b.first) && (a.second == b.second); + } + + template + inline bool operator !=(const pair& a, const pair& b) + { + return !(a == b); + } + + template + inline bool operator <(const pair& a, const pair& b) + { + return (a.first < b.first) || + (!(b.first < a.first) && (a.second < b.second)); + } + + template + inline bool operator >(const pair& a, const pair& b) + { + return (b < a); + } + + template + inline bool operator <=(const pair& a, const pair& b) + { + return !(b < a); + } + + template + inline bool operator >=(const pair& a, const pair& b) + { + return !(a < b); + } +} + +#endif diff --git a/include/etl/stl/functional.h b/include/etl/stl/functional.h new file mode 100644 index 00000000..f3fd0034 --- /dev/null +++ b/include/etl/stl/functional.h @@ -0,0 +1,13 @@ + +#ifndef ETL_STL_FUNCTIONAL_INCLUDED +#define ETL_STL_FUNCTIONAL_INCLUDED + +#include "../platform.h" + +#if defined(ETL_NO_STL) + #include "alternate/functional.h" +#else + #include +#endif + +#endif diff --git a/include/etl/stl/iterator.h b/include/etl/stl/iterator.h new file mode 100644 index 00000000..91299a26 --- /dev/null +++ b/include/etl/stl/iterator.h @@ -0,0 +1,43 @@ + +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_ITERATOR_INCLUDED +#define ETL_STL_ITERATOR_INCLUDED + +#include "../platform.h" + +#if defined(ETL_NO_STL) + #include "alternate/iterator.h" +#else + #include +#endif + +#endif \ No newline at end of file diff --git a/include/etl/stl/limits.h b/include/etl/stl/limits.h new file mode 100644 index 00000000..6a0ce1d4 --- /dev/null +++ b/include/etl/stl/limits.h @@ -0,0 +1,42 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_LIMITS_INCLUDED +#define ETL_STL_LIMITS_INCLUDED + +#include "../platform.h" + +#if defined(ETL_NO_STL) + #include "alternate/limits.h" +#else + #include +#endif + +#endif diff --git a/include/etl/stl/utility.h b/include/etl/stl/utility.h new file mode 100644 index 00000000..24a5990f --- /dev/null +++ b/include/etl/stl/utility.h @@ -0,0 +1,42 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STL_UTILITY_INCLUDED +#define ETL_STL_UTILITY_INCLUDED + +#include "../platform.h" + +#if defined(ETL_NO_STL) + #include "alternate/utility.h" +#else + #include +#endif + +#endif diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 5402cda6..10240fed 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -40,7 +40,7 @@ SOFTWARE. #include "integral_limits.h" #include "hash.h" -#include +#include "algorithm.h" ///\defgroup array array /// A wrapper for arrays @@ -104,7 +104,7 @@ namespace etl typedef T value_type; typedef TTraits traits_type; - typedef std::size_t size_type; + typedef size_t size_type; typedef const T& const_reference; typedef const T* const_pointer; typedef const T* const_iterator; diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index f0b23bfa..ee01e614 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -60,7 +60,7 @@ SOFTWARE. #include "nullptr.h" #include "static_assert.h" -#if (ETL_CPP11_SUPPORTED) +#if (ETL_CPP11_SUPPORTED) && !defined(ETL_NO_STL) #include #endif @@ -269,14 +269,14 @@ namespace etl /// is_pod /// For C++03, only fundamental and pointers types are recognised. ///\ingroup type_traits -#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(ETL_IN_UNIT_TEST) +#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL) // For compilers that support C++11 template struct is_pod : std::is_pod {}; #else template struct is_pod : etl::integral_constant::value || etl::is_pointer::value> {}; #endif -#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(ETL_IN_UNIT_TEST) +#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL) /// is_trivially_constructible ///\ingroup type_traits template struct is_trivially_constructible : std::is_trivially_constructible {}; diff --git a/include/etl/type_traits_generator.h b/include/etl/type_traits_generator.h index 61df9313..183d74ca 100644 --- a/include/etl/type_traits_generator.h +++ b/include/etl/type_traits_generator.h @@ -72,7 +72,7 @@ cog.outl("//******************************************************************** #include "nullptr.h" #include "static_assert.h" -#if (ETL_CPP11_SUPPORTED) +#if (ETL_CPP11_SUPPORTED) && !defined(ETL_NO_STL) #include #endif @@ -281,14 +281,14 @@ namespace etl /// is_pod /// For C++03, only fundamental and pointers types are recognised. ///\ingroup type_traits -#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(ETL_IN_UNIT_TEST) +#if (ETL_CPP11_SUPPORTED && !defined(ARDUINO) && !defined(ETL_STLPORT)) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL) // For compilers that support C++11 template struct is_pod : std::is_pod {}; #else template struct is_pod : etl::integral_constant::value || etl::is_pointer::value> {}; #endif -#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(ETL_IN_UNIT_TEST) +#if (ETL_CPP11_TYPE_TRAITS_IS_TRIVIAL_SUPPORTED) && !defined(ETL_STLPORT) && !defined(ETL_IN_UNIT_TEST) && !defined(ETL_NO_STL) /// is_trivially_constructible ///\ingroup type_traits template struct is_trivially_constructible : std::is_trivially_constructible {}; diff --git a/include/etl/u16string.h b/include/etl/u16string.h index e4b8c1af..4dd9b990 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -35,7 +35,7 @@ SOFTWARE. #include "basic_string.h" #include "hash.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -145,7 +145,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7a325634..3edc3465 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -35,7 +35,7 @@ SOFTWARE. #include "basic_string.h" #include "hash.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -145,7 +145,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 0f757b0e..5dc63314 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -32,13 +32,14 @@ SOFTWARE. #define ETL_UNORDERED_MAP_INCLUDED #include -#include -#include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "container.h" #include "pool.h" #include "array.h" diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 25257d39..4db58e5a 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -32,13 +32,14 @@ SOFTWARE. #define ETL_UNORDERED_MULTIMAP_INCLUDED #include -#include -#include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "container.h" #include "pool.h" #include "vector.h" diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 11cbc07a..8e3bcd29 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -32,13 +32,14 @@ SOFTWARE. #define ETL_UNORDERED_MULTISET_INCLUDED #include -#include -#include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "container.h" #include "pool.h" #include "vector.h" diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 94473567..b1541ee5 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -32,13 +32,14 @@ SOFTWARE. #define ETL_UNORDERED_SET_INCLUDED #include -#include -#include -#include -#include -#include #include "platform.h" + +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" +#include "stl/utility.h" + #include "container.h" #include "pool.h" #include "vector.h" diff --git a/include/etl/variant_pool.h b/include/etl/variant_pool.h index 1c033ce5..068d0d3a 100644 --- a/include/etl/variant_pool.h +++ b/include/etl/variant_pool.h @@ -52,9 +52,11 @@ SOFTWARE. #define ETL_VARIANT_POOL_INCLUDED #include -#include #include "platform.h" + +#include "stl/utility.h" + #include "error_handler.h" #include "exception.h" #include "largest.h" @@ -133,7 +135,7 @@ namespace etl { } -#if !ETL_CPP11_SUPPORTED || defined(ETL_STLPORT) +#if !ETL_CPP11_SUPPORTED || defined(ETL_STLPORT) || defined(ETL_NO_STL) //************************************************************************* /// Creates the object. Default constructor. //************************************************************************* diff --git a/include/etl/variant_pool_generator.h b/include/etl/variant_pool_generator.h index cb357424..62a2f923 100644 --- a/include/etl/variant_pool_generator.h +++ b/include/etl/variant_pool_generator.h @@ -64,7 +64,6 @@ cog.outl("//******************************************************************** #define ETL_VARIANT_POOL_INCLUDED #include -#include #include "platform.h" #include "error_handler.h" @@ -74,7 +73,9 @@ cog.outl("//******************************************************************** #include "alignment.h" #include "static_assert.h" #include "type_lookup.h" -#include +#include "pool.h" + +#include "stl/utility.h" #undef ETL_FILE #define ETL_FILE "40" diff --git a/include/etl/vector.h b/include/etl/vector.h index 9eb0b83d..50b3ee30 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -35,9 +35,6 @@ SOFTWARE. #include #include -#include -#include -#include #include #include "platform.h" @@ -53,7 +50,11 @@ SOFTWARE. #include "debug_count.h" #include "private/vector_base.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#include "stl/algorithm.h" +#include "stl/iterator.h" +#include "stl/functional.h" + +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -1067,7 +1068,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* @@ -1183,7 +1184,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Constructor, from an initializer_list. //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index a4f7bc23..1ab83a02 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -35,7 +35,7 @@ SOFTWARE. #include "basic_string.h" #include "hash.h" -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) #include #endif @@ -146,7 +146,7 @@ namespace etl this->assign(first, last); } -#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) +#if ETL_CPP11_SUPPORTED && !defined(ETL_STLPORT) && !defined(ETL_NO_STL) //************************************************************************* /// Construct from initializer_list. //************************************************************************* diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9fb4fb86..9ac85d7a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -132,7 +132,7 @@ if (WIN32) endif() if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - list(APPEND TEST_SOURCE_FILES "test_atomic_gcc.cpp") + list(APPEND TEST_SOURCE_FILES "test_atomic_gcc_sync.cpp") endif() add_executable(etl_tests ${TEST_SOURCE_FILES} diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 20b6dfb2..7a3eee9d 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -279,6 +279,16 @@ + + + + + + + + + + @@ -383,6 +393,10 @@ + + + + diff --git a/test/etl_profile.h b/test/etl_profile.h index 906660b9..213e99ea 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -74,6 +74,8 @@ SOFTWARE. //#define ETL_MESSAGES_ARE_VIRTUAL //#define ETL_POLYMORPHIC_MESSAGES +//#define ETL_NO_STL + #ifdef _MSC_VER #include "profiles/msvc_x86.h" #else diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index b04d62fc..52984cc9 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -867,5 +867,47 @@ namespace is_same = std::equal(std::begin(output_false), std::end(output_false), std::begin(compare_false)); CHECK(is_same); } + + //========================================================================= + TEST(sort_default) + { + std::vector data(100, 0); + std::iota(data.begin(), data.end(), 1); + + for (int i = 0; i < 100; ++i) + { + std::random_shuffle(data.begin(), data.end()); + + std::vector data1 = data; + std::vector data2 = data; + + std::sort(data1.begin(), data1.end()); + etl::sort(data2.begin(), data2.end()); + + bool is_same = std::equal(data1.begin(), data1.end(), data2.begin()); + CHECK(is_same); + } + } + + //========================================================================= + TEST(sort_greater) + { + std::vector data(100, 0); + std::iota(data.begin(), data.end(), 1); + + for (int i = 0; i < 100; ++i) + { + std::random_shuffle(data.begin(), data.end()); + + std::vector data1 = data; + std::vector data2 = data; + + std::sort(data1.begin(), data1.end(), std::greater()); + etl::sort(data2.begin(), data2.end(), std::greater()); + + bool is_same = std::equal(data1.begin(), data1.end(), data2.begin()); + CHECK(is_same); + } + } }; } diff --git a/test/test_atomic_std.cpp b/test/test_atomic_std.cpp index 9af9c77e..d89872a9 100644 --- a/test/test_atomic_std.cpp +++ b/test/test_atomic_std.cpp @@ -230,7 +230,7 @@ namespace std::atomic compare(&data[0]); etl::atomic test(&data[0]); - CHECK_EQUAL((int*)compare.fetch_add(std::ptrdiff_t(10)), (int*)test.fetch_add(std::ptrdiff_t(10))); + CHECK_EQUAL((int*)compare.fetch_add(ptrdiff_t(10)), (int*)test.fetch_add(ptrdiff_t(10))); } //========================================================================= @@ -338,7 +338,7 @@ namespace std::atomic compare(&data[0]); etl::atomic test(&data[0]); - CHECK_EQUAL((int*)compare.fetch_add(std::ptrdiff_t(10)), (int*)test.fetch_add(std::ptrdiff_t(10))); + CHECK_EQUAL((int*)compare.fetch_add(ptrdiff_t(10)), (int*)test.fetch_add(ptrdiff_t(10))); } //========================================================================= diff --git a/test/test_fsm.cpp b/test/test_fsm.cpp index 74cb9b45..cbc6d376 100644 --- a/test/test_fsm.cpp +++ b/test/test_fsm.cpp @@ -182,7 +182,7 @@ namespace typedef etl::largest Largest_t; typedef etl::packet Packet_t; - + etl::queue messageQueue; int startCount; @@ -531,7 +531,7 @@ namespace // Send Start event. motorControl.receive(nmr, Recursive()); - CHECK_EQUAL(1, motorControl.messageQueue.size()); + CHECK_EQUAL(1U, motorControl.messageQueue.size()); // Send the queued message. motorControl.receive(nmr, motorControl.messageQueue.front().get()); diff --git a/test/test_no_stl_algorithm.cpp b/test/test_no_stl_algorithm.cpp new file mode 100644 index 00000000..f29b4f9d --- /dev/null +++ b/test/test_no_stl_algorithm.cpp @@ -0,0 +1,581 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#undef min +#undef max + +#include "../include/etl/stl/alternate/algorithm.h" + +#include +#include +#include + +namespace +{ + int dataEQ[10] = { 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 }; + std::list dataEQL = { 1, 1, 3, 3, 5, 5, 7, 7, 9, 9 }; + + int dataS[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + std::list dataSL = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + + int dataA[10] = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 }; + + typedef std::vector Vector; + Vector dataV = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 }; + + typedef std::list List; + List dataL = { 2, 1, 4, 3, 6, 5, 8, 7, 10, 9 }; + + class Data + { + public: + + Data() + : a(0), + b(0) + { + } + + Data(int a, int b) + : a(a), + b(b) + { + } + + int a; + int b; + }; + + Data dataD[10] = { Data(1, 2), Data(2, 1), Data(3, 4), Data(4, 3), Data(5, 6), Data(6, 5), Data(7, 8), Data(8, 7), Data(9, 10), Data(10, 9) }; + + bool operator ==(const Data& lhs, const Data& rhs) + { + return (lhs.a == rhs.a) && (lhs.b == rhs.b); + } + + struct StructDataPredicate + { + bool operator ()(const Data& lhs, const Data& rhs) const + { + return lhs.a < rhs.a; + } + }; + + struct StructDataEquality + { + bool operator ()(const Data& lhs, const Data& rhs) const + { + return lhs.a == rhs.a; + } + }; + + std::ostream& operator << (std::ostream& os, const Data& data_) + { + os << data_.a << "," << data_.b; + return os; + } + + struct Greater : public std::binary_function + { + bool operator()(int a, int b) const + { + return a > b; + } + }; + + SUITE(test_no_stl_algorithm) + { + //************************************************************************* + TEST(distance_non_random) + { + ptrdiff_t d1 = std::distance(dataL.begin(), dataL.end()); + ptrdiff_t d2 = etlstd::distance(dataL.begin(), dataL.end()); + + CHECK_EQUAL(d1, d2); + } + + //************************************************************************* + TEST(distance_random) + { + ptrdiff_t d1 = std::distance(dataV.begin(), dataV.end()); + ptrdiff_t d2 = etlstd::distance(dataV.begin(), dataV.end()); + + CHECK_EQUAL(d1, d2); + } + + //************************************************************************* + TEST(advance_non_random) + { + List::const_iterator itr1 = dataL.begin(); + List::const_iterator itr2 = dataL.begin(); + + std::advance(itr1, 4); + std::advance(itr2, 4); + + CHECK_EQUAL(*itr1, *itr2); + } + + //************************************************************************* + TEST(advance_random) + { + Vector::const_iterator itr1 = dataV.begin(); + Vector::const_iterator itr2 = dataV.begin(); + + std::advance(itr1, 4); + std::advance(itr2, 4); + + CHECK_EQUAL(*itr1, *itr2); + } + + //************************************************************************* + TEST(min) + { + int a = 1; + int b = 2; + + CHECK_EQUAL((std::min(a, b)), (etlstd::min(a, b))); + CHECK_EQUAL((std::min(b, a)), (etlstd::min(b, a))); + } + + //************************************************************************* + TEST(min_compare) + { + int a = 1; + int b = 2; + + CHECK_EQUAL((std::min(a, b, Greater())), (etlstd::min(a, b, Greater()))); + CHECK_EQUAL((std::min(b, a, Greater())), (etlstd::min(b, a, Greater()))); + } + + //************************************************************************* + TEST(max) + { + int a = 1; + int b = 2; + + CHECK_EQUAL((std::max(a, b)), (etlstd::max(a, b))); + CHECK_EQUAL((std::max(b, a)), (etlstd::max(b, a))); + } + + //************************************************************************* + TEST(max_compare) + { + int a = 1; + int b = 2; + + CHECK_EQUAL((std::max(a, b, Greater())), (etlstd::max(a, b, Greater()))); + CHECK_EQUAL((std::max(b, a, Greater())), (etlstd::max(b, a, Greater()))); + } + + //************************************************************************* + TEST(copy_pod_pointer) + { + int data1[10]; + int data2[10]; + + std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); + etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_non_pod_pointer) + { + Data data1[10]; + Data data2[10]; + + std::copy(std::begin(dataD), std::end(dataD), std::begin(data1)); + etlstd::copy(std::begin(dataD), std::end(dataD), std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_non_random_iterator) + { + List data1(dataL.size()); + List data2(dataL.size()); + + std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); + etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_n_pod_pointer) + { + int data1[10]; + int data2[10]; + + std::copy_n(std::begin(dataA), 10, std::begin(data1)); + etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_n_non_pod_pointer) + { + Data data1[10]; + Data data2[10]; + + std::copy_n(std::begin(dataD), 10, std::begin(data1)); + etlstd::copy_n(std::begin(dataD), 10, std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_n_non_random_iterator) + { + List data1(dataL.size()); + List data2(dataL.size()); + + std::copy_n(std::begin(dataA), 10, std::begin(data1)); + etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_backward_pod_pointer) + { + int data1[10]; + int data2[10]; + + std::copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); + etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_backward_non_pod_pointer) + { + Data data1[10]; + Data data2[10]; + + std::copy_backward(std::begin(dataD), std::end(dataD), std::end(data1)); + etlstd::copy_backward(std::begin(dataD), std::end(dataD), std::end(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(copy_backward_non_random_iterator) + { + List data1(dataL.size()); + List data2(dataL.size()); + + std::copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); + etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(lower_bound_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + int* lb1 = std::lower_bound(std::begin(dataS), std::end(dataS), i); + int* lb2 = etlstd::lower_bound(std::begin(dataS), std::end(dataS), i); + + CHECK_EQUAL(lb1, lb2); + } + } + + //************************************************************************* + TEST(lower_bound_non_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + std::list::iterator lb1 = std::lower_bound(std::begin(dataSL), std::end(dataSL), i); + std::list::iterator lb2 = etlstd::lower_bound(std::begin(dataSL), std::end(dataSL), i); + + CHECK_EQUAL(std::distance(std::begin(dataSL), lb1), std::distance(std::begin(dataSL), lb2)); + } + } + + //************************************************************************* + TEST(upper_bound_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + int* lb1 = std::upper_bound(std::begin(dataS), std::end(dataS), i); + int* lb2 = etlstd::upper_bound(std::begin(dataS), std::end(dataS), i); + + CHECK_EQUAL(std::distance(std::begin(dataS), lb1), std::distance(std::begin(dataS), lb2)); + } + } + + //************************************************************************* + TEST(upper_bound_non_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + std::list::iterator lb1 = std::upper_bound(std::begin(dataSL), std::end(dataSL), i); + std::list::iterator lb2 = etlstd::upper_bound(std::begin(dataSL), std::end(dataSL), i); + + CHECK_EQUAL(std::distance(std::begin(dataSL), lb1), std::distance(std::begin(dataSL), lb2)); + } + } + + //************************************************************************* + TEST(equal_range_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + std::pair lb1 = std::equal_range(std::begin(dataEQ), std::end(dataEQ), i); + std::pair lb2 = etlstd::equal_range(std::begin(dataEQ), std::end(dataEQ), i); + + CHECK_EQUAL(std::distance(std::begin(dataEQ), lb1.first), std::distance(std::begin(dataEQ), lb2.first)); + CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance(lb2.first, lb2.second)); + } + } + + //************************************************************************* + TEST(equal_range_non_random_iterator) + { + for (int i = 0; i < 11; ++i) + { + std::pair::iterator, std::list::iterator> lb1 = std::equal_range(std::begin(dataEQL), std::end(dataEQL), i); + std::pair::iterator, std::list::iterator> lb2 = etlstd::equal_range(std::begin(dataEQL), std::end(dataEQL), i); + + CHECK_EQUAL(std::distance(std::begin(dataEQL), lb1.first), std::distance(std::begin(dataEQL), lb2.first)); + CHECK_EQUAL(std::distance(lb1.first, lb1.second), std::distance(lb2.first, lb2.second)); + } + } + + //************************************************************************* + TEST(fill_non_char) + { + int data1[10]; + int data2[10]; + + std::fill(std::begin(data1), std::end(data1), 0x12345678); + etlstd::fill(std::begin(data2), std::end(data2), 0x12345678); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(fill_char) + { + unsigned char data1[10]; + unsigned char data2[10]; + + std::fill(std::begin(data1), std::end(data1), char(0x12)); + etlstd::fill(std::begin(data2), std::end(data2), char(0x12)); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(swap) + { + int a = 1; + int b = 2; + + etlstd::swap(a, b); + CHECK_EQUAL(2, a); + CHECK_EQUAL(1, b); + } + + //************************************************************************* + TEST(iter_swap) + { + int a = 1; + int b = 2; + + etlstd::iter_swap(&a, &b); + CHECK_EQUAL(2, a); + CHECK_EQUAL(1, b); + } + + //************************************************************************* + TEST(equal) + { + CHECK(etlstd::equal(std::begin(dataV), std::end(dataV), std::begin(dataL))); + CHECK(!etlstd::equal(std::begin(dataSL), std::end(dataSL), std::begin(dataL))); + } + + //************************************************************************* + TEST(lexicographical_compare) + { + std::string text1("Hello World"); + std::string text2("Hello Xorld"); + + bool t1 = std::lexicographical_compare(text1.begin(), text1.end(), text2.begin(), text2.begin() + 7); + bool t2 = etlstd::lexicographical_compare(text1.begin(), text1.end(), text2.begin(), text2.begin() + 7); + + CHECK(t1 == t2); + } + + //************************************************************************* + TEST(lexicographical_compare_greater) + { + std::string text1("Hello World"); + std::string text2("Hello Xorld"); + + bool t1 = std::lexicographical_compare(text1.begin(), text1.end(), text2.begin(), text2.begin() + 7, Greater()); + bool t2 = etlstd::lexicographical_compare(text1.begin(), text1.end(), text2.begin(), text2.begin() + 7, Greater()); + + CHECK(t1 == t2); + } + + //************************************************************************* + TEST(search) + { + std::string haystack = "ABCDFEGHIJKLMNOPQRSTUVWXYZ"; + std::string needle = "KLMNO"; + + std::string::iterator itr1 = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin()); + std::string::iterator itr2 = etlstd::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin()); + + CHECK(itr1 == itr2); + } + + //************************************************************************* + TEST(search_predicate) + { + std::string haystack = "ABCDFEGHIJKLMNOPQRSTUVWXYZ"; + std::string needle = "KLMNO"; + + std::string::iterator itr1 = std::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin(), std::equal_to()); + std::string::iterator itr2 = etlstd::search(haystack.begin(), haystack.end(), needle.begin(), needle.begin(), std::equal_to()); + + CHECK(itr1 == itr2); + } + + //************************************************************************* + TEST(heap) + { + Vector data1 = dataV; + Vector data2 = dataV; + + std::make_heap(data1.begin(), data1.end()); + etlstd::make_heap(data2.begin(), data2.end()); + + bool isEqual; + + CHECK(std::is_heap(data2.begin(), data2.end())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + std::pop_heap(data1.begin(), data1.end()); + etlstd::pop_heap(data2.begin(), data2.end()); + + data1.pop_back(); + data2.pop_back(); + + CHECK(std::is_heap(data1.begin(), data1.end())); + CHECK(std::is_heap(data2.begin(), data2.end())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + CHECK(std::is_heap(data2.begin(), data2.end())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + data1.push_back(5); + data2.push_back(5); + + std::push_heap(data1.begin(), data1.end()); + etlstd::push_heap(data2.begin(), data2.end()); + + CHECK(std::is_heap(data2.begin(), data2.end())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + + //************************************************************************* + TEST(heap_greater) + { + Vector data1 = dataV; + Vector data2 = dataV; + + std::make_heap(data1.begin(), data1.end(), Greater()); + etlstd::make_heap(data2.begin(), data2.end(), Greater()); + + bool isEqual; + + CHECK(std::is_heap(data2.begin(), data2.end(), Greater())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + std::pop_heap(data1.begin(), data1.end(), Greater()); + etlstd::pop_heap(data2.begin(), data2.end(), Greater()); + + data1.pop_back(); + data2.pop_back(); + + CHECK(std::is_heap(data1.begin(), data1.end(), Greater())); + CHECK(std::is_heap(data2.begin(), data2.end(), Greater())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + CHECK(std::is_heap(data2.begin(), data2.end(), Greater())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + + data1.push_back(5); + data2.push_back(5); + + std::push_heap(data1.begin(), data1.end(), Greater()); + etlstd::push_heap(data2.begin(), data2.end(), Greater()); + + CHECK(std::is_heap(data2.begin(), data2.end(), Greater())); + + isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + }; +} diff --git a/test/test_no_stl_functional.cpp b/test/test_no_stl_functional.cpp new file mode 100644 index 00000000..8b92a715 --- /dev/null +++ b/test/test_no_stl_functional.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#undef min +#undef max + +#include "../include/etl/stl/alternate/functional.h" + +namespace +{ + template + bool compare(int a, int b) + { + return TCompare()(a, b); + } + + SUITE(test_no_stl_functional) + { + //************************************************************************* + TEST(test_less) + { + CHECK((compare>(1, 2))); + CHECK(!(compare>(2, 1))); + CHECK(!(compare>(1, 1))); + } + + //************************************************************************* + TEST(test_greater) + { + CHECK(!(compare>(1, 2))); + CHECK((compare>(2, 1))); + CHECK(!(compare>(1, 1))); + } + + //************************************************************************* + TEST(test_equal_to) + { + CHECK((compare>(1, 1))); + CHECK(!(compare>(1, 2))); + CHECK(!(compare>(2, 1))); + } + + //************************************************************************* + TEST(test_not_equal_to) + { + CHECK(!(compare>(1, 1))); + CHECK((compare>(1, 2))); + CHECK((compare>(2, 1))); + } + }; +} diff --git a/test/test_no_stl_limits.cpp b/test/test_no_stl_limits.cpp new file mode 100644 index 00000000..4035020b --- /dev/null +++ b/test/test_no_stl_limits.cpp @@ -0,0 +1,762 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#include "../include/etl/stl/alternate/limits.h" + +#include + +namespace +{ + SUITE(test_no_stl_limits) + { + //************************************************************************* + TEST(test_bool) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(STD::is_modulo, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_char) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_unsigned_char) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(true, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_signed_char) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_char16_t) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_char32_t) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_wchar_t) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(STD::is_modulo, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_short) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_unsigned_short) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(true, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_int) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_unsigned_int) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(true, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_long) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_unsigned_long) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(true, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_long_long) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_unsigned_long_long) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(STD::has_denorm_loss, ETL::has_denorm_loss); + CHECK_EQUAL(STD::has_infinity, ETL::has_infinity); + CHECK_EQUAL(STD::has_quiet_NaN, ETL::has_quiet_NaN); + CHECK_EQUAL(STD::has_signaling_NaN, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::infinity(), ETL::infinity()); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(true, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + CHECK_EQUAL(STD::tinyness_before, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + } + + //************************************************************************* + TEST(test_float) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(true, ETL::has_denorm_loss); + CHECK_EQUAL(false, ETL::has_infinity); + CHECK_EQUAL(false, ETL::has_quiet_NaN); + CHECK_EQUAL(false, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(true, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + + // CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + // CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + // CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + // CHECK_EQUAL(STD::infinity(), ETL::infinity()); + } + + //************************************************************************* + TEST(test_double) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(true, ETL::has_denorm_loss); + CHECK_EQUAL(false, ETL::has_infinity); + CHECK_EQUAL(false, ETL::has_quiet_NaN); + CHECK_EQUAL(false, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(true, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + + // CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + // CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + // CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + // CHECK_EQUAL(STD::infinity(), ETL::infinity()); + } + + //************************************************************************* + TEST(test_long_double) + { + typedef etlstd::numeric_limits ETL; + typedef std::numeric_limits STD; + + CHECK_EQUAL(STD::digits, ETL::digits); + CHECK_EQUAL(STD::digits10, ETL::digits10); + CHECK_EQUAL(STD::epsilon(), ETL::epsilon()); + CHECK_EQUAL(int(STD::has_denorm), int(ETL::has_denorm)); + CHECK_EQUAL(true, ETL::has_denorm_loss); + CHECK_EQUAL(false, ETL::has_infinity); + CHECK_EQUAL(false, ETL::has_quiet_NaN); + CHECK_EQUAL(false, ETL::has_signaling_NaN); + CHECK_EQUAL(STD::is_bounded, ETL::is_bounded); + CHECK_EQUAL(STD::is_exact, ETL::is_exact); + CHECK_EQUAL(STD::is_iec559, ETL::is_iec559); + CHECK_EQUAL(STD::is_integer, ETL::is_integer); + CHECK_EQUAL(false, ETL::is_modulo); + CHECK_EQUAL(STD::is_signed, ETL::is_signed); + CHECK_EQUAL(STD::is_specialized, ETL::is_specialized); + CHECK_EQUAL(STD::lowest(), ETL::lowest()); + CHECK_EQUAL(STD::max(), ETL::max()); + CHECK_EQUAL(STD::max_digits10, ETL::max_digits10); + CHECK_EQUAL(STD::max_exponent, ETL::max_exponent); + CHECK_EQUAL(STD::max_exponent10, ETL::max_exponent10); + CHECK_EQUAL(STD::min(), ETL::min()); + CHECK_EQUAL(STD::min_exponent, ETL::min_exponent); + CHECK_EQUAL(STD::min_exponent10, ETL::min_exponent10); + CHECK_EQUAL(STD::radix, ETL::radix); + CHECK_EQUAL(STD::round_error(), ETL::round_error()); + CHECK_EQUAL(int(STD::round_style), int(ETL::round_style)); + CHECK_EQUAL(true, ETL::tinyness_before); + CHECK_EQUAL(false, ETL::traps); + + // CHECK_EQUAL(STD::denorm_min(), ETL::denorm_min()); + // CHECK_EQUAL(STD::signaling_NaN(), ETL::signaling_NaN()); + // CHECK_EQUAL(STD::quiet_NaN(), ETL::quiet_NaN()); + // CHECK_EQUAL(STD::infinity(), ETL::infinity()); + } + }; +} diff --git a/test/test_no_stl_utility.cpp b/test/test_no_stl_utility.cpp new file mode 100644 index 00000000..441ef930 --- /dev/null +++ b/test/test_no_stl_utility.cpp @@ -0,0 +1,142 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2018 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++.h" + +#undef min +#undef max + +#include "../include/etl/stl/alternate/utility.h" + +namespace +{ + SUITE(test_no_stl_utility) + { + //************************************************************************* + TEST(pair_default_construct) + { + etlstd::pair p1; + + CHECK_EQUAL(int(), p1.first); + CHECK_EQUAL(double(), p1.second); + } + + //************************************************************************* + TEST(test_pair_construct) + { + etlstd::pair p1(1, 2.3); + + CHECK_EQUAL(1, p1.first); + CHECK_EQUAL(2.3, p1.second); + } + + //************************************************************************* + TEST(test_pair_copy_construct) + { + etlstd::pair p1(1, 2.3); + etlstd::pair p2(p1); + + CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.second, p2.second); + } + + //************************************************************************* + TEST(test_pair_copy_construct_alternate) + { + etlstd::pair p1(1, 2.3f); + etlstd::pair p2(p1); + + CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.second, p2.second); + } + + //************************************************************************* + TEST(test_make_pair) + { + etlstd::pair p1(1, 2.3); + etlstd::pair p2; + p2 = etlstd::make_pair(1, 2.3); + + CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.second, p2.second); + } + + //************************************************************************* + TEST(test_pair_swap_member) + { + etlstd::pair p1(1, 2.3); + etlstd::pair p2(2, 3.4); + + p1.swap(p2); + + CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(3.4, p1.second); + + CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(2.3, p2.second); + } + + //************************************************************************* + TEST(test_pair_swap_global) + { + etlstd::pair p1(1, 2.3); + etlstd::pair p2(2, 3.4); + + etlstd::swap(p1, p2); + + CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(3.4, p1.second); + + CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(2.3, p2.second); + } + + //************************************************************************* + TEST(test_pair_conditional) + { + etlstd::pair p1(1, 2.3); + etlstd::pair p2(1, 2.3); + etlstd::pair p3(2, 3.4); + + CHECK(p1 == p2); + CHECK(!(p1 == p3)); + CHECK(p1 != p3); + CHECK(!(p1 != p2)); + CHECK(p1 <= p2); + CHECK(p1 <= p3); + CHECK(!(p1 < p2)); + CHECK(p1 < p3); + CHECK(!(p3 < p1)); + CHECK(p1 >= p2); + CHECK(!(p1 >= p3)); + CHECK(!(p1 > p2)); + CHECK(!(p1 > p3)); + CHECK(p3 > p1); + } + }; +} diff --git a/test/vs2017/etl.vcxproj b/test/vs2017/etl.vcxproj index d5fc33a3..36cb1401 100644 --- a/test/vs2017/etl.vcxproj +++ b/test/vs2017/etl.vcxproj @@ -385,10 +385,15 @@ + + + + + @@ -402,6 +407,16 @@ + + + + + + + + + + @@ -549,6 +564,7 @@ + ../../../unittest-cpp ../../../unittest-cpp @@ -669,6 +685,9 @@ + + + false @@ -745,6 +764,7 @@ + diff --git a/test/vs2017/etl.vcxproj.filters b/test/vs2017/etl.vcxproj.filters index 78786739..52458239 100644 --- a/test/vs2017/etl.vcxproj.filters +++ b/test/vs2017/etl.vcxproj.filters @@ -73,6 +73,12 @@ {0bcdf7f9-8e2b-4f70-932b-bde56404f421} + + {86dc2850-2ddf-4582-9908-2436a1aa6e86} + + + {0d093ee6-686c-4c9e-856e-bdf7075ff7a6} + @@ -270,9 +276,6 @@ ETL\Containers - - ETL\Private - ETL\Utilities @@ -633,6 +636,54 @@ ETL\Profiles + + ETL\Private + + + ETL\STL\Alternate + + + ETL\STL\Alternate + + + ETL\STL + + + ETL\Profiles + + + ETL\Profiles + + + ETL\Profiles + + + ETL\Profiles + + + ETL\Profiles + + + ETL\STL\Alternate + + + ETL\STL + + + ETL\STL + + + ETL\STL\Alternate + + + ETL\STL + + + ETL\STL\Alternate + + + ETL\STL + @@ -1046,6 +1097,18 @@ UnitTest++\Win32 + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -1095,6 +1158,9 @@ Resource Files\Make + + Source Files +