From 47c47c5d328a2765bb6552fe295e35061e5aebbe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Jun 2018 19:43:20 +0100 Subject: [PATCH 01/13] Removed non-C++03 compliant function template default types. --- include/etl/array_view.h | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 7a9722c7..b56e21e5 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -123,8 +123,7 @@ namespace etl /// Construct from std::array or etl::array or other type that supports /// data() and size() member functions. //************************************************************************* - template ::value, void>::type> + template explicit array_view(TArray& a) : mbegin(a.data()), mend(a.data() + a.size()) @@ -134,8 +133,7 @@ namespace etl //************************************************************************* /// Construct from iterators //************************************************************************* - template ::value, void>::type> + template array_view(TIterator begin_, TIterator end_) : mbegin(etl::addressof(*begin_)), mend(etl::addressof(*begin_) + std::distance(begin_, end_)) @@ -146,8 +144,7 @@ namespace etl /// Construct from C array //************************************************************************* template ::value, void>::type> + typename TSize> array_view(TIterator begin_, TSize size_) : mbegin(etl::addressof(*begin_)), mend(etl::addressof(*begin_) + size_) @@ -354,24 +351,22 @@ namespace etl //************************************************************************* /// Assign from iterators //************************************************************************* - template ::value, void>::type> + template void assign(TIterator begin_, TIterator end_) { mbegin = etl::addressof(*begin_); - mend = etl::addressof(*begin_) + std::distance(begin_, end_); + mend = etl::addressof(*begin_) + std::distance(begin_, end_); } //************************************************************************* /// Assign from iterator and size. //************************************************************************* template ::value, void>::type> + typename TSize> void assign(TIterator begin_, TSize size_) { mbegin = etl::addressof(*begin_); - mend = etl::addressof(*begin_) + size_; + mend = etl::addressof(*begin_) + size_; } //************************************************************************* @@ -518,8 +513,7 @@ namespace etl /// Construct from std::array or etl::array or other type that supports /// data() and size() member functions. //************************************************************************* - template ::value, void>::type> + template explicit const_array_view(TArray& a) : mbegin(a.data()), mend(a.data() + a.size()) @@ -529,8 +523,7 @@ namespace etl //************************************************************************* /// Construct from iterators //************************************************************************* - template ::value, void>::type> + template const_array_view(TIterator begin_, TIterator end_) : mbegin(etl::addressof(*begin_)), mend(etl::addressof(*begin_) + std::distance(begin_, end_)) @@ -541,7 +534,7 @@ namespace etl /// Construct from C array //************************************************************************* template ::value, void>::type> + typename TSize> const_array_view(TIterator begin_, TSize size_) : mbegin(etl::addressof(*begin_)), mend(etl::addressof(*begin_) + size_) @@ -705,8 +698,7 @@ namespace etl //************************************************************************* /// Assign from iterators //************************************************************************* - template ::value, void>::type> + template void assign(TIterator begin_, TIterator end_) { mbegin = etl::addressof(*begin_); @@ -717,8 +709,7 @@ namespace etl /// Assign from iterator and size. //************************************************************************* template ::value, void>::type> + typename TSize> void assign(TIterator begin_, TSize size_) { mbegin = etl::addressof(*begin_); @@ -833,7 +824,7 @@ namespace etl size_t operator()(const etl::array_view& view) const { return etl::private_hash::generic_hash(reinterpret_cast(&view[0]), - reinterpret_cast(&view[view.size()])); + reinterpret_cast(&view[view.size()])); } }; @@ -843,7 +834,7 @@ namespace etl size_t operator()(const etl::const_array_view& view) const { return etl::private_hash::generic_hash(reinterpret_cast(&view[0]), - reinterpret_cast(&view[view.size()])); + reinterpret_cast(&view[view.size()])); } }; #endif From e23c485aa3fbe888b2871b7a7ecac75bae077f40 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Jun 2018 19:43:46 +0100 Subject: [PATCH 02/13] Added etl::less as default compare type. --- include/etl/map.h | 2 +- include/etl/multimap.h | 2 +- include/etl/multiset.h | 2 +- include/etl/priority_queue.h | 2 +- include/etl/set.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/etl/map.h b/include/etl/map.h index b04ffc87..de8d73a3 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -458,7 +458,7 @@ namespace etl /// A templated base for all etl::map types. ///\ingroup map //*************************************************************************** - template + template > class imap : public etl::map_base { public: diff --git a/include/etl/multimap.h b/include/etl/multimap.h index 6be6b681..2653eb88 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -614,7 +614,7 @@ namespace etl /// A templated base for all etl::multimap types. ///\ingroup map //*************************************************************************** - template + template > class imultimap : public etl::multimap_base { public: diff --git a/include/etl/multiset.h b/include/etl/multiset.h index e0be09db..2cecb26b 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -614,7 +614,7 @@ namespace etl /// A templated base for all etl::multiset types. ///\ingroup set //*************************************************************************** - template + template > class imultiset : public etl::multiset_base { public: diff --git a/include/etl/priority_queue.h b/include/etl/priority_queue.h index 42df8261..54bcd779 100644 --- a/include/etl/priority_queue.h +++ b/include/etl/priority_queue.h @@ -113,7 +113,7 @@ namespace etl /// \tparam TContainer to hold the T queue values /// \tparam TCompare to use in comparing T values //*************************************************************************** - template + template > class ipriority_queue { public: diff --git a/include/etl/set.h b/include/etl/set.h index 59283c0c..a6df4f39 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -453,7 +453,7 @@ namespace etl /// A templated base for all etl::set types. ///\ingroup set //*************************************************************************** - template + template > class iset : public etl::set_base { public: From 10453997a5bcb752d92edbcd06c159f23b635ae3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Jun 2018 20:08:18 +0100 Subject: [PATCH 03/13] Moved non-template code in pvoidvector to cpp file. --- include/etl/private/pvoidvector.h | 471 +++--------------------------- src/private/pvoidvector.cpp | 456 +++++++++++++++++++++++++++++ 2 files changed, 497 insertions(+), 430 deletions(-) diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 4cef3c8e..5997b2e6 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -74,246 +74,41 @@ namespace etl public: - //********************************************************************* - /// Returns an iterator to the beginning of the vector. - ///\return An iterator to the beginning of the vector. - //********************************************************************* - iterator begin() - { - return p_buffer; - } + iterator begin(); + const_iterator begin() const; - //********************************************************************* - /// Returns a const_iterator to the beginning of the vector. - ///\return A const iterator to the beginning of the vector. - //********************************************************************* - const_iterator begin() const - { - return const_iterator(p_buffer); - } + iterator end(); + const_iterator end() const; - //********************************************************************* - /// Returns an iterator to the end of the vector. - ///\return An iterator to the end of the vector. - //********************************************************************* - iterator end() - { - return p_end; - } + const_iterator cbegin() const; + const_iterator cend() const; - //********************************************************************* - /// Returns a const_iterator to the end of the vector. - ///\return A const iterator to the end of the vector. - //********************************************************************* - const_iterator end() const - { - return const_iterator(p_end); - } + reverse_iterator rbegin(); + const_reverse_iterator rbegin() const; - //********************************************************************* - /// Returns a const_iterator to the beginning of the vector. - ///\return A const iterator to the beginning of the vector. - //********************************************************************* - const_iterator cbegin() const - { - return const_iterator(p_buffer); - } + reverse_iterator rend(); + const_reverse_iterator rend() const; - //********************************************************************* - /// Returns a const_iterator to the end of the vector. - ///\return A const iterator to the end of the vector. - //********************************************************************* - const_iterator cend() const - { - return const_iterator(p_end); - } + const_reverse_iterator crbegin() const; + const_reverse_iterator crend() const; - //********************************************************************* - /// Returns an reverse iterator to the reverse beginning of the vector. - ///\return Iterator to the reverse beginning of the vector. - //********************************************************************* - reverse_iterator rbegin() - { - return reverse_iterator(end()); - } + void resize(size_t new_size); + void resize(size_t new_size, value_type value); - //********************************************************************* - /// Returns a const reverse iterator to the reverse beginning of the vector. - ///\return Const iterator to the reverse beginning of the vector. - //********************************************************************* - const_reverse_iterator rbegin() const - { - return const_reverse_iterator(end()); - } + reference operator [](size_t i); + const_reference operator [](size_t i) const; - //********************************************************************* - /// Returns a reverse iterator to the end + 1 of the vector. - ///\return Reverse iterator to the end + 1 of the vector. - //********************************************************************* - reverse_iterator rend() - { - return reverse_iterator(begin()); - } + reference at(size_t i); + const_reference at(size_t i) const; - //********************************************************************* - /// Returns a const reverse iterator to the end + 1 of the vector. - ///\return Const reverse iterator to the end + 1 of the vector. - //********************************************************************* - const_reverse_iterator rend() const - { - return const_reverse_iterator(begin()); - } + reference front(); + const_reference front() const; - //********************************************************************* - /// Returns a const reverse iterator to the reverse beginning of the vector. - ///\return Const reverse iterator to the reverse beginning of the vector. - //********************************************************************* - const_reverse_iterator crbegin() const - { - return const_reverse_iterator(cend()); - } + reference back(); + const_reference back() const; - //********************************************************************* - /// Returns a const reverse iterator to the end + 1 of the vector. - ///\return Const reverse iterator to the end + 1 of the vector. - //********************************************************************* - const_reverse_iterator crend() const - { - return const_reverse_iterator(cbegin()); - } - - //********************************************************************* - /// Resizes the vector. - /// If asserts or exceptions are enabled and the new size is larger than the - /// maximum then a vector_full is thrown. - ///\param new_size The new size. - //********************************************************************* - void resize(size_t new_size) - { - ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); - - p_end = p_buffer + new_size; - } - - //********************************************************************* - /// Resizes the vector. - /// If asserts or exceptions are enabled and the new size is larger than the - /// maximum then a vector_full is thrown. - ///\param new_size The new size. - ///\param value The value to fill new elements with. Default = default constructed value. - //********************************************************************* - void resize(size_t new_size, value_type value) - { - ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); - - pointer p_new_end = p_buffer + new_size; - - // Size up if necessary. - if (p_end < p_new_end) - { - std::fill(p_end, p_new_end, value); - } - - p_end = p_new_end; - } - - //********************************************************************* - /// Returns a reference to the value at index 'i' - ///\param i The index. - ///\return A reference to the value at index 'i' - //********************************************************************* - reference operator [](size_t i) - { - return p_buffer[i]; - } - - //********************************************************************* - /// Returns a const reference to the value at index 'i' - ///\param i The index. - ///\return A const reference to the value at index 'i' - //********************************************************************* - const_reference operator [](size_t i) const - { - return const_reference(p_buffer[i]); - } - - //********************************************************************* - /// Returns a reference to the value at index 'i' - /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. - ///\param i The index. - ///\return A reference to the value at index 'i' - //********************************************************************* - reference at(size_t i) - { - ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return p_buffer[i]; - } - - //********************************************************************* - /// Returns a const reference to the value at index 'i' - /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. - ///\param i The index. - ///\return A const reference to the value at index 'i' - //********************************************************************* - const_reference at(size_t i) const - { - ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return const_reference(p_buffer[i]); - } - - //********************************************************************* - /// Returns a reference to the first element. - ///\return A reference to the first element. - //********************************************************************* - reference front() - { - return p_buffer[0]; - } - - //********************************************************************* - /// Returns a const reference to the first element. - ///\return A const reference to the first element. - //********************************************************************* - const_reference front() const - { - return const_reference(p_buffer[0]); - } - - //********************************************************************* - /// Returns a reference to the last element. - ///\return A reference to the last element. - //********************************************************************* - reference back() - { - return *(p_end -1); - } - - //********************************************************************* - /// Returns a const reference to the last element. - ///\return A const reference to the last element. - //********************************************************************* - const_reference back() const - { - return const_reference(*(p_end - 1)); - } - - //********************************************************************* - /// Returns a pointer to the beginning of the vector data. - ///\return A pointer to the beginning of the vector data. - //********************************************************************* - pointer data() - { - return p_buffer; - } - - //********************************************************************* - /// Returns a const pointer to the beginning of the vector data. - ///\return A const pointer to the beginning of the vector data. - //********************************************************************* - const_pointer data() const - { - return const_pointer(p_buffer); - } + pointer data(); + const_pointer data() const; //********************************************************************* /// Assigns values to the vector. @@ -338,110 +133,17 @@ namespace etl } } - //********************************************************************* - /// Assigns values to the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. - ///\param n The number of elements to add. - ///\param value The value to insert for each element. - //********************************************************************* - void assign(size_t n, value_type value) - { - initialise(); + void assign(size_t n, value_type value); - ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full)); + void clear(); - for (size_t current_size = 0; current_size < n; ++current_size) - { - *p_end++ = value; - } - } + void push_back(); + void push_back(value_type value); - //************************************************************************* - /// Clears the vector. - //************************************************************************* - void clear() - { - initialise(); - } + void pop_back(); - //************************************************************************* - /// Increases the size of the vector by one, but does not initialise the new element. - /// If asserts or exceptions are enabled, throws a vector_full if the vector is already full. - //************************************************************************* - void push_back() - { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); -#endif - - ++p_end; - } - - //********************************************************************* - /// Inserts a value at the end of the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. - ///\param value The value to add. - //********************************************************************* - void push_back(value_type value) - { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); -#endif - *p_end++ = value; - } - - //************************************************************************* - /// Removes an element from the end of the vector. - /// Does nothing if the vector is empty. - //************************************************************************* - void pop_back() - { -#if defined(ETL_CHECK_PUSH_POP) - ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); -#endif - --p_end; - } - - //********************************************************************* - /// Inserts a value to the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. - ///\param position The position to insert before. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator position, value_type value) - { - ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full)); - - if (position != end()) - { - ++p_end; - std::copy_backward(position, end() - 1, end()); - *position = value; - } - else - { - *p_end++ = value; - } - - return position; - } - - //********************************************************************* - /// Inserts 'n' values to the vector. - /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. - ///\param position The position to insert before. - ///\param n The number of elements to add. - ///\param value The value to insert. - //********************************************************************* - void insert(iterator position, size_t n, value_type value) - { - ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full)); - - std::copy_backward(position, p_end, p_end + n); - std::fill_n(position, n, value); - - p_end += n; - } + iterator insert(iterator position, value_type value); + void insert(iterator position, size_t n, value_type value); //********************************************************************* /// Inserts a range of values to the vector. @@ -463,117 +165,26 @@ namespace etl p_end += count; } - //********************************************************************* - /// Erases an element. - ///\param i_element Iterator to the element. - ///\return An iterator pointing to the element that followed the erased element. - //********************************************************************* - iterator erase(iterator i_element) - { - std::copy(i_element + 1, end(), i_element); - --p_end; + iterator erase(iterator i_element); + iterator erase(iterator first, iterator last); - return i_element; - } + pvoidvector& operator = (const pvoidvector& rhs); - //********************************************************************* - /// Erases a range of elements. - /// The range includes all the elements between first and last, including the - /// element pointed by first, but not the one pointed by last. - ///\param first Iterator to the first element. - ///\param last Iterator to the last element. - ///\return An iterator pointing to the element that followed the erased element. - //********************************************************************* - iterator erase(iterator first, iterator last) - { - std::copy(last, end(), first); - size_t n_delete = std::distance(first, last); + size_type size() const; - // Just adjust the count. - p_end -= n_delete; + bool empty() const; - return first; - } + bool full() const; - //************************************************************************* - /// Assignment operator. - //************************************************************************* - pvoidvector& operator = (const pvoidvector& rhs) - { - if (&rhs != this) - { - assign(rhs.cbegin(), rhs.cend()); - } - - return *this; - } - - //************************************************************************* - /// Gets the current size of the vector. - ///\return The current size of the vector. - //************************************************************************* - size_type size() const - { - return size_t(p_end - p_buffer); - } - - //************************************************************************* - /// Checks the 'empty' state of the vector. - ///\return true if empty. - //************************************************************************* - bool empty() const - { - return (p_end == p_buffer); - } - - //************************************************************************* - /// Checks the 'full' state of the vector. - ///\return true if full. - //************************************************************************* - bool full() const - { - return size() == CAPACITY; - } - - //************************************************************************* - /// Returns the remaining capacity. - ///\return The remaining capacity. - //************************************************************************* - size_t available() const - { - return max_size() - size(); - } + size_t available() const; protected: - //********************************************************************* - /// Constructor. - //********************************************************************* - pvoidvector(void** p_buffer_, size_t MAX_SIZE) - : vector_base(MAX_SIZE), - p_buffer(p_buffer_), - p_end(p_buffer_) - { - } + pvoidvector(void** p_buffer_, size_t MAX_SIZE); - //********************************************************************* - /// Initialise the vector. - //********************************************************************* - void initialise() - { - p_end = p_buffer; - } + void initialise(); - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* - void repair(void** p_buffer_) - { - uintptr_t length = p_end - p_buffer; - - p_buffer = p_buffer_; - p_end = p_buffer_ + length; - } + void repair(void** p_buffer_); void** p_buffer; void** p_end; diff --git a/src/private/pvoidvector.cpp b/src/private/pvoidvector.cpp index 5b000adf..527abfbe 100644 --- a/src/private/pvoidvector.cpp +++ b/src/private/pvoidvector.cpp @@ -31,6 +31,462 @@ SOFTWARE. #include "../../include/etl/platform.h" #include "../../include/etl/private/pvoidvector.h" +//********************************************************************* +/// Returns an iterator to the beginning of the vector. +///\return An iterator to the beginning of the vector. +//********************************************************************* +etl::pvoidvector::iterator etl::pvoidvector::begin() +{ + return p_buffer; +} + +//********************************************************************* +/// Returns a const_iterator to the beginning of the vector. +///\return A const iterator to the beginning of the vector. +//********************************************************************* +etl::pvoidvector::const_iterator etl::pvoidvector::begin() const +{ + return const_iterator(p_buffer); +} + +//********************************************************************* +/// Returns an iterator to the end of the vector. +///\return An iterator to the end of the vector. +//********************************************************************* +etl::pvoidvector::iterator etl::pvoidvector::end() +{ + return p_end; +} + +//********************************************************************* +/// Returns a const_iterator to the end of the vector. +///\return A const iterator to the end of the vector. +//********************************************************************* +etl::pvoidvector::const_iterator etl::pvoidvector::end() const +{ + return const_iterator(p_end); +} + +//********************************************************************* +/// Returns a const_iterator to the beginning of the vector. +///\return A const iterator to the beginning of the vector. +//********************************************************************* +etl::pvoidvector::const_iterator etl::pvoidvector::cbegin() const +{ + return const_iterator(p_buffer); +} + +//********************************************************************* +/// Returns a const_iterator to the end of the vector. +///\return A const iterator to the end of the vector. +//********************************************************************* +etl::pvoidvector::const_iterator etl::pvoidvector::cend() const +{ + return const_iterator(p_end); +} + +//********************************************************************* +/// Returns an reverse iterator to the reverse beginning of the vector. +///\return Iterator to the reverse beginning of the vector. +//********************************************************************* +etl::pvoidvector::reverse_iterator etl::pvoidvector::rbegin() +{ + return reverse_iterator(end()); +} + +//********************************************************************* +/// Returns a const reverse iterator to the reverse beginning of the vector. +///\return Const iterator to the reverse beginning of the vector. +//********************************************************************* +etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rbegin() const +{ + return const_reverse_iterator(end()); +} + +//********************************************************************* +/// Returns a reverse iterator to the end + 1 of the vector. +///\return Reverse iterator to the end + 1 of the vector. +//********************************************************************* +etl::pvoidvector::reverse_iterator etl::pvoidvector::rend() +{ + return reverse_iterator(begin()); +} + +//********************************************************************* +/// Returns a const reverse iterator to the end + 1 of the vector. +///\return Const reverse iterator to the end + 1 of the vector. +//********************************************************************* +etl::pvoidvector::const_reverse_iterator etl::pvoidvector::rend() const +{ + return const_reverse_iterator(begin()); +} + +//********************************************************************* +/// Returns a const reverse iterator to the reverse beginning of the vector. +///\return Const reverse iterator to the reverse beginning of the vector. +//********************************************************************* +etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crbegin() const +{ + return const_reverse_iterator(cend()); +} + +//********************************************************************* +/// Returns a const reverse iterator to the end + 1 of the vector. +///\return Const reverse iterator to the end + 1 of the vector. +//********************************************************************* +etl::pvoidvector::const_reverse_iterator etl::pvoidvector::crend() const +{ + return const_reverse_iterator(cbegin()); +} + +//********************************************************************* +/// Resizes the vector. +/// If asserts or exceptions are enabled and the new size is larger than the +/// maximum then a vector_full is thrown. +///\param new_size The new size. +//********************************************************************* +void etl::pvoidvector::resize(size_t new_size) +{ + ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); + + p_end = p_buffer + new_size; +} + +//********************************************************************* +/// Resizes the vector. +/// If asserts or exceptions are enabled and the new size is larger than the +/// maximum then a vector_full is thrown. +///\param new_size The new size. +///\param value The value to fill new elements with. Default = default constructed value. +//********************************************************************* +void etl::pvoidvector::resize(size_t new_size, etl::pvoidvector::value_type value) +{ + ETL_ASSERT(new_size <= CAPACITY, ETL_ERROR(vector_full)); + + pointer p_new_end = p_buffer + new_size; + + // Size up if necessary. + if (p_end < p_new_end) + { + std::fill(p_end, p_new_end, value); + } + + p_end = p_new_end; +} + +//********************************************************************* +/// Returns a reference to the value at index 'i' +///\param i The index. +///\return A reference to the value at index 'i' +//********************************************************************* +etl::pvoidvector::reference etl::pvoidvector::operator [](size_t i) +{ + return p_buffer[i]; +} + +//********************************************************************* +/// Returns a const reference to the value at index 'i' +///\param i The index. +///\return A const reference to the value at index 'i' +//********************************************************************* +etl::pvoidvector::const_reference etl::pvoidvector::operator [](size_t i) const +{ + return const_reference(p_buffer[i]); +} + +//********************************************************************* +/// Returns a reference to the value at index 'i' +/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. +///\param i The index. +///\return A reference to the value at index 'i' +//********************************************************************* +etl::pvoidvector::reference etl::pvoidvector::at(size_t i) +{ + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); + return p_buffer[i]; +} + +//********************************************************************* +/// Returns a const reference to the value at index 'i' +/// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. +///\param i The index. +///\return A const reference to the value at index 'i' +//********************************************************************* +etl::pvoidvector::const_reference etl::pvoidvector::at(size_t i) const +{ + ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); + return const_reference(p_buffer[i]); +} + +//********************************************************************* +/// Returns a reference to the first element. +///\return A reference to the first element. +//********************************************************************* +etl::pvoidvector::reference etl::pvoidvector::front() +{ + return p_buffer[0]; +} + +//********************************************************************* +/// Returns a const reference to the first element. +///\return A const reference to the first element. +//********************************************************************* +etl::pvoidvector::const_reference etl::pvoidvector::front() const +{ + return const_reference(p_buffer[0]); +} + +//********************************************************************* +/// Returns a reference to the last element. +///\return A reference to the last element. +//********************************************************************* +etl::pvoidvector::reference etl::pvoidvector::back() +{ + return *(p_end - 1); +} + +//********************************************************************* +/// Returns a const reference to the last element. +///\return A const reference to the last element. +//********************************************************************* +etl::pvoidvector::const_reference etl::pvoidvector::back() const +{ + return const_reference(*(p_end - 1)); +} + +//********************************************************************* +/// Returns a pointer to the beginning of the vector data. +///\return A pointer to the beginning of the vector data. +//********************************************************************* +etl::pvoidvector::pointer etl::pvoidvector::data() +{ + return p_buffer; +} + +//********************************************************************* +/// Returns a const pointer to the beginning of the vector data. +///\return A const pointer to the beginning of the vector data. +//********************************************************************* +etl::pvoidvector::const_pointer etl::pvoidvector::data() const +{ + return const_pointer(p_buffer); +} + +//********************************************************************* +/// Assigns values to the vector. +/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. +///\param n The number of elements to add. +///\param value The value to insert for each element. +//********************************************************************* +void etl::pvoidvector::assign(size_t n, etl::pvoidvector::value_type value) +{ + initialise(); + + ETL_ASSERT(n <= CAPACITY, ETL_ERROR(vector_full)); + + for (size_t current_size = 0; current_size < n; ++current_size) + { + *p_end++ = value; + } +} + +//************************************************************************* +/// Clears the vector. +//************************************************************************* +void etl::pvoidvector::clear() +{ + initialise(); +} + +//************************************************************************* +/// Increases the size of the vector by one, but does not initialise the new element. +/// If asserts or exceptions are enabled, throws a vector_full if the vector is already full. +//************************************************************************* +void etl::pvoidvector::push_back() +{ +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); +#endif + + ++p_end; +} + +//********************************************************************* +/// Inserts a value at the end of the vector. +/// If asserts or exceptions are enabled, emits vector_full if the vector is already full. +///\param value The value to add. +//********************************************************************* +void etl::pvoidvector::push_back(etl::pvoidvector::value_type value) +{ +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); +#endif + *p_end++ = value; +} + +//************************************************************************* +/// Removes an element from the end of the vector. +/// Does nothing if the vector is empty. +//************************************************************************* +void etl::pvoidvector::pop_back() +{ +#if defined(ETL_CHECK_PUSH_POP) + ETL_ASSERT(size() > 0, ETL_ERROR(vector_empty)); +#endif + --p_end; +} + +//********************************************************************* +/// Inserts a value to the vector. +/// If asserts or exceptions are enabled, emits vector_full if the vector is already full. +///\param position The position to insert before. +///\param value The value to insert. +//********************************************************************* +etl::pvoidvector::iterator etl::pvoidvector::insert(etl::pvoidvector::iterator position, etl::pvoidvector::value_type value) +{ + ETL_ASSERT(size() + 1 <= CAPACITY, ETL_ERROR(vector_full)); + + if (position != end()) + { + ++p_end; + std::copy_backward(position, end() - 1, end()); + *position = value; + } + else + { + *p_end++ = value; + } + + return position; +} + +//********************************************************************* +/// Inserts 'n' values to the vector. +/// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. +///\param position The position to insert before. +///\param n The number of elements to add. +///\param value The value to insert. +//********************************************************************* +void etl::pvoidvector::insert(etl::pvoidvector::iterator position, size_t n, etl::pvoidvector::value_type value) +{ + ETL_ASSERT((size() + 1) <= CAPACITY, ETL_ERROR(vector_full)); + + std::copy_backward(position, p_end, p_end + n); + std::fill_n(position, n, value); + + p_end += n; +} + +//********************************************************************* +/// Erases an element. +///\param i_element Iterator to the element. +///\return An iterator pointing to the element that followed the erased element. +//********************************************************************* +etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator i_element) +{ + std::copy(i_element + 1, end(), i_element); + --p_end; + + return i_element; +} + +//********************************************************************* +/// Erases a range of elements. +/// The range includes all the elements between first and last, including the +/// element pointed by first, but not the one pointed by last. +///\param first Iterator to the first element. +///\param last Iterator to the last element. +///\return An iterator pointing to the element that followed the erased element. +//********************************************************************* +etl::pvoidvector::iterator etl::pvoidvector::erase(etl::pvoidvector::iterator first, etl::pvoidvector::iterator last) +{ + std::copy(last, end(), first); + size_t n_delete = std::distance(first, last); + + // Just adjust the count. + p_end -= n_delete; + + return first; +} + +//************************************************************************* +/// Assignment operator. +//************************************************************************* +etl::pvoidvector& etl::pvoidvector::operator = (const etl::pvoidvector& rhs) +{ + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; +} + +//************************************************************************* +/// Gets the current size of the vector. +///\return The current size of the vector. +//************************************************************************* +etl::pvoidvector::size_type etl::pvoidvector::size() const +{ + return size_t(p_end - p_buffer); +} + +//************************************************************************* +/// Checks the 'empty' state of the vector. +///\return true if empty. +//************************************************************************* +bool etl::pvoidvector::empty() const +{ + return (p_end == p_buffer); +} + +//************************************************************************* +/// Checks the 'full' state of the vector. +///\return true if full. +//************************************************************************* +bool etl::pvoidvector::full() const +{ + return size() == CAPACITY; +} + +//************************************************************************* +/// Returns the remaining capacity. +///\return The remaining capacity. +//************************************************************************* +size_t etl::pvoidvector::available() const +{ + return max_size() - size(); +} + +//********************************************************************* +/// Constructor. +//********************************************************************* +etl::pvoidvector::pvoidvector(void** p_buffer_, size_t MAX_SIZE) + : vector_base(MAX_SIZE), + p_buffer(p_buffer_), + p_end(p_buffer_) +{ +} + +//********************************************************************* +/// Initialise the vector. +//********************************************************************* +void etl::pvoidvector::initialise() +{ + p_end = p_buffer; +} + +//************************************************************************* +/// Fix the internal pointers after a low level memory copy. +//************************************************************************* +void etl::pvoidvector::repair(void** p_buffer_) +{ + uintptr_t length = p_end - p_buffer; + + p_buffer = p_buffer_; + p_end = p_buffer_ + length; +} + namespace etl { //*************************************************************************** From 48fa8f346ceecc49b76f3edae1ac22c464181465 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Jun 2018 20:08:45 +0100 Subject: [PATCH 04/13] Updated version and release notes --- include/etl/version.h | 4 ++-- support/Release notes.txt | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index c13c8c8e..cb827822 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.12.1" +#define ETL_VERSION "11.12.2" #define ETL_VERSION_MAJOR 11 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_PATCH 2 #endif diff --git a/support/Release notes.txt b/support/Release notes.txt index 7ef5910e..79e74a7d 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,9 @@ +=============================================================================== +11.12.2 +Remove SFINAE from array_view. +Added default etl::less compare type appropriate map and set classes. +Moved non-template code in pvoidvector to cpp file. + =============================================================================== 11.12.1 Made atomic load const for non STL vesions From d9589351e7193b709dbd675106e2a30a6547e22c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 3 Jul 2018 22:13:11 +0100 Subject: [PATCH 05/13] Added specialisation for vector --- include/etl/private/ivectorpointer.h | 402 ++++++++++++ include/etl/version.h | 6 +- support/Release notes.txt | 4 + test/test_vector_pointer.cpp | 902 +++++++++++++++++++++++++-- 4 files changed, 1275 insertions(+), 39 deletions(-) diff --git a/include/etl/private/ivectorpointer.h b/include/etl/private/ivectorpointer.h index 6dcda8f3..9ef26977 100644 --- a/include/etl/private/ivectorpointer.h +++ b/include/etl/private/ivectorpointer.h @@ -446,6 +446,408 @@ namespace etl } }; + template + class ivector : public pvoidvector + { + public: + + typedef const T* value_type; + typedef const T*& reference; + typedef const T* const & const_reference; + typedef const T** pointer; + typedef const T* const * const_pointer; + typedef const T** iterator; + typedef const T* const * const_iterator; + typedef std::reverse_iterator reverse_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef size_t size_type; + typedef typename std::iterator_traits::difference_type difference_type; + + protected: + + typedef value_type parameter_t; + + private: + + typedef pvoidvector base_t; + + public: + + //********************************************************************* + /// Returns an iterator to the beginning of the vector. + ///\return An iterator to the beginning of the vector. + //********************************************************************* + iterator begin() + { + return iterator(base_t::begin()); + } + + //********************************************************************* + /// Returns a const_iterator to the beginning of the vector. + ///\return A const iterator to the beginning of the vector. + //********************************************************************* + const_iterator begin() const + { + return const_iterator(base_t::begin()); + } + + //********************************************************************* + /// Returns an iterator to the end of the vector. + ///\return An iterator to the end of the vector. + //********************************************************************* + iterator end() + { + return iterator(base_t::end()); + } + + //********************************************************************* + /// Returns a const_iterator to the end of the vector. + ///\return A const iterator to the end of the vector. + //********************************************************************* + const_iterator end() const + { + return const_iterator(base_t::end()); + } + + //********************************************************************* + /// Returns a const_iterator to the beginning of the vector. + ///\return A const iterator to the beginning of the vector. + //********************************************************************* + const_iterator cbegin() const + { + return const_iterator(base_t::cbegin()); + } + + //********************************************************************* + /// Returns a const_iterator to the end of the vector. + ///\return A const iterator to the end of the vector. + //********************************************************************* + const_iterator cend() const + { + return const_iterator(base_t::cend()); + } + + //********************************************************************* + /// Returns an reverse iterator to the reverse beginning of the vector. + ///\return Iterator to the reverse beginning of the vector. + //********************************************************************* + reverse_iterator rbegin() + { + return reverse_iterator(iterator(base_t::end())); + } + + //********************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the vector. + ///\return Const iterator to the reverse beginning of the vector. + //********************************************************************* + const_reverse_iterator rbegin() const + { + return const_reverse_iterator(const_iterator(base_t::end())); + } + + //********************************************************************* + /// Returns a reverse iterator to the end + 1 of the vector. + ///\return Reverse iterator to the end + 1 of the vector. + //********************************************************************* + reverse_iterator rend() + { + return reverse_iterator(iterator(base_t::begin())); + } + + //********************************************************************* + /// Returns a const reverse iterator to the end + 1 of the vector. + ///\return Const reverse iterator to the end + 1 of the vector. + //********************************************************************* + const_reverse_iterator rend() const + { + return const_reverse_iterator(const_iterator(base_t::begin())); + } + + //********************************************************************* + /// Returns a const reverse iterator to the reverse beginning of the vector. + ///\return Const reverse iterator to the reverse beginning of the vector. + //********************************************************************* + const_reverse_iterator crbegin() const + { + return const_reverse_iterator(const_iterator(base_t::cend())); + } + + //********************************************************************* + /// Returns a const reverse iterator to the end + 1 of the vector. + ///\return Const reverse iterator to the end + 1 of the vector. + //********************************************************************* + const_reverse_iterator crend() const + { + return const_reverse_iterator(const_iterator(base_t::cbegin())); + } + + //********************************************************************* + /// Resizes the vector. + /// If asserts or exceptions are enabled and the new size is larger than the + /// maximum then a vector_full is thrown. + ///\param new_size The new size. + //********************************************************************* + void resize(size_t new_size) + { + base_t::resize(new_size); + } + + //********************************************************************* + /// Resizes the vector. + /// If asserts or exceptions are enabled and the new size is larger than the + /// maximum then a vector_full is thrown. + ///\param new_size The new size. + ///\param value The value to fill new elements with. Default = default constructed value. + //********************************************************************* + void resize(size_t new_size, value_type value) + { + base_t::resize(new_size, const_cast(value)); + } + + //********************************************************************* + /// Returns a reference to the value at index 'i' + ///\param i The index. + ///\return A reference to the value at index 'i' + //********************************************************************* + reference operator [](size_t i) + { + return reference(base_t::operator[](i)); + } + + //********************************************************************* + /// Returns a const reference to the value at index 'i' + ///\param i The index. + ///\return A const reference to the value at index 'i' + //********************************************************************* + const_reference operator [](size_t i) const + { + return const_reference(base_t::operator[](i)); + } + + //********************************************************************* + /// Returns a reference to the value at index 'i' + /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. + ///\param i The index. + ///\return A reference to the value at index 'i' + //********************************************************************* + reference at(size_t i) + { + return reference(base_t::at(i)); + } + + //********************************************************************* + /// Returns a const reference to the value at index 'i' + /// If asserts or exceptions are enabled, emits an etl::vector_out_of_bounds if the index is out of range. + ///\param i The index. + ///\return A const reference to the value at index 'i' + //********************************************************************* + const_reference at(size_t i) const + { + return const_reference(base_t::at(i)); + } + + //********************************************************************* + /// Returns a reference to the first element. + ///\return A reference to the first element. + //********************************************************************* + reference front() + { + return reference(base_t::front()); + } + + //********************************************************************* + /// Returns a const reference to the first element. + ///\return A const reference to the first element. + //********************************************************************* + const_reference front() const + { + return const_reference(base_t::front()); + } + + //********************************************************************* + /// Returns a reference to the last element. + ///\return A reference to the last element. + //********************************************************************* + reference back() + { + return reference(base_t::back()); + } + + //********************************************************************* + /// Returns a const reference to the last element. + ///\return A const reference to the last element. + //********************************************************************* + const_reference back() const + { + return const_reference(base_t::back()); + } + + //********************************************************************* + /// Returns a pointer to the beginning of the vector data. + ///\return A pointer to the beginning of the vector data. + //********************************************************************* + pointer data() + { + return pointer(base_t::data()); + } + + //********************************************************************* + /// Returns a const pointer to the beginning of the vector data. + ///\return A const pointer to the beginning of the vector data. + //********************************************************************* + const_pointer data() const + { + return const_pointer(base_t::data()); + } + + //********************************************************************* + /// Assigns values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + /// If asserts or exceptions are enabled, emits vector_iterator if the iterators are reversed. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //********************************************************************* + template + void assign(TIterator first, TIterator last) + { + base_t::initialise(); + + while (first != last) + { + *p_end++ = (void*)*first++; + } + } + + //********************************************************************* + /// Assigns values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + ///\param n The number of elements to add. + ///\param value The value to insert for each element. + //********************************************************************* + void assign(size_t n, parameter_t value) + { + base_t::assign(n, const_cast(value)); + } + + //************************************************************************* + /// Clears the vector. + //************************************************************************* + void clear() + { + base_t::clear(); + } + + //************************************************************************* + /// Increases the size of the vector by one, but does not initialise the new element. + /// If asserts or exceptions are enabled, throws a vector_full if the vector is already full. + //************************************************************************* + void push_back() + { + base_t::push_back(); + } + + //********************************************************************* + /// Inserts a value at the end of the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. + ///\param value The value to add. + //********************************************************************* + void push_back(parameter_t value) + { + base_t::push_back(const_cast(value)); + } + + //************************************************************************* + /// Removes an element from the end of the vector. + /// Does nothing if the vector is empty. + //************************************************************************* + void pop_back() + { + base_t::pop_back(); + } + + //********************************************************************* + /// Inserts a value to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. + ///\param position The position to insert before. + ///\param value The value to insert. + //********************************************************************* + iterator insert(iterator position, parameter_t value) + { + return iterator(base_t::insert(base_t::iterator(position), const_cast(value))); + } + + //********************************************************************* + /// Inserts 'n' values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + ///\param position The position to insert before. + ///\param n The number of elements to add. + ///\param value The value to insert. + //********************************************************************* + void insert(iterator position, size_t n, parameter_t value) + { + base_t::insert(base_t::iterator(position), n, const_cast(value)); + } + + //********************************************************************* + /// Inserts a range of values to the vector. + /// If asserts or exceptions are enabled, emits vector_full if the vector does not have enough free space. + ///\param position The position to insert before. + ///\param first The first element to add. + ///\param last The last + 1 element to add. + //********************************************************************* + template + void insert(iterator position, TIterator first, TIterator last) + { + base_t::insert(base_t::iterator(position), first, last); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(iterator i_element) + { + return iterator(base_t::erase(base_t::iterator(i_element))); + } + + //********************************************************************* + /// Erases a range of elements. + /// The range includes all the elements between first and last, including the + /// element pointed by first, but not the one pointed by last. + ///\param first Iterator to the first element. + ///\param last Iterator to the last element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(iterator first, iterator last) + { + return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last))); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + ivector& operator = (const ivector& rhs) + { + if (&rhs != this) + { + assign(rhs.cbegin(), rhs.cend()); + } + + return *this; + } + + protected: + + //********************************************************************* + /// Constructor. + //********************************************************************* + ivector(const T** p_buffer_, size_t MAX_SIZE_) + : pvoidvector(reinterpret_cast(const_cast(p_buffer_)), MAX_SIZE_) + { + } + }; + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first vector. diff --git a/include/etl/version.h b/include/etl/version.h index cb827822..9043d8f3 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.12.2" +#define ETL_VERSION "11.13.0" #define ETL_VERSION_MAJOR 11 -#define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_MINOR 13 +#define ETL_VERSION_PATCH 0 #endif diff --git a/support/Release notes.txt b/support/Release notes.txt index 79e74a7d..315fa97c 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +11.13.0 +Added specialisation for vector + =============================================================================== 11.12.2 Remove SFINAE from array_view. diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 970d2263..eeac0e8c 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -41,9 +41,12 @@ namespace { static const size_t SIZE = 10; - typedef etl::vector Data; - typedef etl::ivector IData; - typedef std::vector Compare_Data; + typedef etl::vector Data; + typedef etl::vector CData; + typedef etl::ivector IData; + typedef etl::ivector CIData; + typedef std::vector Compare_Data; + typedef std::vector CCompare_Data; Compare_Data initial_data; Compare_Data less_data; @@ -97,6 +100,17 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_default_constructor) + { + CData data; + + CHECK_EQUAL(data.size(), size_t(0)); + CHECK(data.empty()); + CHECK_EQUAL(data.capacity(), SIZE); + CHECK_EQUAL(data.max_size(), SIZE); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { @@ -108,6 +122,17 @@ namespace CHECK(data.crbegin() == data.crend()); } + //************************************************************************* + TEST(test_const_iterator_comparison_empty) + { + CData data; + + CHECK(data.begin() == data.end()); + CHECK(data.cbegin() == data.cend()); + CHECK(data.rbegin() == data.rend()); + CHECK(data.crbegin() == data.crend()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size) { @@ -118,6 +143,16 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_constructor_size) + { + const size_t INITIAL_SIZE = 5; + CData data(INITIAL_SIZE); + + CHECK(data.size() == INITIAL_SIZE); + CHECK(!data.empty()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { @@ -137,12 +172,37 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_constructor_size_value) + { + const size_t INITIAL_SIZE = 5; + int INITIAL_VALUE = 1; + + std::array compare_data; + compare_data.fill(&INITIAL_VALUE); + + CData data(INITIAL_SIZE, &INITIAL_VALUE); + + CHECK(data.size() == INITIAL_SIZE); + CHECK(!data.empty()); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_excess) { CHECK_THROW(Data data(SIZE + 1), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_constructor_size_excess) + { + CHECK_THROW(CData data(SIZE + 1), etl::vector_full); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { @@ -155,6 +215,18 @@ namespace CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_constructor_range) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + CHECK(data.size() == SIZE); + CHECK(!data.empty()); + CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); + } + //************************************************************************* TEST(test_constructor_initializer_list) { @@ -170,6 +242,21 @@ namespace CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST(test_const_constructor_initializer_list) + { + int a = 0; + int b = 1; + int c = 3; + int d = 4; + + CCompare_Data compare_data = { &a, &b, &c, &d }; + CData data = { &a, &b, &c, &d }; + + CHECK_EQUAL(compare_data.size(), data.size()); + CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { @@ -181,6 +268,17 @@ namespace CHECK(data2 != data); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_copy_constructor) + { + CData data(initial_data.begin(), initial_data.end()); + CData data2(data); + CHECK(data2 == data); + + data2[2] = nullptr; + CHECK(data2 != data); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { @@ -194,6 +292,19 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_assignment) + { + CData data(initial_data.begin(), initial_data.end()); + CData other_data; + + other_data = data; + + bool is_equal = std::equal(data.begin(), data.end(), other_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment_iterface) { @@ -210,6 +321,22 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_assignment_iterface) + { + CData data1(initial_data.begin(), initial_data.end()); + CData data2; + + CIData& idata1 = data1; + CIData& idata2 = data2; + + idata2 = idata1; + + bool is_equal = std::equal(data1.begin(), data1.end(), data2.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_self_assignment) { @@ -223,6 +350,19 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_self_assignment) + { + CData data(initial_data.begin(), initial_data.end()); + CData other_data(data); + + other_data = other_data; + + bool is_equal = std::equal(data.begin(), data.end(), other_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -233,6 +373,16 @@ namespace CHECK_EQUAL(&constData[0], constData.begin()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_begin) + { + CData data(10); + const CData constData(10); + + CHECK_EQUAL(&data[0], data.begin()); + CHECK_EQUAL(&constData[0], constData.begin()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { @@ -243,6 +393,16 @@ namespace CHECK_EQUAL(&constData[10], constData.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_end) + { + CData data(10); + const CData constData(10); + + CHECK_EQUAL(&data[10], data.end()); + CHECK_EQUAL(&constData[10], constData.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { @@ -255,6 +415,18 @@ namespace CHECK_EQUAL(data.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_resize_up) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 8; + + CData data(INITIAL_SIZE); + data.resize(NEW_SIZE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { @@ -273,6 +445,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_resize_up_value) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 8; + int INITIAL_VALUE = 1; + + CData data(INITIAL_SIZE, &INITIAL_VALUE); + data.resize(NEW_SIZE, &INITIAL_VALUE); + + std::array compare_data; + compare_data.fill(&INITIAL_VALUE); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { @@ -284,6 +474,17 @@ namespace CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_resize_excess) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = SIZE + 1; + + CData data(INITIAL_SIZE); + + CHECK_THROW(data.resize(NEW_SIZE), etl::vector_full); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { @@ -296,6 +497,18 @@ namespace CHECK_EQUAL(data.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_resize_down) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 2; + + CData data(INITIAL_SIZE); + data.resize(NEW_SIZE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { @@ -309,6 +522,19 @@ namespace CHECK_EQUAL(data.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_resize_down_value) + { + const size_t INITIAL_SIZE = 5; + const size_t NEW_SIZE = 2; + int INITIAL_VALUE = 1; + + CData data(INITIAL_SIZE); + data.resize(NEW_SIZE, &INITIAL_VALUE); + + CHECK_EQUAL(data.size(), NEW_SIZE); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty) { @@ -319,6 +545,16 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_empty) + { + CData data; + data.resize(data.max_size()); + + CHECK(data.full()); + CHECK(!data.empty()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_full) { @@ -328,6 +564,15 @@ namespace CHECK(data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_full) + { + CData data; + + CHECK(!data.full()); + CHECK(data.empty()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { @@ -341,6 +586,19 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_index) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data[i], compare_data[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { @@ -354,6 +612,19 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_index_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + const CData data(compare_data.begin(), compare_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data[i], compare_data[i]); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { @@ -368,6 +639,20 @@ namespace CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_at) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data.at(i), compare_data.at(i)); + } + + CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { @@ -382,6 +667,20 @@ namespace CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_at_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + const CData data(initial_data.begin(), initial_data.end()); + + for (size_t i = 0; i < data.size(); ++i) + { + CHECK_EQUAL(data.at(i), compare_data.at(i)); + } + + CHECK_THROW(data.at(data.size()), etl::vector_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { @@ -391,6 +690,15 @@ namespace CHECK(data.front() == compare_data.front()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_front) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + CHECK(data.front() == compare_data.front()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { @@ -400,6 +708,15 @@ namespace CHECK(data.front() == compare_data.front()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_front_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + const CData data(initial_data.begin(), initial_data.end()); + + CHECK(data.front() == compare_data.front()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { @@ -409,6 +726,15 @@ namespace CHECK(data.back() == compare_data.back()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_back) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + CHECK(data.back() == compare_data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { @@ -418,6 +744,14 @@ namespace CHECK(data.back() == compare_data.back()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_back_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + const CData data(initial_data.begin(), initial_data.end()); + + CHECK(data.back() == compare_data.back()); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) @@ -431,6 +765,18 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_data) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.data(), data.data() + data.size(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { @@ -443,6 +789,18 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_data_const) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + const CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.data(), data.data() + data.size(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { @@ -457,6 +815,20 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_assign_range) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data; + + data.assign(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { @@ -473,6 +845,22 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_assign_size_value) + { + const size_t INITIAL_SIZE = 5; + int INITIAL_VALUE = 1; + std::array compare_data; + compare_data.fill(&INITIAL_VALUE); + + CData data; + data.assign(INITIAL_SIZE, &INITIAL_VALUE); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) { @@ -487,6 +875,20 @@ namespace CHECK_THROW(data.assign(EXCESS_SIZE, &INITIAL_VALUE), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_assign_size_value_excess) + { + const size_t INITIAL_SIZE = SIZE; + const size_t EXCESS_SIZE = SIZE + 1; + int INITIAL_VALUE = 1; + std::array compare_data; + compare_data.fill(&INITIAL_VALUE); + + CData data; + + CHECK_THROW(data.assign(EXCESS_SIZE, &INITIAL_VALUE), etl::vector_full); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { @@ -510,6 +912,29 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_push_back) + { + CCompare_Data compare_data; + CData data; + + const int d = 0; + + for (size_t i = 0; i < SIZE; ++i) + { + compare_data.push_back(&d); + } + + for (size_t i = 0; i < SIZE; ++i) + { + data.push_back(&d); + } + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_null) { @@ -528,6 +953,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_push_back_null) + { + CCompare_Data compare_data; + CData data; + + const int d = 0; + + compare_data.push_back(&d); + + data.push_back(); + data[0] = &d; + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { @@ -543,6 +986,21 @@ namespace CHECK_THROW(data.push_back(&d), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_push_back_excess) + { + CData data; + + const int d = 0; + + for (size_t i = 0; i < SIZE; ++i) + { + data.push_back(&d); + } + + CHECK_THROW(data.push_back(&d), etl::vector_full); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { @@ -555,9 +1013,24 @@ namespace data.pop_back(); data.pop_back(); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_pop_back) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + compare_data.pop_back(); + compare_data.pop_back(); + + data.pop_back(); + data.pop_back(); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -575,6 +1048,19 @@ namespace CHECK_THROW(data.pop_back(), etl::vector_empty); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_pop_back_exception) + { + CData data; + + data.resize(2); + + data.pop_back(); + data.pop_back(); + + CHECK_THROW(data.pop_back(), etl::vector_empty); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { @@ -594,9 +1080,32 @@ namespace CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_value) + { + const size_t INITIAL_SIZE = 5; + int INITIAL_VALUE = 1; + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CCompare_Data compare_data; + CData data; + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + + data.insert(data.begin() + offset, &INITIAL_VALUE); + compare_data.insert(compare_data.begin() + offset, &INITIAL_VALUE); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -640,9 +1149,30 @@ namespace data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE); compare_data.insert(compare_data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value) + { + const size_t INITIAL_SIZE = 5; + const size_t INSERT_SIZE = 3; + int INITIAL_VALUE = 11; + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CCompare_Data compare_data; + CData data; + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE); + compare_data.insert(compare_data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -674,6 +1204,32 @@ namespace CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_n_value_excess) + { + const size_t INITIAL_SIZE = SIZE; + const size_t INSERT_SIZE = 4; + const int INITIAL_VALUE = 1; + + CData data(INITIAL_SIZE, &INITIAL_VALUE); + + size_t offset = 0; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE), etl::vector_full); + + offset = 2; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE), etl::vector_full); + + offset = 4; + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE), etl::vector_full); + + offset = data.size(); + + CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, &INITIAL_VALUE), etl::vector_full); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { @@ -698,6 +1254,30 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_range) + { + const size_t INITIAL_SIZE = 5; + const int INITIAL_VALUE = 1; + + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + { + CCompare_Data compare_data; + CData data; + + data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); + data.insert(data.begin() + offset, insert_data.begin(), insert_data.end()); + compare_data.insert(compare_data.begin() + offset, insert_data.begin(), insert_data.end()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { @@ -722,7 +1302,31 @@ namespace CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_insert_position_range_excess) + { + const size_t INITIAL_SIZE = 5; + const int INITIAL_VALUE = 1; + CData data(INITIAL_SIZE, &INITIAL_VALUE); + + size_t offset = 0; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = 2; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = 4; + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + + offset = data.size(); + + CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) @@ -734,9 +1338,22 @@ namespace data.erase(data.begin() + 2); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_single) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + compare_data.erase(compare_data.begin() + 2); + + data.erase(data.begin() + 2); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -751,9 +1368,22 @@ namespace data.erase(data.begin() + 2, data.begin() + 4); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_range) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + + data.erase(data.begin() + 2, data.begin() + 4); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -769,6 +1399,17 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_clear) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + data.clear(); + + CHECK_EQUAL(data.size(), size_t(0)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { @@ -776,9 +1417,19 @@ namespace Data data(compare_data.begin(), compare_data.end()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_iterator_const) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); CHECK(is_equal); } @@ -790,9 +1441,19 @@ namespace Data data(compare_data.begin(), compare_data.end()); - bool is_equal = std::equal(data.cbegin(), - data.cend(), - compare_data.cbegin()); + bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_iterator_const) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin()); CHECK(is_equal); } @@ -804,9 +1465,19 @@ namespace Data data(compare_data.begin(), compare_data.end()); - bool is_equal = std::equal(data.rbegin(), - data.rend(), - compare_data.rbegin()); + bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_reverse_iterator_const) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin()); CHECK(is_equal); } @@ -818,9 +1489,19 @@ namespace const Data data(compare_data.begin(), compare_data.end()); - bool is_equal = std::equal(data.crbegin(), - data.crend(), - compare_data.crbegin()); + bool is_equal = std::equal(data.crbegin(), data.crend(), compare_data.crbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_reverse_iterator_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + const CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.crbegin(), data.crend(), compare_data.crbegin()); CHECK(is_equal); } @@ -832,9 +1513,19 @@ namespace const Data data(compare_data.begin(), compare_data.end()); - bool is_equal = std::equal(data.rbegin(), - data.rend(), - compare_data.rbegin()); + bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_reverse_iterator2_const) + { + const CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + + const CData data(compare_data.begin(), compare_data.end()); + + bool is_equal = std::equal(data.rbegin(), data.rend(), compare_data.rbegin()); CHECK(is_equal); } @@ -856,6 +1547,23 @@ namespace CHECK(!(shorter == initial1)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_equal) + { + const CData initial1(initial_data.begin(), initial_data.end()); + const CData initial2(initial_data.begin(), initial_data.end()); + + CHECK(initial1 == initial2); + + const CData different(different_data.begin(), different_data.end()); + + CHECK(!(initial1 == different)); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK(!(shorter == initial1)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_not_equal) { @@ -873,6 +1581,23 @@ namespace CHECK(shorter != initial1); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_not_equal) + { + const CData initial1(initial_data.begin(), initial_data.end()); + const CData initial2(initial_data.begin(), initial_data.end()); + + CHECK(!(initial1 != initial2)); + + const CData different(different_data.begin(), different_data.end()); + + CHECK(initial1 != different); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK(shorter != initial1); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_less_than) { @@ -891,6 +1616,24 @@ namespace CHECK((initial < shorter) == (initial_data < shorter_data)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_less_than) + { + const CData less(less_data.begin(), less_data.end()); + const CData initial(initial_data.begin(), initial_data.end()); + + CHECK((less < initial) == (less_data < initial_data)); + + const CData greater(greater_data.begin(), greater_data.end()); + + CHECK((greater < initial) == (greater_data < initial_data)); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter < initial) == (shorter_data < initial_data)); + CHECK((initial < shorter) == (initial_data < shorter_data)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_less_than_or_equal) { @@ -912,6 +1655,27 @@ namespace CHECK((initial <= initial2) == (initial_data <= initial_data)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_less_than_or_equal) + { + const CData less(less_data.begin(), less_data.end()); + const CData initial(initial_data.begin(), initial_data.end()); + + CHECK((less <= initial) == (less_data <= initial_data)); + + const CData greater(greater_data.begin(), greater_data.end()); + + CHECK((greater <= initial) == (greater_data <= initial_data)); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter <= initial) == (shorter_data <= initial_data)); + CHECK((initial <= shorter) == (initial_data <= shorter_data)); + + const CData initial2(initial_data.begin(), initial_data.end()); + CHECK((initial <= initial2) == (initial_data <= initial_data)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_greater_than) { @@ -930,6 +1694,24 @@ namespace CHECK((initial > shorter) == (initial_data > shorter_data)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_greater_than) + { + const CData less(less_data.begin(), less_data.end()); + const CData initial(initial_data.begin(), initial_data.end()); + + CHECK((less > initial) == (less_data > initial_data)); + + const CData greater(greater_data.begin(), greater_data.end()); + + CHECK((greater > initial) == (greater_data > initial_data)); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter > initial) == (shorter_data > initial_data)); + CHECK((initial > shorter) == (initial_data > shorter_data)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_greater_than_or_equal) { @@ -951,6 +1733,27 @@ namespace CHECK((initial >= initial2) == (initial_data >= initial_data)); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_greater_than_or_equal) + { + const CData less(less_data.begin(), less_data.end()); + const CData initial(initial_data.begin(), initial_data.end()); + + CHECK((less >= initial) == (less_data >= initial_data)); + + const CData greater(greater_data.begin(), greater_data.end()); + + CHECK((greater >= initial) == (greater_data >= initial_data)); + + const CData shorter(shorter_data.begin(), shorter_data.end()); + + CHECK((shorter >= initial) == (shorter_data >= initial_data)); + CHECK((initial >= shorter) == (initial_data > shorter_data)); + + const CData initial2(initial_data.begin(), initial_data.end()); + CHECK((initial >= initial2) == (initial_data >= initial_data)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_memcpy_repair) { @@ -977,9 +1780,36 @@ namespace // Modify the original and check that the memcpy'd vector is not the same. std::reverse(data.begin(), data.end()); - is_equal = std::equal(rdata.begin(), - rdata.end(), - data.begin()); + is_equal = std::equal(rdata.begin(), rdata.end(), data.begin()); + + CHECK(!is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_memcpy_repair) + { + CData data(initial_data.begin(), initial_data.end()); + + char buffer[sizeof(CData)]; + + memcpy(&buffer, &data, sizeof(data)); + + CData& rdata(*reinterpret_cast(buffer)); + rdata.repair(); + + // Check that the memcpy'd vector is the same. + CHECK_EQUAL(data.size(), rdata.size()); + CHECK(!rdata.empty()); + CHECK(rdata.full()); + + bool is_equal = std::equal(rdata.begin(), rdata.end(), data.begin()); + + CHECK(is_equal); + + // Modify the original and check that the memcpy'd vector is not the same. + std::reverse(data.begin(), data.end()); + + is_equal = std::equal(rdata.begin(), rdata.end(), data.begin()); CHECK(!is_equal); } From 5279ea161949d85a8c924cf5ef00fc171ce2a5fc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 4 Jul 2018 20:21:21 +0100 Subject: [PATCH 06/13] Fixed vector of pointer typedefs --- include/etl/private/ivectorpointer.h | 24 ++++++++++++------------ include/etl/private/pvoidvector.h | 12 ++++++------ include/etl/version.h | 4 ++-- src/private/pvoidvector.cpp | 10 +++++----- support/Release notes.txt | 4 ++++ test/test_vector_pointer.cpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/include/etl/private/ivectorpointer.h b/include/etl/private/ivectorpointer.h index 9ef26977..4a24a186 100644 --- a/include/etl/private/ivectorpointer.h +++ b/include/etl/private/ivectorpointer.h @@ -50,12 +50,12 @@ namespace etl public: typedef T* value_type; - typedef T*& reference; - typedef const T* const & const_reference; - typedef T** pointer; - typedef const T* const * const_pointer; - typedef T** iterator; - typedef const T* const * const_iterator; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type* iterator; + typedef const value_type* const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; typedef size_t size_type; @@ -452,12 +452,12 @@ namespace etl public: typedef const T* value_type; - typedef const T*& reference; - typedef const T* const & const_reference; - typedef const T** pointer; - typedef const T* const * const_pointer; - typedef const T** iterator; - typedef const T* const * const_iterator; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type* iterator; + typedef const value_type* const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; typedef size_t size_type; diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 5997b2e6..b6f8e61a 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -61,12 +61,12 @@ namespace etl public: typedef void* value_type; - typedef void*& reference; - typedef const void*& const_reference; - typedef void** pointer; - typedef const void** const_pointer; - typedef void** iterator; - typedef const void** const_iterator; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type* iterator; + typedef const value_type* const_iterator; typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; typedef size_t size_type; diff --git a/include/etl/version.h b/include/etl/version.h index 9043d8f3..5c7e5d03 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.13.0" +#define ETL_VERSION "11.13.1" #define ETL_VERSION_MAJOR 11 #define ETL_VERSION_MINOR 13 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #endif diff --git a/src/private/pvoidvector.cpp b/src/private/pvoidvector.cpp index 527abfbe..814abbd4 100644 --- a/src/private/pvoidvector.cpp +++ b/src/private/pvoidvector.cpp @@ -181,7 +181,7 @@ void etl::pvoidvector::resize(size_t new_size, etl::pvoidvector::value_type valu //********************************************************************* etl::pvoidvector::reference etl::pvoidvector::operator [](size_t i) { - return p_buffer[i]; + return reference(p_buffer[i]); } //********************************************************************* @@ -203,7 +203,7 @@ etl::pvoidvector::const_reference etl::pvoidvector::operator [](size_t i) const etl::pvoidvector::reference etl::pvoidvector::at(size_t i) { ETL_ASSERT(i < size(), ETL_ERROR(vector_out_of_bounds)); - return p_buffer[i]; + return reference(p_buffer[i]); } //********************************************************************* @@ -224,7 +224,7 @@ etl::pvoidvector::const_reference etl::pvoidvector::at(size_t i) const //********************************************************************* etl::pvoidvector::reference etl::pvoidvector::front() { - return p_buffer[0]; + return reference(p_buffer[0]); } //********************************************************************* @@ -242,7 +242,7 @@ etl::pvoidvector::const_reference etl::pvoidvector::front() const //********************************************************************* etl::pvoidvector::reference etl::pvoidvector::back() { - return *(p_end - 1); + return reference(*(p_end - 1)); } //********************************************************************* @@ -260,7 +260,7 @@ etl::pvoidvector::const_reference etl::pvoidvector::back() const //********************************************************************* etl::pvoidvector::pointer etl::pvoidvector::data() { - return p_buffer; + return pointer(p_buffer); } //********************************************************************* diff --git a/support/Release notes.txt b/support/Release notes.txt index 315fa97c..94460ab2 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +11.13.1 +Fixed vector of pointer typedefs + =============================================================================== 11.13.0 Added specialisation for vector diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index eeac0e8c..d35cc045 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -1813,5 +1813,33 @@ namespace CHECK(!is_equal); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_ivector_of_pointer_to_pointer) + { + int i1 = 1; + etl::vector consttest; + consttest.push_back(&i1); + const etl::ivector& ct = consttest; + + int* i2 = ct[0]; + + CHECK(i1 == *i2); + CHECK(&i1 == i2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_ivector_of_pointer_to_const_pointer) + { + int i1 = 1; + etl::vector consttest; + consttest.push_back(&i1); + const etl::ivector& ct = consttest; + + const int* i2 = ct[0]; + + CHECK(i1 == *i2); + CHECK(&i1 == i2); + } }; } From 8f22244054ed1b2d1d98616abe70adcfc4774479 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Jul 2018 21:32:54 +0100 Subject: [PATCH 07/13] Merge remote-tracking branch 'origin/master' into development --- LICENSE | 4 +-- README.md | 2 +- include/etl/fsm.h | 70 +++++++++++++++++++++++++++++++++++++ include/etl/fsm_generator.h | 14 ++++++++ include/etl/observer.h | 6 ++++ library.properties | 1 + 6 files changed, 93 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 8f66b070..0e19085c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 jwellbelove -https://github.com/ETLCPP/etl -http://www.etlcpp.com +Copyright (c) 2016 jwellbelove, https://github.com/ETLCPP/etl, http://www.etlcpp.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 1a4efc26..cfbd3f07 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Embedded Template Library (ETL) ------------------------- -AppVeyor [![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master) +AppVeyor [![Build status](https://ci.appveyor.com/api/projects/status/b7jgecv7unqjw4u0/branch/master?svg=true)](https://ci.appveyor.com/project/jwellbelove/etl/branch/master) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT) **Motivation** diff --git a/include/etl/fsm.h b/include/etl/fsm.h index 3a837f39..8ba4b972 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -390,6 +390,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -451,6 +455,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -511,6 +519,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -570,6 +582,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -627,6 +643,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -683,6 +703,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -738,6 +762,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -792,6 +820,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -844,6 +876,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -895,6 +931,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -945,6 +985,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -994,6 +1038,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -1041,6 +1089,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -1087,6 +1139,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -1132,6 +1188,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -1176,6 +1236,10 @@ namespace etl } protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { @@ -1216,6 +1280,12 @@ namespace etl : ifsm_state(STATE_ID) { } + + protected: + + ~fsm_state() + { + } inline TContext& get_fsm_context() const { diff --git a/include/etl/fsm_generator.h b/include/etl/fsm_generator.h index a937542e..176fa60d 100644 --- a/include/etl/fsm_generator.h +++ b/include/etl/fsm_generator.h @@ -411,6 +411,10 @@ namespace etl cog.outl("") cog.outl("protected:") cog.outl("") + cog.outl(" ~fsm_state()") + cog.outl(" {") + cog.outl(" }") + cog.outl("") cog.outl(" inline TContext& get_fsm_context() const") cog.outl(" {") cog.outl(" return static_cast(ifsm_state::get_fsm_context());") @@ -484,6 +488,10 @@ namespace etl cog.outl("") cog.outl("protected:") cog.outl("") + cog.outl(" ~fsm_state()") + cog.outl(" {") + cog.outl(" }") + cog.outl("") cog.outl(" inline TContext& get_fsm_context() const") cog.outl(" {") cog.outl(" return static_cast(ifsm_state::get_fsm_context());") @@ -538,6 +546,12 @@ namespace etl cog.outl(" {") cog.outl(" }") cog.outl("") + cog.outl("protected:") + cog.outl("") + cog.outl(" ~fsm_state()") + cog.outl(" {") + cog.outl(" }") + cog.outl("") cog.outl(" inline TContext& get_fsm_context() const") cog.outl(" {") cog.outl(" return static_cast(ifsm_state::get_fsm_context());") diff --git a/include/etl/observer.h b/include/etl/observer.h index b9c0dbfa..1cc9786a 100644 --- a/include/etl/observer.h +++ b/include/etl/observer.h @@ -179,6 +179,12 @@ namespace etl } } + protected: + + ~observable() + { + } + private: /// The list of observers. diff --git a/library.properties b/library.properties index c9913f89..78d54048 100644 --- a/library.properties +++ b/library.properties @@ -2,6 +2,7 @@ name=Embedded Template Library version=10.21.2 author= John Wellbelove maintainer=John Wellbelove +license=MIT sentence=A C++ template library tailored for embedded systems. paragraph=Requires some support from STL. See http://andybrown.me.uk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/ or https://github.com/mike-matera/ArduinoSTL.git for Arduino. category=Other From 5652c029a861b152fa6fd6192b1cde9c127436a4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Jul 2018 21:35:58 +0100 Subject: [PATCH 08/13] remove_observer returns bool --- include/etl/observer.h | 8 +++++++- include/etl/version.h | 4 ++-- support/Release notes.txt | 5 +++++ test/test_observer.cpp | 6 +++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/etl/observer.h b/include/etl/observer.h index 1cc9786a..1cd9b3f0 100644 --- a/include/etl/observer.h +++ b/include/etl/observer.h @@ -133,8 +133,9 @@ namespace etl //***************************************************************** /// Remove a particular observer from the list. ///\param observer A reference to the observer. + ///\return true if the observer was removed, false if not. //***************************************************************** - void remove_observer(TObserver& observer) + bool remove_observer(TObserver& observer) { // See if we have it in our list. typename Observer_List::iterator i_observer = std::find(observer_list.begin(), @@ -146,6 +147,11 @@ namespace etl { // Erase it. observer_list.erase(i_observer); + return true; + } + else + { + return false; } } diff --git a/include/etl/version.h b/include/etl/version.h index 5c7e5d03..caaedbcf 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.13.1" +#define ETL_VERSION "11.13.2" #define ETL_VERSION_MAJOR 11 #define ETL_VERSION_MINOR 13 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_PATCH 2 #endif diff --git a/support/Release notes.txt b/support/Release notes.txt index 94460ab2..e9202643 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +11.13.2 +Protected destructor for some FSM classes. +Observer's remove_observer returns bool. + =============================================================================== 11.13.1 Fixed vector of pointer typedefs diff --git a/test/test_observer.cpp b/test/test_observer.cpp index f6efc6b4..b23a1359 100644 --- a/test/test_observer.cpp +++ b/test/test_observer.cpp @@ -424,7 +424,11 @@ namespace CHECK_THROW(observable.add_observer(observer5), etl::observer_list_full); - observable.remove_observer(observer3); + CHECK(observable.remove_observer(observer3)); + CHECK_EQUAL(size_t(3), observable.number_of_observers()); + + // Try again. + CHECK(!observable.remove_observer(observer3)); CHECK_EQUAL(size_t(3), observable.number_of_observers()); observable.clear_observers(); From 3fdf3e6b1a541e5ba98f9398d493289abece20ad Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 22 Jul 2018 20:51:03 +0100 Subject: [PATCH 09/13] Merge remote-tracking branch 'origin/feature/no_stl' into development # Conflicts: # include/etl/private/ivectorpointer.h # test/test_vector_pointer.cpp --- include/etl/algorithm.h | 43 +- include/etl/array.h | 28 +- include/etl/array_view.h | 7 +- include/etl/array_wrapper.h | 22 +- include/etl/atomic.h | 2 +- include/etl/atomic/atomic_gcc_sync.h | 16 +- include/etl/atomic/atomic_std.h | 16 +- include/etl/basic_string.h | 8 +- include/etl/binary.h | 4 +- include/etl/bitset.h | 6 +- include/etl/callback_timer.h | 2 +- include/etl/char_traits.h | 5 +- include/etl/compare.h | 4 +- include/etl/container.h | 3 +- include/etl/crc16.h | 3 +- include/etl/crc16_ccitt.h | 3 +- include/etl/crc16_kermit.h | 3 +- include/etl/crc32.h | 3 +- include/etl/crc32_c.h | 3 +- include/etl/crc64_ecma.h | 3 +- include/etl/crc8_ccitt.h | 4 +- include/etl/cstring.h | 4 +- include/etl/cyclic_value.h | 4 +- include/etl/deque.h | 10 +- include/etl/fixed_iterator.h | 4 +- include/etl/flat_map.h | 4 +- include/etl/flat_multimap.h | 4 +- include/etl/flat_multiset.h | 4 +- include/etl/flat_set.h | 4 +- include/etl/forward_list.h | 12 +- include/etl/ihash.h | 4 +- include/etl/intrusive_forward_list.h | 7 +- include/etl/intrusive_links.h | 3 +- include/etl/intrusive_list.h | 7 +- include/etl/io_port.h | 3 +- include/etl/iterator.h | 5 +- include/etl/jenkins.h | 3 +- include/etl/list.h | 12 +- include/etl/map.h | 13 +- include/etl/memory.h | 5 +- include/etl/message_bus.h | 2 +- include/etl/message_timer.h | 2 +- include/etl/multimap.h | 12 +- include/etl/multiset.h | 12 +- include/etl/mutex.h | 2 +- include/etl/observer.h | 2 +- include/etl/platform.h | 1 + include/etl/pool.h | 14 +- include/etl/priority_queue.h | 6 +- include/etl/private/pvoidvector.h | 6 +- include/etl/profiles/arduino_arm.h | 2 - include/etl/profiles/armv5.h | 2 - .../etl/profiles/armv5_no_stl.h | 51 +- include/etl/profiles/armv6.h | 2 - include/etl/profiles/armv6_no_stl.h | 49 ++ include/etl/profiles/cpp03.h | 2 - include/etl/profiles/cpp03_no_stl.h | 49 ++ include/etl/profiles/cpp11.h | 2 - include/etl/profiles/cpp11_no_stl.h | 49 ++ include/etl/profiles/cpp14.h | 2 - include/etl/profiles/cpp14_no_stl.h | 49 ++ include/etl/profiles/gcc_generic.h | 6 +- include/etl/profiles/gcc_linux_x86.h | 6 +- include/etl/profiles/gcc_windows_x86.h | 6 +- include/etl/profiles/msvc_x86.h | 6 +- include/etl/profiles/segger_gcc_stlport.h | 6 +- include/etl/profiles/ticc.h | 2 - include/etl/reference_flat_multiset.h | 10 +- include/etl/reference_flat_set.h | 10 +- include/etl/set.h | 11 +- include/etl/stack.h | 4 +- include/etl/stl/algorithm.h | 42 + include/etl/stl/alternate/algorithm.h | 626 ++++++++++++++ include/etl/stl/alternate/functional.h | 54 ++ include/etl/stl/alternate/iterator.h | 347 ++++++++ include/etl/stl/alternate/limits.h | 533 ++++++++++++ include/etl/stl/alternate/utility.h | 140 ++++ include/etl/stl/functional.h | 13 + include/etl/stl/iterator.h | 43 + include/etl/stl/limits.h | 42 + include/etl/stl/utility.h | 42 + include/etl/string_view.h | 4 +- include/etl/type_traits.h | 6 +- include/etl/type_traits_generator.h | 6 +- include/etl/u16string.h | 4 +- include/etl/u32string.h | 4 +- include/etl/unordered_map.h | 11 +- include/etl/unordered_multimap.h | 11 +- include/etl/unordered_multiset.h | 11 +- include/etl/unordered_set.h | 11 +- include/etl/variant_pool.h | 6 +- include/etl/variant_pool_generator.h | 5 +- include/etl/vector.h | 13 +- include/etl/wstring.h | 4 +- test/CMakeLists.txt | 2 +- test/codeblocks/ETL.cbp | 14 + test/etl_profile.h | 2 + test/test_algorithm.cpp | 42 + test/test_atomic_std.cpp | 4 +- test/test_fsm.cpp | 4 +- test/test_no_stl_algorithm.cpp | 581 +++++++++++++ test/test_no_stl_functional.cpp | 78 ++ test/test_no_stl_limits.cpp | 762 ++++++++++++++++++ test/test_no_stl_utility.cpp | 142 ++++ test/vs2017/etl.vcxproj | 20 + test/vs2017/etl.vcxproj.filters | 72 +- 106 files changed, 4113 insertions(+), 273 deletions(-) rename src/profiles/etl_profile.h => include/etl/profiles/armv5_no_stl.h (61%) create mode 100644 include/etl/profiles/armv6_no_stl.h create mode 100644 include/etl/profiles/cpp03_no_stl.h create mode 100644 include/etl/profiles/cpp11_no_stl.h create mode 100644 include/etl/profiles/cpp14_no_stl.h create mode 100644 include/etl/stl/algorithm.h create mode 100644 include/etl/stl/alternate/algorithm.h create mode 100644 include/etl/stl/alternate/functional.h create mode 100644 include/etl/stl/alternate/iterator.h create mode 100644 include/etl/stl/alternate/limits.h create mode 100644 include/etl/stl/alternate/utility.h create mode 100644 include/etl/stl/functional.h create mode 100644 include/etl/stl/iterator.h create mode 100644 include/etl/stl/limits.h create mode 100644 include/etl/stl/utility.h create mode 100644 test/test_no_stl_algorithm.cpp create mode 100644 test/test_no_stl_functional.cpp create mode 100644 test/test_no_stl_limits.cpp create mode 100644 test/test_no_stl_utility.cpp 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 + From dea6fa13718ce15382daf522edb36baade537d54 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 25 Jul 2018 10:20:59 +0100 Subject: [PATCH 10/13] Added test for limited self insert. --- test/test_string_char.cpp | 19 +++++++++++++++++++ test/test_string_u16.cpp | 19 +++++++++++++++++++ test/test_string_u32.cpp | 21 +++++++++++++++++++-- test/test_string_wchar_t.cpp | 19 +++++++++++++++++++ 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 3d9aab80..948476f3 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -48,6 +48,7 @@ namespace typedef etl::istring IText; typedef std::string Compare_Text; typedef Text::value_type value_t; + typedef etl::string<52> TextL; Compare_Text initial_text; Compare_Text less_text; @@ -867,6 +868,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_self) + { + size_t length = TextL::MAX_SIZE / 2; + + for (size_t offset = 10; offset < length; ++offset) + { + Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); + compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 62de9237..81ed3a4a 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -47,6 +47,7 @@ namespace typedef etl::iu16string IText; typedef std::u16string Compare_Text; typedef Text::value_type value_t; + typedef etl::u16string<52> TextL; Compare_Text initial_text; Compare_Text less_text; @@ -866,6 +867,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_self) + { + size_t length = TextL::MAX_SIZE / 2; + + for (size_t offset = 10; offset < length; ++offset) + { + Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); + compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 4cfd43f9..e3f3528e 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -47,6 +47,7 @@ namespace typedef etl::iu32string IText; typedef std::u32string Compare_Text; typedef Text::value_type value_t; + typedef etl::u32string<52> TextL; Compare_Text initial_text; Compare_Text less_text; @@ -583,8 +584,6 @@ namespace CHECK(is_equal); } - - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { @@ -866,6 +865,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_self) + { + size_t length = TextL::MAX_SIZE / 2; + + for (size_t offset = 10; offset < length; ++offset) + { + Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); + compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index ff538896..e1cbdad2 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -47,6 +47,7 @@ namespace typedef etl::iwstring IText; typedef std::wstring Compare_Text; typedef Text::value_type value_t; + typedef etl::wstring<52> TextL; Compare_Text initial_text; Compare_Text less_text; @@ -866,6 +867,24 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_position_range_self) + { + size_t length = TextL::MAX_SIZE / 2; + + for (size_t offset = 10; offset < length; ++offset) + { + Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + + text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); + compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { From c1673ca1950074b52e051cb3ce0ba20464657f6b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 25 Jul 2018 10:21:31 +0100 Subject: [PATCH 11/13] Added 'wipe on destruct' class --- include/etl/memory.h | 172 ++++++++++++++++++++++++++++++------------- test/test_memory.cpp | 42 +++++++++++ 2 files changed, 163 insertions(+), 51 deletions(-) diff --git a/include/etl/memory.h b/include/etl/memory.h index 0d06a1f0..de82cc95 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -31,13 +31,14 @@ SOFTWARE. #ifndef ETL_MEMORY_INCLUDED #define ETL_MEMORY_INCLUDED -#include "algorithm.h" - #include "platform.h" +#include "algorithm.h" #include "type_traits.h" #include "stl/iterator.h" +#include + ///\defgroup memory memory ///\ingroup etl namespace etl @@ -96,7 +97,7 @@ namespace etl count += int32_t(std::distance(o_begin, o_end)); std::fill(o_begin, o_end, value); - + return o_end; } @@ -340,7 +341,7 @@ namespace etl /// Default initialises N objects to uninitialised memory. ///\ingroup memory //***************************************************************************** - template + template typename etl::enable_if::value_type>::value, TOutputIterator>::type uninitialized_default_construct_n(TOutputIterator o_begin, TSize n) { @@ -770,12 +771,41 @@ namespace etl }; //***************************************************************************** - /// Unique pointer. + /// Default deleter. ///\tparam T The pointed to type type. ///\ingroup memory //***************************************************************************** template - class unique_ptr + struct default_delete + { + void operator()(T* p) const + { + delete p; + } + }; + + //***************************************************************************** + /// Default deleter for arrays. + ///\tparam T The pointed to type type. + ///\ingroup memory + //***************************************************************************** + template + struct default_delete + { + template + void operator()(U* p) const + { + delete[] p; + } + }; + + //***************************************************************************** + /// Unique pointer. + ///\tparam T The pointed to type type. + ///\ingroup memory + //***************************************************************************** + template > + class unique_ptr { public: @@ -799,22 +829,32 @@ namespace etl { } #endif - + ~unique_ptr() { - delete p; + deleter(p); } ETL_CONSTEXPR pointer get() const { return p; } - + + TDeleter& get_deleter() + { + return deleter; + } + + const TDeleter& get_deleter() const + { + return deleter; + } + pointer release() - { + { pointer value = p; p = nullptr; - + return value; } @@ -826,21 +866,21 @@ namespace etl p = p_; delete value; } - + void swap(unique_ptr& value) - { + { std::swap(p, value.p); } - + ETL_CONSTEXPR explicit operator bool() const { return (p != nullptr); } - + unique_ptr& operator =(pointer p_) { reset(p_); - + return *this; } @@ -848,36 +888,36 @@ namespace etl unique_ptr& operator =(unique_ptr&& p_) { reset(p_.release()); - - return *this; + + return *this; } #endif - + ETL_CONSTEXPR reference operator *() const { return *get(); } - + ETL_CONSTEXPR pointer operator ->() const { return get(); } - + ETL_CONSTEXPR reference operator [](size_t i) const { return get()[i]; } - + ETL_CONSTEXPR bool operator== (const pointer p_) const { return p == p_; } - + ETL_CONSTEXPR bool operator== (const unique_ptr& p_) const { return p == p_.p; } - + ETL_CONSTEXPR bool operator< (const unique_ptr& p_) const { return p < p_.p; @@ -889,25 +929,26 @@ namespace etl unique_ptr(const unique_ptr&); unique_ptr& operator =(const unique_ptr&); + TDeleter deleter; + pointer p; }; - //***************************************************************************** /// Unique pointer for arrays. ///\tparam T The pointed to type type. ///\ingroup memory //***************************************************************************** - template - class unique_ptr + template + class unique_ptr { public: typedef T element_type; typedef T* pointer; typedef T& reference; - - ETL_CONSTEXPR unique_ptr() + + ETL_CONSTEXPR unique_ptr() : p(nullptr) { } @@ -916,43 +957,53 @@ namespace etl : p(p_) { } - + #if ETL_CPP11_SUPPORTED unique_ptr(unique_ptr&& p_) : p(p_.release()) { } #endif - - ~unique_ptr() + + ~unique_ptr() { - delete[] p; + deleter(p); } - + ETL_CONSTEXPR pointer get() const { return p; } - - pointer release() + + TDeleter& get_deleter() + { + return deleter; + } + + const TDeleter& get_deleter() const + { + return deleter; + } + + pointer release() { pointer value = p; p = nullptr; return value; } - + void reset(pointer p_) { assert(p_ != p); - pointer value = p; - p = p_; - delete[] value; + pointer value = p; + p = p_; + delete[] value; } void swap(unique_ptr& v) { - std::swap(p, v.p); + std::swap(p, v.p); } ETL_CONSTEXPR explicit operator bool() const @@ -963,8 +1014,8 @@ namespace etl unique_ptr& operator =(pointer p_) { reset(p_); - - return *this; + + return *this; } #if ETL_CPP11_SUPPORTED @@ -972,31 +1023,31 @@ namespace etl { reset(p_.release()); - return *this; + return *this; } #endif ETL_CONSTEXPR reference operator *() const { - return *p; + return *p; } ETL_CONSTEXPR pointer operator ->() const { - return p; + return p; } ETL_CONSTEXPR reference operator [](size_t i) const { - return p[i]; + return p[i]; } ETL_CONSTEXPR bool operator ==(const pointer p_) const { - return (p == p_); + return (p == p_); } - ETL_CONSTEXPR bool operator ==(const unique_ptr& p_) const + ETL_CONSTEXPR bool operator ==(const unique_ptr& p_) const { return (p == p_.p); } @@ -1005,14 +1056,33 @@ namespace etl { return (p < p_.p); } - + private: // Deleted. unique_ptr(const unique_ptr&); unique_ptr& operator =(const unique_ptr&); - pointer p; + TDeleter deleter; + + pointer p; + }; + + //***************************************************************************** + /// Base class for objects that require their memory to be wiped after use. + /// Erases the object's memory to zero. + /// Note: This must be the last destructor called for the derived object. + ///\tparam T The derived type. + ///\ingroup memory + //***************************************************************************** + template + struct wipe_on_destruct + { + ~wipe_on_destruct() + { + char* pobject = reinterpret_cast(static_cast(this)); + memset(pobject, 0, sizeof(T)); + } }; } diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 0f5f0f4e..85eab67a 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -528,5 +528,47 @@ namespace CHECK_EQUAL(test_item_trivial, etl::make_copy_at(pn, test_item_trivial, count)); CHECK_EQUAL(3U, count); } + + //************************************************************************* + TEST(test_wipe_on_destruct) + { + struct Data : public etl::wipe_on_destruct + { + Data(int a_, char b_, double c_) + : a(a_), + b(b_), + c(c_) + { + } + + bool operator ==(const Data& other) const + { + return (a == other.a) && (b == other.b) && (c == other.c); + } + + int a; + char b; + double c; + }; + + std::array buffer; + buffer.fill(0); + + // Construct in-place. + ::new (buffer.data()) Data(1, 'b', 3.4); + + Data& other = *reinterpret_cast(buffer.data()); + CHECK(other == Data(1, 'b', 3.4)); + + // Cleared compare buffer. + std::array clear; + clear.fill(0); + + // Destruct; + other.~Data(); + + // Storage should be wiped. + CHECK(buffer == clear); + } }; } From df735dec5946357f657d1b88daf66becded91d22 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 25 Jul 2018 10:37:26 +0100 Subject: [PATCH 12/13] Updated version and release notes. --- include/etl/version.h | 6 +++--- support/Release notes.txt | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index caaedbcf..933abed9 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,10 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.13.2" +#define ETL_VERSION "11.14.0" #define ETL_VERSION_MAJOR 11 -#define ETL_VERSION_MINOR 13 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_MINOR 14 +#define ETL_VERSION_PATCH 0 #endif diff --git a/support/Release notes.txt b/support/Release notes.txt index e9202643..3d4b9fac 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,9 @@ +=============================================================================== +11.14.0 +Added tests for limited support for self insert for strings. +Added 'wipe_on_destruct' template class for secure wiping of objects on destruction. +Updated unique_ptr API. + =============================================================================== 11.13.2 Protected destructor for some FSM classes. From 741d922c33cb12a3017526b36cdf471b08d69813 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 25 Jul 2018 14:09:16 +0100 Subject: [PATCH 13/13] Added wide character versions of the version string. Added numerical version value --- include/etl/version.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/etl/version.h b/include/etl/version.h index 933abed9..69ea1206 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -37,10 +37,14 @@ SOFTWARE. /// Definitions of the ETL version ///\ingroup utilities -#define ETL_VERSION "11.14.0" +#define ETL_VERSION "11.14.0" +#define ETL_VERSION_W L"11.14.0" +#define ETL_VERSION_U16 u"11.14.0" +#define ETL_VERSION_U32 U"11.14.0" #define ETL_VERSION_MAJOR 11 #define ETL_VERSION_MINOR 14 #define ETL_VERSION_PATCH 0 +#define ETL_VERSION_VALUE ((ETL_VERSION_MAJOR * 10000) + (ETL_VERSION_MINOR * 100) + ETL_VERSION_PATCH) #endif