diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e2a6141c..63c0d4c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -63,3 +63,4 @@ jobs: - name: Run tests run: ./test/etl_tests + diff --git a/appveyor.yml b/appveyor.yml index b4f4dc4c..375e1e81 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,7 +2,7 @@ version: 1.0.{build} branches: only: - master -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: - Debug - DebugNoSTL @@ -12,7 +12,7 @@ install: before_build: - cmd: git clone https://github.com/unittest-cpp/unittest-cpp.git c:\projects\unittest-cpp build: - project: test/vs2017/etl.vcxproj + project: test/vs2019/etl.vcxproj verbosity: minimal notifications: - provider: Webhook @@ -20,4 +20,5 @@ notifications: method: POST on_build_success: true on_build_failure: true - on_build_status_changed: true \ No newline at end of file + on_build_status_changed: true + \ No newline at end of file diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 0fb55434..d0d8eaba 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -127,7 +127,7 @@ namespace etl template typename etl::enable_if::value && etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy(TIterator1 sb, TIterator1 se, TIterator2 db) { typedef typename etl::iterator_traits::value_type value_t; @@ -142,7 +142,7 @@ namespace etl template typename etl::enable_if::value || !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy(TIterator1 sb, TIterator1 se, TIterator2 db) { while (sb != se) @@ -192,7 +192,7 @@ namespace etl template typename etl::enable_if::value && etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_n(TIterator1 sb, TSize count, TIterator2 db) { typedef typename etl::iterator_traits::value_type value_t; @@ -204,7 +204,7 @@ namespace etl template typename etl::enable_if::value || !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_n(TIterator1 sb, TSize count, TIterator2 db) { while (count != 0) @@ -236,8 +236,8 @@ namespace etl // Pointer template typename etl::enable_if::value && - etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { typedef typename etl::iterator_traits::value_type value_t; @@ -250,8 +250,8 @@ namespace etl // Other iterator template typename etl::enable_if::value || - !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { while (se != sb) @@ -275,8 +275,12 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // move + // non-pointer or not trivially copyable template - TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db) + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move(TIterator1 sb, TIterator1 se, TIterator2 db) { while (sb != se) { @@ -285,6 +289,21 @@ namespace etl return db; } + + // pointer and trivially copyable + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move(TIterator1 sb, TIterator1 se, TIterator2 db) + { + typedef typename etl::iterator_traits::value_type value_t; + typedef typename etl::iterator_traits::difference_type difference_t; + + difference_t count = (se - sb); + + return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count; + } #else //*************************************************************************** // move @@ -310,8 +329,12 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // move_backward + // non-pointer, non-pod template - TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { while (sb != se) { @@ -320,6 +343,22 @@ namespace etl return de; } + + // pointer and pod + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + { + typedef typename etl::iterator_traits::value_type value_t; + typedef typename etl::iterator_traits::difference_type difference_t; + + difference_t count = (se - sb); + TIterator2 db = de - count; + + return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count; + } #else //*************************************************************************** // move_backward @@ -690,7 +729,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // count_if template @@ -722,12 +761,12 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // equal template ETL_NODISCARD - typename etl::enable_if::value || !etl::is_pointer::value || !etl::is_pod::value_type>::value, bool>::type + typename etl::enable_if::value || !etl::is_pointer::value || !etl::is_trivially_copyable::value_type>::value, bool>::type equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) { while (first1 != last1) @@ -743,7 +782,7 @@ namespace etl template ETL_NODISCARD - typename etl::enable_if::value && etl::is_pointer::value && etl::is_pod::value_type>::value, bool>::type + typename etl::enable_if::value && etl::is_pointer::value && etl::is_trivially_copyable::value_type>::value, bool>::type equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) { typedef typename etl::iterator_traits::value_type value_t; @@ -761,7 +800,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // lexicographical_compare template @@ -823,7 +862,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // min template @@ -859,7 +898,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // max template @@ -895,7 +934,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // transform template @@ -935,7 +974,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // replace template @@ -1056,7 +1095,7 @@ namespace etl } } - #if defined (ETL_NO_STL) + #if ETL_NOT_USING_STL // Pop Heap template void pop_heap(TIterator first, TIterator last, TCompare compare) @@ -1258,7 +1297,7 @@ namespace etl #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // Search template @@ -1323,33 +1362,91 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // Rotate + namespace private_algorithm + { + //********************************* + template + TIterator rotate_general(TIterator first, TIterator middle, TIterator last) + { + TIterator next = middle; + + while (first != next) + { + using ETL_OR_STD::swap; // Allow ADL + + swap(*first++, *next++); + + if (next == last) + { + next = middle; + } + else if (first == middle) + { + middle = next; + } + } + + return first; + } + + //********************************* + template + TIterator rotate_left_by_one(TIterator first, TIterator last) + { + typedef typename etl::iterator_traits::value_type value_type; + + // Save the first item. + value_type temp(etl::move(*first)); + + // Move the rest. + TIterator result = etl::move(etl::next(first), last, first); + + // Restore the first item in its rotated position. + *result = etl::move(temp); + + // The new position of the first item. + return result; + } + + //********************************* + template + TIterator rotate_right_by_one(TIterator first, TIterator last) + { + typedef typename etl::iterator_traits::value_type value_type; + + // Save the last item. + TIterator previous = etl::prev(last); + value_type temp(etl::move(*previous)); + + // Move the rest. + TIterator result = etl::move_backward(first, previous, last); + + // Restore the last item in its rotated position. + *first = etl::move(temp); + + // The new position of the first item. + return result; + } + } + + //********************************* template TIterator rotate(TIterator first, TIterator middle, TIterator last) { - using ETL_OR_STD::swap; // Allow ADL - - TIterator next = middle; - - while (first != next) + if (etl::next(first) == middle) { - using ETL_OR_STD::swap; - - swap(*first++, *next++); - - if (next == last) - { - next = middle; - } - else if (first == middle) - { - middle = next; - } + return private_algorithm::rotate_left_by_one(first, last); } - return first; + if (etl::next(middle) == last) + { + return private_algorithm::rotate_right_by_one(first, last); + } + + return private_algorithm::rotate_general(first, middle, last); } #else //*************************************************************************** @@ -1361,7 +1458,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // find_end // Predicate diff --git a/include/etl/alignment.h b/include/etl/alignment.h index a24bf23b..f7a258f2 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -184,7 +184,7 @@ namespace etl return reinterpret_cast(data); } -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) alignas(ALIGNMENT) char data[LENGTH]; #else union diff --git a/include/etl/array.h b/include/etl/array.h index e92f25cc..410603c0 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -552,6 +552,15 @@ namespace etl T _buffer[SIZE]; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED + template + array(T, Ts...) + -> array && ...), T>, 1U + sizeof...(Ts)>; +#endif + //************************************************************************* /// Overloaded swap for etl::array ///\param lhs The first array. @@ -670,4 +679,3 @@ namespace etl } #endif - diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 9f333b41..e302739a 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -40,6 +40,7 @@ SOFTWARE. #include "hash.h" #include "algorithm.h" #include "memory.h" +#include "type_traits.h" ///\defgroup array array /// A wrapper for arrays @@ -132,7 +133,7 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR explicit array_view(TArray& a) + ETL_CONSTEXPR array_view(TArray& a) : mbegin(a.data()), mend(a.data() + a.size()) { @@ -162,8 +163,8 @@ namespace etl //************************************************************************* /// Construct from C array //************************************************************************* - template - ETL_CONSTEXPR explicit array_view(T(&begin_)[ARRAY_SIZE]) + template + ETL_CONSTEXPR array_view(T(&begin_)[ARRAY_SIZE]) : mbegin(begin_), mend(begin_ + ARRAY_SIZE) { @@ -505,6 +506,24 @@ namespace etl T* mend; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED + template + array_view(TArray& a) + -> array_view; + + template + array_view(const TIterator begin_, const TIterator end_) + -> array_view>; + + template + array_view(const TIterator begin_, const TSize size_) + -> array_view>; +#endif + //************************************************************************* /// Hash function. //************************************************************************* @@ -533,4 +552,3 @@ void swap(etl::array_view& lhs, etl::array_view& rhs) #undef ETL_FILE #endif - diff --git a/include/etl/bitset.h b/include/etl/bitset.h index c6538f3e..9d59243d 100644 --- a/include/etl/bitset.h +++ b/include/etl/bitset.h @@ -874,7 +874,7 @@ namespace etl /// The class emulates an array of bool elements, but optimized for space allocation. /// Will accommodate any number of bits. /// Does not use std::string. - ///\tparam N The number of bits. + ///\tparam MAXN The number of bits. ///\ingroup bitset //************************************************************************* template diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h new file mode 100644 index 00000000..412b99d2 --- /dev/null +++ b/include/etl/bresenham_line.h @@ -0,0 +1,361 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 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_BRESENHAM_LINE_INCLUDED +#define ETL_BRESENHAM_LINE_INCLUDED + +#include + +#include "platform.h" +#include "iterator.h" +#include "static_assert.h" +#include "type_traits.h" +#include "utility.h" + +namespace etl +{ + //*************************************************************************** + /// A pseudo-container that generates points on a line, using Bresenham's + /// line algorithm. + /// T is the type for the etl::coordinate_2d value type. + /// TWork is the internal working variable type. Default is int16_t. + //*************************************************************************** + template + class bresenham_line + { + public: + + //*************************************************** + /// Standard container types. + //*************************************************** + typedef etl::coordinate_2d value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + //*************************************************** + /// Const Iterator + //*************************************************** + class const_iterator : public etl::iterator + { + public: + + friend class bresenham_line; + + //*************************************************** + /// Default constructor + //*************************************************** + const_iterator() + : p_bresenham_line(ETL_NULLPTR) + { + } + + //*************************************************** + /// Copy constuctor + //*************************************************** + const_iterator(const const_iterator& other) + : p_bresenham_line(other.p_bresenham_line) + { + } + + //*************************************************** + /// Assignment operator + //*************************************************** + const_iterator& operator =(const const_iterator& rhs) + { + p_bresenham_line = rhs.p_bresenham_line; + + return *this; + } + + //*************************************************** + /// Pre-increment operator + //*************************************************** + const_iterator& operator ++() + { + // Has the end of the series has been reached? + if (p_bresenham_line->get_coordinate() == p_bresenham_line->back()) + { + // Mark it as an end iterator. + p_bresenham_line = ETL_NULLPTR; + } + else + { + p_bresenham_line->next(); + } + + return *this; + } + + //*************************************************** + /// De-reference operator + //*************************************************** + value_type operator *() const + { + return p_bresenham_line->get_coordinate(); + } + + //*************************************************** + /// Equality operator + //*************************************************** + friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs) + { + return lhs.p_bresenham_line == rhs.p_bresenham_line; + } + + //*************************************************** + /// Inequality operator + //*************************************************** + friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + //*************************************************** + /// Constructor for use by bresenham_line + //*************************************************** + const_iterator(bresenham_line* pb) + : p_bresenham_line(pb) + { + } + + bresenham_line* p_bresenham_line; + }; + + //*************************************************** + /// Constructor. + //*************************************************** + bresenham_line() + { + initialise(T(0), T(0), T(0), T(0)); + } + + //*************************************************** + /// Constructor. + /// Supplied first and last coordinates + //*************************************************** + bresenham_line(etl::coordinate_2d first_, etl::coordinate_2d last_) + { + initialise(first_.x, first_.y, last_.x, last_.y); + } + + //*************************************************** + /// Constructor. + /// Supplied first and last coordinates + //*************************************************** + bresenham_line(T first_x, T first_y, T last_x, T last_y) + { + initialise(first_x, first_y, last_x, last_y); + } + + //*************************************************** + /// Resets the line. + /// Supplied first and last coordinates + //*************************************************** + void reset(etl::coordinate_2d first_, etl::coordinate_2d last_) + { + initialise(first_.x, first_.y, last_.x, last_.y); + } + + //*************************************************** + /// Resets the line. + /// Supplied first and last coordinates + //*************************************************** + void reset(T first_x, T first_y, T last_x, T last_y) + { + initialise(first_x, first_y, last_x, last_y); + } + + //*************************************************** + /// Get a const_iterator to the first coordinate. + /// Resets the Bresenham line. + //*************************************************** + const_iterator begin() + { + coordinate = first; + + return const_iterator(this); + } + + //*************************************************** + /// Get a const_iterator to one past the last coordinate. + //*************************************************** + const_iterator end() const + { + return const_iterator(); + } + + //*************************************************** + /// Get the first coordinate. + //*************************************************** + const_reference front() const + { + return first; + } + + //*************************************************** + /// Get the last coordinate. + //*************************************************** + const_reference back() const + { + return last; + } + + //*************************************************** + /// Get the size of the series. + //*************************************************** + size_t size() const + { + if (y_is_major_axis()) + { + return (dy / 2) + 1; + } + else + { + return (dx / 2) + 1; + } + } + + //*************************************************** + /// Equality operator + //*************************************************** + friend bool operator ==(const bresenham_line& lhs, const bresenham_line& rhs) + { + return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back()); + } + + //*************************************************** + /// Inequality operator + //*************************************************** + friend bool operator !=(const bresenham_line& lhs, const bresenham_line& rhs) + { + return !(lhs == rhs); + } + + private: + + //*************************************************** + /// Get the current number of generated points. + //*************************************************** + void initialise(T first_x, T first_y, T last_x, T last_y) + { + first = value_type(first_x, first_y); + last = value_type(last_x, last_y); + coordinate = first; + x_increment = (last_x < first_x) ? -1 : 1; + y_increment = (last_y < first_y) ? -1 : 1; + dx = (last_x < first_x) ? first_x - last_x : last_x - first_x; + dy = (last_y < first_y) ? first_y - last_y : last_y - first_y; + do_minor_increment = false; + + if (y_is_major_axis()) + { + dx *= 2; + balance = dx - dy; + dy *= 2; + } + else + { + dy *= 2; + balance = dy - dx; + dx *= 2; + } + } + + //*************************************************** + /// Returns true if Y is the major axis. + //*************************************************** + bool y_is_major_axis() const + { + return dx < dy; + } + + //*************************************************** + /// Calculate the next point. + //*************************************************** + void next() + { + if (y_is_major_axis()) + { + // Y is major axis. + if (do_minor_increment) + { + coordinate.x = T(coordinate.x + x_increment); + balance -= dy; + } + + coordinate.y = T(coordinate.y + y_increment); + balance += dx; + } + else + { + // X is major axis. + if (do_minor_increment) + { + coordinate.y = T(coordinate.y + y_increment); + balance -= dx; + } + + coordinate.x = T(coordinate.x + x_increment); + balance += dy; + } + + do_minor_increment = (balance >= 0); + } + + //*************************************************** + /// Get the current coordinate. + //*************************************************** + value_type get_coordinate() const + { + return coordinate; + } + + typedef TWork work_t; + + value_type first; + value_type last; + value_type coordinate; + work_t x_increment; + work_t y_increment; + work_t dx; + work_t dy; + work_t balance; + bool do_minor_increment; + }; +} + +#endif + diff --git a/include/etl/char_traits.h b/include/etl/char_traits.h index 36cffb37..8cbc0344 100644 --- a/include/etl/char_traits.h +++ b/include/etl/char_traits.h @@ -102,19 +102,19 @@ namespace etl typedef typename char_traits_types::state_type state_type; //************************************************************************* - static bool eq(char_type a, char_type b) + ETL_CONSTEXPR static bool eq(char_type a, char_type b) { return a == b; } //************************************************************************* - static bool lt(char_type a, char_type b) + ETL_CONSTEXPR static bool lt(char_type a, char_type b) { return a < b; } //************************************************************************* - static size_t length(const char_type* str) + ETL_CONSTEXPR14 static size_t length(const char_type* str) { size_t count = 0; diff --git a/include/etl/cstring.h b/include/etl/cstring.h index a6b424aa..4dc5960a 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2016 jwellbelove +Copyright(c) 2020 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 @@ -28,460 +28,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_STRING_INCLUDED -#define ETL_STRING_INCLUDED +//***************************************************************************** +// This header is deprecated. Use "string.h" +//***************************************************************************** -#include "platform.h" -#include "basic_string.h" -#include "string_view.h" -#include "hash.h" +#pragma message ("This header is deprecated. Use 'etl/string.h'") -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - #include -#endif - -#include "private/minmax_push.h" - -namespace etl -{ - typedef etl::ibasic_string istring; - - //*************************************************************************** - /// A string implementation that uses a fixed size buffer. - ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. - ///\ingroup string - //*************************************************************************** - template - class string : public istring - { - public: - - typedef istring base_type; - typedef istring interface_type; - - typedef istring::value_type value_type; - - static const size_t MAX_SIZE = MAX_SIZE_; - - //************************************************************************* - /// Constructor. - //************************************************************************* - string() - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->initialise(); - } - - //************************************************************************* - /// Copy constructor. - ///\param other The other string. - //************************************************************************* - string(const etl::string& other) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(other); - } - - //************************************************************************* - /// From other istring. - ///\param other The other istring. - //************************************************************************* - string(const etl::istring& other) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(other); - } - - //************************************************************************* - /// From other string, position, length. - ///\param other The other string. - ///\param position The position of the first character. - ///\param length The number of characters. Default = npos. - //************************************************************************* - string(const etl::istring& other, size_t position, size_t length_ = npos) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - - this->assign(other.begin() + position, other.begin() + position + length_); - - if (other.truncated()) - { - this->is_truncated = true; - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } - } - - //************************************************************************* - /// Constructor, from null terminated text. - ///\param text The initial text of the string. - //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(text, text + etl::char_traits::length(text)); - } - - //************************************************************************* - /// Constructor, from null terminated text and count. - ///\param text The initial text of the string. - ///\param count The number of characters to copy. - //************************************************************************* - string(const value_type* text, size_t count) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(text, text + count); - } - - //************************************************************************* - /// Constructor, from initial size and value. - ///\param initialSize The initial size of the string. - ///\param value The value to fill the string with. - //************************************************************************* - string(size_t count, value_type c) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->initialise(); - this->resize(count, c); - } - - //************************************************************************* - /// Constructor, from an iterator range. - ///\tparam TIterator The iterator type. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. - //************************************************************************* - template - string(TIterator first, TIterator last) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(first, last); - } - -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - //************************************************************************* - /// Construct from initializer_list. - //************************************************************************* - string(std::initializer_list init) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(init.begin(), init.end()); - } -#endif - - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string(const etl::string_view& view) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } - - //************************************************************************* - /// Returns a sub-string. - ///\param position The position of the first character. Default = 0. - ///\param length The number of characters. Default = npos. - //************************************************************************* - etl::string substr(size_t position = 0, size_t length_ = npos) const - { - etl::string new_string; - - if (position != this->size()) - { - ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds)); - - length_ = etl::min(length_, this->size() - position); - - new_string.assign(buffer + position, buffer + position + length_); - } - - return new_string; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const string& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const istring& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const value_type* text) - { - this->assign(text); - - return *this; - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* - void repair() -#ifdef ETL_ISTRING_REPAIR_ENABLE - ETL_OVERRIDE -#endif - { - etl::istring::repair_buffer(buffer); - } - - private: - - value_type buffer[MAX_SIZE + 1]; - }; - - //*************************************************************************** - /// A string implementation that uses a fixed size buffer. - /// A specilisation that requires an external buffer to be specified. - ///\ingroup string - //*************************************************************************** - template <> - class string<0U> : public istring - { - public: - - typedef istring base_type; - typedef istring interface_type; - - typedef istring::value_type value_type; - - //************************************************************************* - /// Constructor. - //************************************************************************* - string(value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->initialise(); - } - - //************************************************************************* - /// Copy constructor. - ///\param other The other string. - //************************************************************************* - string(const etl::string<0U>& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(other); - } - - //************************************************************************* - /// From other istring. - ///\param other The other istring. - //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(other); - } - - //************************************************************************* - /// From other string, position, length. - ///\param other The other string. - ///\param position The position of the first character. - ///\param length The number of characters. Default = npos. - //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : istring(buffer, max_size - 1) - { - ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - - this->assign(other.begin() + position, other.begin() + position + length_); - - if (other.truncated()) - { - this->is_truncated = true; - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } - } - - //************************************************************************* - /// Constructor, from null terminated text. - ///\param text The initial text of the string. - //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(text, text + etl::char_traits::length(text)); - } - - //************************************************************************* - /// Constructor, from null terminated text and count. - ///\param text The initial text of the string. - ///\param count The number of characters to copy. - //************************************************************************* - string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(text, text + count); - } - - //************************************************************************* - /// Constructor, from initial size and value. - ///\param initialSize The initial size of the string. - ///\param value The value to fill the string with. - //************************************************************************* - string(size_t count, value_type c, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->initialise(); - this->resize(count, c); - } - - //************************************************************************* - /// Constructor, from an iterator range. - ///\tparam TIterator The iterator type. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. - //************************************************************************* - template - string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(first, last); - } - -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - //************************************************************************* - /// Construct from initializer_list. - //************************************************************************* - string(std::initializer_list init, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(init.begin(), init.end()); - } -#endif - - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string(const etl::string_view& view, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) - { - this->assign(view.begin(), view.end()); - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const string& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const istring& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const value_type* text) - { - this->assign(text); - - return *this; - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* - void repair() -#ifdef ETL_ISTRING_REPAIR_ENABLE - ETL_OVERRIDE -#endif - { - } - }; - - //************************************************************************* - /// Hash function. - //************************************************************************* -#if ETL_8BIT_SUPPORT - template <> - struct hash - { - size_t operator()(const etl::istring& text) const - { - return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); - } - }; - - template - struct hash > - { - size_t operator()(const etl::string& text) const - { - return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); - } - }; -#endif - - //*************************************************************************** - /// Make string from string literal or char array - //*************************************************************************** - template - etl::string make_string(const char (&text) [MAX_SIZE]) - { - return etl::string(text, MAX_SIZE - 1); - } - - //*************************************************************************** - /// Make string with max capacity from string literal or char array - //*************************************************************************** - template - etl::string make_string_with_capacity(const char(&text)[SIZE]) - { - return etl::string(text, SIZE - 1); - } -} - -#include "private/minmax_pop.h" - -#endif +#include "string.h" diff --git a/include/etl/deque.h b/include/etl/deque.h index 5cd57588..ee02abcd 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -186,6 +186,15 @@ namespace etl return CAPACITY; } + //************************************************************************* + /// Returns the maximum possible size of the deque. + ///\return The maximum size of the deque. + //************************************************************************* + size_type capacity() const + { + return CAPACITY; + } + //************************************************************************* /// Returns the remaining capacity. ///\return The remaining capacity. @@ -2457,6 +2466,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer[BUFFER_SIZE]; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + deque(T, Ts...) + ->deque && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the _begin deque. diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 5f59f5a6..760248fe 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -43,40 +43,9 @@ SOFTWARE. #include "function.h" #include "nullptr.h" +#if defined(ETL_LOG_ERRORS) || defined(ETL_IN_UNIT_TEST) namespace etl { - namespace private_error_handler - { - // A wrapper template to allow static definition in header. - template - struct wrapper - { - typedef void(*stub_type)(void* object, const etl::exception&); - - //************************************************************************* - /// The internal invocation object. - //************************************************************************* - struct invocation_element - { - //*********************************************************************** - invocation_element() - : object(ETL_NULLPTR) - , stub(ETL_NULLPTR) - { - } - - //*********************************************************************** - void* object; - stub_type stub; - }; - - static invocation_element invocation; - }; - - template - typename wrapper::invocation_element wrapper::invocation; - } - //*************************************************************************** /// Error handler for when throwing exceptions is not required. ///\ingroup error_handler @@ -86,7 +55,7 @@ namespace etl public: //************************************************************************* - /// Callback class for free handler functions. + /// Callback class for free handler functions. Deprecated. //************************************************************************* struct free_function : public etl::function { @@ -97,7 +66,7 @@ namespace etl }; //************************************************************************* - /// Callback class for member handler functions. + /// Callback class for member handler functions. Deprecated. //************************************************************************* template struct member_function : public etl::function @@ -109,7 +78,7 @@ namespace etl }; //***************************************************************************** - /// Sets the error callback function. + /// Sets the error callback function. Deprecated. ///\param f A reference to an etl::function object that will handler errors. //***************************************************************************** static void set_callback(ifunction& f) @@ -168,9 +137,11 @@ namespace etl //***************************************************************************** static void error(const etl::exception& e) { - if (private_error_handler::wrapper::invocation.stub != ETL_NULLPTR) + invocation_element& invocation = get_invocation_element(); + + if (invocation.stub != ETL_NULLPTR) { - (*private_error_handler::wrapper::invocation.stub)(private_error_handler::wrapper::invocation.object, e); + (*invocation.stub)(invocation.object, e); } } @@ -183,24 +154,37 @@ namespace etl //************************************************************************* struct invocation_element { + //*********************************************************************** invocation_element() : object(ETL_NULLPTR) , stub(ETL_NULLPTR) { } - + //*********************************************************************** void* object; stub_type stub; }; + //************************************************************************* + /// Returns the static invocation element. + //************************************************************************* + static invocation_element& get_invocation_element() + { + static invocation_element invocation; + + return invocation; + } + //************************************************************************* /// Constructs a callback from an object and stub. //************************************************************************* static void create(void* object, stub_type stub) { - private_error_handler::wrapper::invocation.object = object; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = object; + invocation.stub = stub; } //************************************************************************* @@ -208,8 +192,10 @@ namespace etl //************************************************************************* static void create(stub_type stub) { - private_error_handler::wrapper::invocation.object = ETL_NULLPTR; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = ETL_NULLPTR; + invocation.stub = stub; } //************************************************************************* @@ -269,6 +255,7 @@ namespace etl } }; } +#endif //*************************************************************************** /// Asserts a condition. diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 13c6988a..b5960133 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -1004,6 +1004,17 @@ namespace etl /// The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_map(T, Ts...) + ->flat_map && ...), typename T::first_type>, + etl::enable_if_t<(etl::is_same_v && ...), typename T::second_type>, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index d7761afb..e163ec67 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -907,6 +907,17 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_multimap(T, Ts...) + ->flat_multimap && ...), typename T::first_type>, + etl::enable_if_t<(etl::is_same_v && ...), typename T::second_type>, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 3ffcfaf3..2e3ce7ae 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -857,6 +857,15 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_multiset(T, Ts...) + ->flat_multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index 9f73f099..baa19791 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -944,6 +944,15 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_set(T, Ts...) + ->flat_set && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/format_spec.h b/include/etl/format_spec.h index 27cbcaa0..3ea29cab 100644 --- a/include/etl/format_spec.h +++ b/include/etl/format_spec.h @@ -35,7 +35,7 @@ SOFTWARE. #include "platform.h" #include "basic_format_spec.h" -#include "cstring.h" +#include "string.h" namespace etl { diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index deca5907..4c6b9c22 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -172,6 +172,22 @@ namespace etl return pool_is_shared; } + //************************************************************************* + /// Gets the maximum possible size of the forward_list. + //************************************************************************* + size_type max_size() const + { + return MAX_SIZE; + } + + //************************************************************************* + /// Gets the maximum possible size of the forward_list. + //************************************************************************* + size_type capacity() const + { + return MAX_SIZE; + } + //************************************************************************* /// Gets the size of the forward_list. //************************************************************************* @@ -194,33 +210,16 @@ namespace etl } else { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool)); return p_node_pool->size(); } } - //************************************************************************* - /// Gets the maximum possible size of the forward_list. - //************************************************************************* - size_type max_size() const - { - return MAX_SIZE; - } - //************************************************************************* /// Checks to see if the forward_list is empty. //************************************************************************* bool empty() const { - if (has_shared_pool()) - { - return (size() == 0); - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool)); - return p_node_pool->empty(); - } + return (start_node.next == ETL_NULLPTR); } //************************************************************************* @@ -1735,6 +1734,15 @@ namespace etl etl::pool::data_node_t, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + forward_list(T, Ts...) + ->forward_list && ...), T>, 1U + sizeof...(Ts)>; +#endif + //************************************************************************* /// A templated forward_list implementation that uses a fixed size pool. ///\note 'merge' and 'splice_after' and are not supported. diff --git a/include/etl/fsm.h b/include/etl/fsm.h index 7bc2eefd..2f83fb7e 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -386,7 +386,7 @@ namespace etl //******************************************** bool is_consumer() const ETL_OVERRIDE { - return false; + return true; } private: diff --git a/include/etl/functional.h b/include/etl/functional.h index a540f3a7..842cd4c2 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -52,23 +52,23 @@ namespace etl typedef T type; - explicit reference_wrapper(T& t_) + ETL_CONSTEXPR20 explicit reference_wrapper(T& t_) ETL_NOEXCEPT : t(&t_) { } - operator T& () const + ETL_CONSTEXPR20 reference_wrapper& operator = (const reference_wrapper& rhs) ETL_NOEXCEPT + { + t = rhs.t; + return *this; + } + + ETL_CONSTEXPR20 T& get() const ETL_NOEXCEPT { return *t; } - reference_wrapper& operator = (T value) - { - *t = value; - return *this; - } - - T& get() const + ETL_CONSTEXPR20 operator T&() const ETL_NOEXCEPT { return *t; } diff --git a/include/etl/generators/fsm_generator.h b/include/etl/generators/fsm_generator.h index 85552006..b812684d 100644 --- a/include/etl/generators/fsm_generator.h +++ b/include/etl/generators/fsm_generator.h @@ -398,7 +398,7 @@ namespace etl //******************************************** bool is_consumer() const ETL_OVERRIDE { - return false; + return true; } private: diff --git a/include/etl/indirect_vector.h b/include/etl/indirect_vector.h index f2e727dc..8d6b5442 100644 --- a/include/etl/indirect_vector.h +++ b/include/etl/indirect_vector.h @@ -1404,6 +1404,15 @@ namespace etl etl::pool storage_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + indirect_vector(T, Ts...) + ->indirect_vector && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A indirect_vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. diff --git a/include/etl/integral_limits.h b/include/etl/integral_limits.h index 3a33bbde..7b8d4dd0 100644 --- a/include/etl/integral_limits.h +++ b/include/etl/integral_limits.h @@ -32,6 +32,7 @@ SOFTWARE. #define ETL_INTEGRAL_LIMITS_INCLUDED #include +#include #include "platform.h" #include "type_traits.h" diff --git a/include/etl/list.h b/include/etl/list.h index 269e410e..c40a87ca 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -233,6 +233,14 @@ namespace etl return MAX_SIZE; } + //************************************************************************* + /// Gets the maximum possible size of the list. + //************************************************************************* + size_type capacity() const + { + return MAX_SIZE; + } + //************************************************************************* /// Gets the size of the list. //************************************************************************* @@ -241,7 +249,7 @@ namespace etl if (has_shared_pool()) { // We have to count what we actually own. - size_type count = 0; + size_type count = 0U; node_t* p_node = terminal_node.next; @@ -255,7 +263,6 @@ namespace etl } else { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); return p_node_pool->size(); } } @@ -265,15 +272,7 @@ namespace etl //************************************************************************* bool empty() const { - if (has_shared_pool()) - { - return (size() == 0); - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return p_node_pool->empty(); - } + return (terminal_node.next == &terminal_node); } //************************************************************************* @@ -282,17 +281,17 @@ namespace etl bool full() const { ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return p_node_pool->size() == MAX_SIZE; + return p_node_pool->full(); } //************************************************************************* /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - size_t available() const + size_type available() const { ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return max_size() - p_node_pool->size(); + return p_node_pool->available(); } protected: @@ -756,6 +755,14 @@ namespace etl return reverse_iterator(get_head()); } + //************************************************************************* + /// Gets the reverse end of the list. + //************************************************************************* + const_reverse_iterator rend() const + { + return const_reverse_iterator(get_head()); + } + //************************************************************************* /// Gets the reverse beginning of the list. //************************************************************************* @@ -2159,6 +2166,15 @@ namespace etl etl::pool::data_node_t, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + list(T, Ts...) + ->list && ...), T>, 1U + sizeof...(Ts)>; +#endif + //************************************************************************* /// A templated list implementation that uses a fixed size buffer. //************************************************************************* diff --git a/include/etl/map.h b/include/etl/map.h index b13fdf4f..0efc2ef6 100755 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -2298,6 +2298,17 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + map(T, Ts...) + ->map && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/multimap.h b/include/etl/multimap.h index b54686d1..1cde7318 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -2033,7 +2033,6 @@ namespace etl { } #endif - }; //************************************************************************* @@ -2158,6 +2157,17 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + multimap(T, Ts...) + ->multimap && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 3a43e3ed..dd950be1 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -2140,6 +2140,15 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + multiset(T, Ts...) + ->multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/optional.h b/include/etl/optional.h index 25b4af0a..a909e031 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -507,6 +507,14 @@ namespace etl bool valid; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED + template + optional(T) -> optional; +#endif + //*************************************************************************** /// Equality operator. cppreference 1 //*************************************************************************** diff --git a/include/etl/platform.h b/include/etl/platform.h index 13c9df63..95e6f7c7 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -159,9 +159,11 @@ SOFTWARE. #if ETL_CPP20_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP) #define ETL_LIKELY [[likely]] #define ETL_UNLIKELY [[unlikely]] +#define ETL_CONSTEXPR20 constexpr #else #define ETL_LIKELY #define ETL_UNLIKELY +#define ETL_CONSTEXPR20 #endif // Sort out namespaces for STL/No STL options. diff --git a/include/etl/pool.h b/include/etl/pool.h index 3aa79740..cb191bb6 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -256,7 +256,8 @@ namespace etl //************************************************************************* void release(const void* const p_object) { - release_item((char*)p_object); + const uintptr_t p = uintptr_t(p_object); + release_item((char*)p); } //************************************************************************* @@ -264,7 +265,7 @@ namespace etl //************************************************************************* void release_all() { - items_allocated = 0; + items_allocated = 0; items_initialised = 0; p_next = p_buffer; } @@ -274,10 +275,10 @@ namespace etl /// \param p_object A pointer to the object to be checked. /// \return true<\b> if it does, otherwise false //************************************************************************* - //template bool is_in_pool(const void* p_object) const { - return is_item_in_pool((const char*)p_object); + const uintptr_t p = uintptr_t(p_object); + return is_item_in_pool((const char*)p); } //************************************************************************* diff --git a/include/etl/set.h b/include/etl/set.h index ec16c784..63d3debc 100755 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -2221,6 +2221,15 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + set(T, Ts...) + ->set && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/span.h b/include/etl/span.h index 2f4f5932..89e4cf2f 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -234,7 +234,7 @@ namespace etl //************************************************************************* /// Assign from a span. //************************************************************************* - ETL_CONSTEXPR span& operator =(const span& other) ETL_NOEXCEPT + ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT { mbegin = other.mbegin; mend = other.mend; @@ -309,6 +309,24 @@ namespace etl element_type* mend; }; + //************************************************************************* +/// Template deduction guides. +//************************************************************************* +#if ETL_CPP17_SUPPORTED + template + span(TArray& a) + ->span; + + template + span(const TIterator begin_, const TIterator end_) + ->span>; + + template + span(const TIterator begin_, const TSize size_) + ->span>; +#endif + //************************************************************************* /// Hash function. //************************************************************************* diff --git a/include/etl/stack.h b/include/etl/stack.h index 901e0e62..8c57dbd5 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -447,8 +447,7 @@ namespace etl istack& operator = (istack&& rhs) { if (&rhs != this) - { - clear(); + { clone(etl::move(rhs)); } @@ -463,6 +462,8 @@ namespace etl //************************************************************************* void clone(const istack& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) @@ -477,6 +478,8 @@ namespace etl //************************************************************************* void clone(istack&& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) diff --git a/include/etl/string.h b/include/etl/string.h new file mode 100644 index 00000000..be996692 --- /dev/null +++ b/include/etl/string.h @@ -0,0 +1,495 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2016 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_STRING_INCLUDED +#define ETL_STRING_INCLUDED + +#include "platform.h" +#include "basic_string.h" +#include "string_view.h" +#include "hash.h" + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL +#include +#endif + +#include "private/minmax_push.h" + +namespace etl +{ + typedef etl::ibasic_string istring; + + //*************************************************************************** + /// A string implementation that uses a fixed size buffer. + ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. + ///\ingroup string + //*************************************************************************** + template + class string : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + + static const size_t MAX_SIZE = MAX_SIZE_; + + //************************************************************************* + /// Constructor. + //************************************************************************* + string() + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->initialise(); + } + + //************************************************************************* + /// Copy constructor. + ///\param other The other string. + //************************************************************************* + string(const etl::string& other) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(other); + } + + //************************************************************************* + /// From other istring. + ///\param other The other istring. + //************************************************************************* + string(const etl::istring& other) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(other); + } + + //************************************************************************* + /// From other string, position, length. + ///\param other The other string. + ///\param position The position of the first character. + ///\param length The number of characters. Default = npos. + //************************************************************************* + string(const etl::istring& other, size_t position, size_t length_ = npos) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); + + this->assign(other.begin() + position, other.begin() + position + length_); + + if (other.truncated()) + { + this->is_truncated = true; + +#if defined(ETL_STRING_TRUNCATION_IS_ERROR) + ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif + } + } + + //************************************************************************* + /// Constructor, from null terminated text. + ///\param text The initial text of the string. + //************************************************************************* + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(text, text + etl::char_traits::length(text)); + } + + //************************************************************************* + /// Constructor, from null terminated text and count. + ///\param text The initial text of the string. + ///\param count The number of characters to copy. + //************************************************************************* + string(const value_type* text, size_t count) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(text, text + count); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initialSize The initial size of the string. + ///\param value The value to fill the string with. + //************************************************************************* + string(size_t count, value_type c) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->initialise(); + this->resize(count, c); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + string(TIterator first, TIterator last) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + string(std::initializer_list init) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string(const etl::string_view& view) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } + + //************************************************************************* + /// Returns a sub-string. + ///\param position The position of the first character. Default = 0. + ///\param length The number of characters. Default = npos. + //************************************************************************* + etl::string substr(size_t position = 0, size_t length_ = npos) const + { + etl::string new_string; + + if (position != this->size()) + { + ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds)); + + length_ = etl::min(length_, this->size() - position); + + new_string.assign(buffer + position, buffer + position + length_); + } + + return new_string; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const string& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const istring& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const value_type* text) + { + this->assign(text); + + return *this; + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() +#ifdef ETL_ISTRING_REPAIR_ENABLE + ETL_OVERRIDE +#endif + { + etl::istring::repair_buffer(buffer); + } + + private: + + value_type buffer[MAX_SIZE + 1]; + }; + + //*************************************************************************** + /// A string implementation that uses a fixed size buffer. + /// A specilisation that requires an external buffer to be specified. + ///\ingroup string + //*************************************************************************** + template <> + class string<0U> : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + + //************************************************************************* + /// Constructor. + //************************************************************************* + string(value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->initialise(); + } + + //************************************************************************* + /// Copy constructor. + ///\param other The other string. + //************************************************************************* + string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(other); + } + + //************************************************************************* + /// From other istring. + ///\param other The other istring. + //************************************************************************* + string(const etl::istring& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(other); + } + + //************************************************************************* + /// From other string, position, length. + ///\param other The other string. + ///\param position The position of the first character. + ///\param length The number of characters. Default = npos. + //************************************************************************* + string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : istring(buffer, buffer_size - 1U) + { + ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); + + this->assign(other.begin() + position, other.begin() + position + length_); + + if (other.truncated()) + { + this->is_truncated = true; + +#if defined(ETL_STRING_TRUNCATION_IS_ERROR) + ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif + } + } + + //************************************************************************* + /// Constructor, from null terminated text. + ///\param text The initial text of the string. + //************************************************************************* + string(const value_type* text, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } + } + + //************************************************************************* + /// Constructor, from null terminated text and count. + ///\param text The initial text of the string. + ///\param count The number of characters to copy. + //************************************************************************* + string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(text, text + count); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initialSize The initial size of the string. + ///\param value The value to fill the string with. + //************************************************************************* + string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->initialise(); + this->resize(count, c); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const string& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const istring& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const value_type* text) + { + this->assign(text); + + return *this; + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() +#ifdef ETL_ISTRING_REPAIR_ENABLE + ETL_OVERRIDE +#endif + { + } + }; + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_8BIT_SUPPORT + template <> + struct hash + { + size_t operator()(const etl::istring& text) const + { + return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); + } + }; + + template + struct hash > + { + size_t operator()(const etl::string& text) const + { + return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); + } + }; +#endif + + //*************************************************************************** + /// Make string from string literal or char array + //*************************************************************************** + template + etl::string make_string(const char(&text)[MAX_SIZE]) + { + return etl::string(text, MAX_SIZE - 1); + } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::string make_string_with_capacity(const char(&text)[SIZE]) + { + return etl::string(text, SIZE - 1); + } +} + +#include "private/minmax_pop.h" + +#endif diff --git a/include/etl/string_stream.h b/include/etl/string_stream.h index de244492..d6e2c231 100644 --- a/include/etl/string_stream.h +++ b/include/etl/string_stream.h @@ -34,7 +34,7 @@ SOFTWARE. ///\ingroup string #include "platform.h" -#include "cstring.h" +#include "string.h" #include "format_spec.h" #include "to_string.h" #include "string_view.h" diff --git a/include/etl/string_utilities.h b/include/etl/string_utilities.h index 02c5e604..6701b579 100644 --- a/include/etl/string_utilities.h +++ b/include/etl/string_utilities.h @@ -697,16 +697,22 @@ namespace etl //*************************************************************************** /// get_token //*************************************************************************** - template - etl::optional get_token(const TIString& s, typename TIString::const_pointer delimiters, const etl::optional& last_view, bool ignore_empty_tokens) + template + etl::optional get_token(const TInput& input, typename TInput::const_pointer delimiters, const etl::optional& last_view, bool ignore_empty_tokens) { - typedef typename TIString::const_pointer const_pointer; + typedef typename TInput::const_pointer const_pointer; bool token_found = false; size_t position = 0U; TStringView view = last_view.value_or(TStringView()); - const_pointer begin_ptr = s.data(); - const_pointer end_ptr = begin_ptr + s.size(); + const_pointer begin_ptr = input.data(); + + if (begin_ptr == ETL_NULLPTR) + { + return etl::optional(); + } + + const_pointer end_ptr = begin_ptr + input.size(); while (!token_found) { @@ -716,7 +722,7 @@ namespace etl position = etl::distance(begin_ptr, view.data() + view.size() + 1U); // Have we reached the end of the string? - if (position > s.size()) + if (position > input.size()) { return etl::optional(); } diff --git a/include/etl/to_string.h b/include/etl/to_string.h index c8fe60b0..4535d2c9 100644 --- a/include/etl/to_string.h +++ b/include/etl/to_string.h @@ -35,7 +35,7 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" -#include "cstring.h" +#include "string.h" #include "format_spec.h" #include "private/to_string_helper.h" diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 23728d8b..3757f6b7 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -751,7 +751,7 @@ namespace etl //*************************************************************************** /// Alignment templates. /// These require compiler specific intrinsics. -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) template struct alignment_of : integral_constant { }; #elif ETL_COMPILER_MICROSOFT template struct alignment_of : integral_constant {}; diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c3911002..c2a7db6e 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -260,8 +260,8 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u16string(value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->initialise(); } @@ -270,8 +270,8 @@ namespace etl /// Copy constructor. ///\param other The other u16string. //************************************************************************* - u16string(const etl::u16string<0U>& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::u16string<0U>& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +280,8 @@ namespace etl /// From other iu16string. ///\param other The other iu16string. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +292,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu16string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,10 +313,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* @@ -324,8 +332,8 @@ namespace etl ///\param text The initial text of the u16string. ///\param count The number of characters to copy. //************************************************************************* - u16string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +343,8 @@ namespace etl ///\param initialSize The initial size of the u16string. ///\param value The value to fill the u16string with. //************************************************************************* - u16string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +357,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u16string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +367,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u16string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +378,8 @@ namespace etl /// From u16string_view. ///\param view The u16string_view. //************************************************************************* - explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7de99cb6..7e729260 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -260,8 +260,8 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u32string(value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->initialise(); } @@ -270,8 +270,8 @@ namespace etl /// Copy constructor. ///\param other The other u32string. //************************************************************************* - u32string(const etl::u32string<0U>& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::u32string<0U>& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +280,8 @@ namespace etl /// From other iu32string. ///\param other The other iu32string. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +292,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu32string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,10 +313,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u32string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* @@ -324,8 +332,8 @@ namespace etl ///\param text The initial text of the u32string. ///\param count The number of characters to copy. //************************************************************************* - u32string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +343,8 @@ namespace etl ///\param initialSize The initial size of the u32string. ///\param value The value to fill the u32string with. //************************************************************************* - u32string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +357,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u32string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +367,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u32string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +378,8 @@ namespace etl /// From u32string_view. ///\param view The u32string_view. //************************************************************************* - explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 2b3c3cf1..45220ad1 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "16" @@ -1229,6 +1233,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_map. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_map is empty. //************************************************************************* @@ -1579,6 +1591,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_map(std::initializer_list> init) + : base(node_pool, buckets, MAX_BUCKETS_) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1626,6 +1649,17 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_map(T, Ts...) + ->unordered_map && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 8810bc8a..e029593e 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "25" @@ -1135,6 +1139,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_multimap. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_multimap is empty. //************************************************************************* @@ -1491,6 +1503,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_multimap(std::initializer_list> init) + : base(node_pool, buckets, MAX_BUCKETS_) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1538,6 +1561,17 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_multimap(T, Ts...) + ->unordered_multimap && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 677a5b1c..df7e5671 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -55,6 +55,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "26" @@ -1120,6 +1124,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_multiset. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_multiset is empty. //************************************************************************* @@ -1479,6 +1491,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_multiset(std::initializer_list init) + : base(node_pool, buckets, MAX_BUCKETS) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1526,6 +1549,15 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_multiset(T, Ts...) + ->unordered_multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 4e4322c3..fd5b034e 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "23" @@ -1112,6 +1116,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_set. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_set is empty. //************************************************************************* @@ -1475,6 +1487,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_set(std::initializer_list init) + : base(node_pool, buckets, MAX_BUCKETS) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1522,6 +1545,15 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_set(T, Ts...) + ->unordered_set && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/utility.h b/include/etl/utility.h index e9901fb5..37155c95 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -230,6 +230,14 @@ namespace etl #endif }; +//************************************************************************* +/// Template deduction guides. +//************************************************************************* +#if ETL_CPP17_SUPPORTED + template + pair(T1, T2) ->pair; +#endif + //****************************************************************************** #if ETL_CPP11_SUPPORTED template @@ -328,6 +336,37 @@ namespace etl { return t; } + + //****************************************************************************** + /// 2D coordinate type. + template + struct coordinate_2d + { + coordinate_2d() + : x(T(0)) + , y(T(0)) + { + } + + coordinate_2d(T x_, T y_) + : x(x_) + , y(y_) + { + } + + friend bool operator ==(const coordinate_2d& lhs, const coordinate_2d& rhs) + { + return (lhs.x == rhs.x) && (lhs.y == rhs.y); + } + + friend bool operator !=(const coordinate_2d& lhs, const coordinate_2d& rhs) + { + return !(lhs == rhs); + } + + T x; + T y; + }; } #endif diff --git a/include/etl/vector.h b/include/etl/vector.h index b154adee..087a5c65 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -1286,6 +1286,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + vector(T, Ts...) + ->vector && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. @@ -1569,6 +1578,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + vector(T*, Ts*...) + ->vector && ...), T*>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. diff --git a/include/etl/version.h b/include/etl/version.h index 07c33a62..183fbee5 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 5 +#define ETL_VERSION_MINOR 16 +#define ETL_VERSION_PATCH 1 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 562ac06e..22403529 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -261,8 +261,8 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - wstring(value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->initialise(); } @@ -271,8 +271,8 @@ namespace etl /// Copy constructor. ///\param other The other wstring. //************************************************************************* - wstring(const etl::wstring<0U>& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::wstring<0U>& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -281,8 +281,8 @@ namespace etl /// From other iwstring. ///\param other The other iwstring. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -293,8 +293,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iwstring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -314,10 +314,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const value_type* text, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* @@ -325,8 +333,8 @@ namespace etl ///\param text The initial text of the wstring. ///\param count The number of characters to copy. //************************************************************************* - wstring(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -336,8 +344,8 @@ namespace etl ///\param initialSize The initial size of the wstring. ///\param value The value to fill the wstring with. //************************************************************************* - wstring(size_t count, value_type c, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -350,8 +358,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - wstring(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -360,8 +368,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - wstring(std::initializer_list init, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -371,8 +379,8 @@ namespace etl /// From wstring_view. ///\param view The wstring_view. //************************************************************************* - explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/wstring_stream.h b/include/etl/wstring_stream.h index 6139937f..d3a6000e 100644 --- a/include/etl/wstring_stream.h +++ b/include/etl/wstring_stream.h @@ -34,7 +34,7 @@ SOFTWARE. ///\ingroup string #include "platform.h" -#include "cstring.h" +#include "string.h" #include "wformat_spec.h" #include "to_wstring.h" #include "string_view.h" diff --git a/library.json b/library.json index f024aaba..c72f55bc 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.5", + "version": "18.16.1", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 6deb9856..444646b9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.5 +version=18.16.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 360d40d4..7fced63a 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,60 @@ +=============================================================================== +18.16.1 +Updates to CI configuration files. + +=============================================================================== +18.16.0 +Added template deduction guides for most containers. + +=============================================================================== +18.15.5 +Refactored empty(), full(), available() member functions for etl::list and etl::forward_list + +=============================================================================== +18.15.4 +Performance optimisations for etl::rotate, etl::move & etl::move_backward +when not using the STL, iterators are pointers and the objects are trivially +copyable (currently POD types). + +=============================================================================== +18.15.3 +etl::array_view constructor from C array is no longer explicit. + +=============================================================================== +18.15.2 +Workaround for Segger ARM Link-Time-Optimisation (LTO) bug. +etl::array_view constructor from etl or std array is no longer explicit. + +=============================================================================== +18.15.1 +Refactoring of 18.15.0. +Modified constructor syntax. + +=============================================================================== +18.15.0 +Allow strings with external buffers to use a pre-initialised buffer. + +=============================================================================== +18.14.1 +Fixed conditional compilation macro use for template deduction guides. + +=============================================================================== +18.14.0 +Added template deduction guides for array and array_view + +=============================================================================== +18.13.0 +Added a line coordinate generator using the Bresenham algorithm. +The API is similar to a container. + +=============================================================================== +18.12.7 +Made etl::reference_wrapper API closer to the STL version. Does not support invocation of a callable object. + +=============================================================================== +18.12.6 +Fixed etl::stack top level assignment operator not clearing before copy. + =============================================================================== 18.12.5 Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c2b8ead3..97fb199d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,6 +33,7 @@ set(TEST_SOURCE_FILES test_bitset.cpp test_bit_stream.cpp test_bloom_filter.cpp + test_bresenham_line.cpp test_bsd_checksum.cpp test_callback_service.cpp test_callback_timer.cpp diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 9d532038..7c1393ad 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -234,6 +234,7 @@ + @@ -492,6 +493,7 @@ + @@ -544,6 +546,7 @@ + @@ -578,15 +581,19 @@ + + + + @@ -597,6 +604,7 @@ + diff --git a/test/etl_profile.h b/test/etl_profile.h index 64f6f7d4..4b032bab 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -105,6 +105,10 @@ SOFTWARE. #include "../include/etl/profiles/determine_development_os.h" +#if defined(ETL_COMPILER_GCC) && (ETL_COMPILER_VERSION < 8) + #define ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED +#endif + #if defined(ETL_DEVELOPMENT_OS_WINDOWS) #define ETL_TARGET_OS_WINDOWS #elif defined(ETL_DEVELOPMENT_OS_LINUX) diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 8657383e..aefc9c50 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -1099,7 +1099,7 @@ namespace } //************************************************************************* - TEST(rotate) + TEST(rotate_pod) { std::vector initial_data = { 1, 2, 3, 4, 5, 6, 7 }; @@ -1116,6 +1116,25 @@ namespace } } + + //************************************************************************* + TEST(rotate_non_pod) + { + std::vector initial_data = { NDC(1), NDC(2), NDC(3), NDC(4), NDC(5), NDC(6), NDC(7) }; + + for (size_t i = 0; i < initial_data.size(); ++i) + { + std::vector data1(initial_data); + std::vector data2(initial_data); + + std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size()); + etl::rotate(data2.data(), data2.data() + i, data2.data() + data2.size()); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + } + //************************************************************************* TEST(any_of) { diff --git a/test/test_array.cpp b/test/test_array.cpp index 89965a17..41fe82fb 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -57,6 +57,18 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + Data compare = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + bool isEqual = std::equal(data.begin(), data.end(), compare.begin()); + CHECK(isEqual); + } +#endif + //************************************************************************* TEST(test_assignment) { diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index 89750b0a..7aafe9e6 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -91,6 +91,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_etl_array_1) + { + View view = etldata; + + CHECK_EQUAL(etldata.size(), view.size()); + CHECK_EQUAL(etldata.max_size(), view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), etldata.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_etl_array_1_const) { @@ -139,6 +151,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_stl_array_1) + { + View view = stldata; + + CHECK_EQUAL(stldata.size(), view.size()); + CHECK_EQUAL(stldata.max_size(), view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stldata.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_stl_array_1_const) { @@ -235,6 +259,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_c_array) + { + View view = cdata; + + CHECK_EQUAL(SIZE, view.size()); + CHECK_EQUAL(SIZE, view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), cdata); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_c_array_2_const) { @@ -247,6 +283,39 @@ namespace CHECK(isEqual); } + //************************************************************************* +#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + TEST(test_cpp17_deduced_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::array_view view1{ data }; + etl::array_view view2{ data.begin(), data.end() }; + etl::array_view view3{ data.begin(), data.size() }; + etl::array_view view4{ view1 }; + + int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::array_view view5{ c_array }; + + bool isEqual = false; + + isEqual = std::equal(view1.begin(), view1.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view2.begin(), view2.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view3.begin(), view3.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view4.begin(), view4.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view5.begin(), view5.end(), c_array); + CHECK(isEqual); + } +#endif + //************************************************************************* TEST(test_constructor_range) { diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp new file mode 100644 index 00000000..dacaaad3 --- /dev/null +++ b/test/test_bresenham_line.cpp @@ -0,0 +1,436 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 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++/UnitTest++.h" + +#include "etl/bresenham_line.h" + +#include + +namespace etl +{ + template + std::ostream& operator << (std::ostream& os, const etl::coordinate_2d& point) + { + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; + } +} + +namespace +{ + using Value = char; + + using Point = etl::coordinate_2d; + + std::ostream& operator << (std::ostream& os, const Point& point) + { + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; + } + + using BresenhamLine = etl::bresenham_line; + + SUITE(test_bresenham_line) + { + //************************************************************************* + TEST(horizontal_line_left_right) + { + Point first = { -5, 5 }; + Point last = { 5, 5 }; + + BresenhamLine bl(first.x, first.y, last.x, last.y); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, + Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(horizontal_line_right_left) + { + Point first = { 5, 5 }; + Point last = { -5, 5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, + Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(vertical_line_bottom_top) + { + Point first = { 5, -5 }; + Point last = { 5, 5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, + Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(vertical_line_top_bottom) + { + Point first = { 5, 5 }; + Point last = { 5, -5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, + Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_bottom_left_top_right) + { + Point first = { -5, -3 }; + Point last = { 5, 3}; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, + Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_top_right_bottom_left) + { + Point first = { 5, 3 }; + Point last = { -5, -3 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, + Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_bottom_right_top_left) + { + Point first = { 5, -3 }; + Point last = { -5, 3 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, + Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_top_left_bottom_right) + { + Point first = { -5, 3 }; + Point last = { 5, -3 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_bottom_left_top_right) + { + Point first = { -3, -5 }; + Point last = { 3, 5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, + Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_top_right_bottom_left) + { + Point first = { 3, 5 }; + Point last = { -3, -5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, + Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_bottom_right_top_left) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, + Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_top_left_bottom_right) + { + Point first = { -3, 5 }; + Point last = { 3, -5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(reset_the_line_from_coordinate_2d) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + + Point new_first = { -3, 5 }; + Point new_last = { 3, -5 }; + + bl.reset(new_first, new_last); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(reset_the_line_from_individual_coordinates) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + Point new_first = { -3, 5 }; + Point new_last = { 3, -5 }; + + bl.reset(new_first.x, new_first.y, new_last.x, new_last.y); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.size()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(test_equality) + { + BresenhamLine bl1(0, 1, 2, 3); + BresenhamLine bl2(0, 1, 2, 3); + BresenhamLine bl3(0, 1, 2, 4); + BresenhamLine bl4(0, 2, 2, 3); + + CHECK(bl1 == bl2); + CHECK(!(bl1 != bl2)); + + CHECK(bl1 != bl3); + CHECK(!(bl1 == bl3)); + + CHECK(bl1 != bl4); + CHECK(!(bl1 == bl4)); + } + }; +} diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 876aa4ea..9a312438 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -101,6 +101,24 @@ namespace CHECK_EQUAL(SIZE, data.max_size()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::deque data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; + etl::deque check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(14U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(14U, data.capacity()); + CHECK_EQUAL(14U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_constructor_fill) { diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index bc71c3c4..278cd00a 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -316,6 +316,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_map data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + etl::flat_map check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_map) { diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 687e260d..d6cb90ee 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -293,6 +293,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_multimap data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + etl::flat_multimap check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_multimap) { diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index 96c63bb4..10c52d64 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -262,6 +262,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::flat_multiset check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_multiset) { diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index 89be0a1f..daf16013 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -274,6 +274,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_set data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::flat_set check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_set) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 2955720f..9c3295bc 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -95,6 +95,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::forward_list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + etl::forward_list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size) { diff --git a/test/test_forward_list_shared_pool.cpp b/test/test_forward_list_shared_pool.cpp index 52b7cf2c..39873f21 100644 --- a/test/test_forward_list_shared_pool.cpp +++ b/test/test_forward_list_shared_pool.cpp @@ -97,7 +97,10 @@ namespace PoolDC pool; DataDC data(pool); + CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); + CHECK(!data.full()); + CHECK_EQUAL(data.available(), SIZE); CHECK_EQUAL(data.max_size(), SIZE); CHECK(data.begin() == data.end()); CHECK(data.has_shared_pool()); @@ -109,6 +112,8 @@ namespace DataNDC data; CHECK_THROW(data.push_front(ItemNDC("1")), etl::forward_list_no_pool); + CHECK_THROW(data.full(), etl::forward_list_no_pool); + CHECK_THROW(data.available(), etl::forward_list_no_pool); } //************************************************************************* @@ -123,6 +128,10 @@ namespace CHECK(!data2.empty()); CHECK_EQUAL(INITIAL_SIZE, data1.size()); CHECK_EQUAL(INITIAL_SIZE, data2.size()); + + CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data1.available()); + CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data2.available()); + CHECK_EQUAL((2 * INITIAL_SIZE), pool.size()); } @@ -533,9 +542,14 @@ namespace data1.assign(compare_data.begin(), compare_data.end()); data1.assign(compare_data.begin(), compare_data.end()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); + data2.assign(compare_data.begin(), compare_data.end()); data2.assign(compare_data.begin(), compare_data.end()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); diff --git a/test/test_fsm.cpp b/test/test_fsm.cpp index dd334fa3..f34ebbf3 100644 --- a/test/test_fsm.cpp +++ b/test/test_fsm.cpp @@ -338,6 +338,9 @@ namespace { etl::null_message_router nmr; + CHECK(motorControl.is_producer()); + CHECK(motorControl.is_consumer()); + motorControl.Initialise(stateList, etl::size(stateList)); motorControl.reset(); motorControl.ClearStatistics(); diff --git a/test/test_functional.cpp b/test/test_functional.cpp index d7f106b3..59a42f71 100644 --- a/test/test_functional.cpp +++ b/test/test_functional.cpp @@ -104,7 +104,7 @@ namespace int a = 0; etl::reference_wrapper ra(a); - ra = 1; + ra.get() = 1; CHECK_EQUAL(1, a); CHECK_EQUAL(1, ra); @@ -113,42 +113,15 @@ namespace CHECK_EQUAL(2, ra); } - //************************************************************************* - TEST(test_reference_wrapper_vector) - { - std::vector> ref_int; - - int a = 1; - int b = 2; - - ref_int.push_back(etl::ref(a)); - ref_int.push_back(etl::ref(b)); - - CHECK_EQUAL(a, ref_int[0]); - CHECK_EQUAL(b, ref_int[1]); - - ref_int[0] = 3; - ref_int[1] = 4; - - CHECK_EQUAL(3, a); - CHECK_EQUAL(4, b); - - CHECK_EQUAL(3, ref_int[0]); - CHECK_EQUAL(4, ref_int[1]); - } - //************************************************************************* TEST(test_reference_wrapper_container) { - std::list test = { 0, 1, 2, 3, 4 }; - std::list compare = { 5, 6, 7, 8, 9 }; + std::list test = { 0, 1, 2, 3, 4 }; + std::list compare = { 0, 1, 2, 3, 4 }; std::vector> test_ref(test.begin(), test.end()); - std::iota(test_ref.begin(), test_ref.end(), 5); - - std::list::const_iterator itest = test.begin(); + std::list::const_iterator itest = test.begin(); std::list::const_iterator icompare = compare.begin(); - //std::vector>::const_iterator ivector = test_ref.begin(); while (icompare != compare.end()) { @@ -164,7 +137,7 @@ namespace int a = 0; etl::reference_wrapper ra = etl::ref(a); - ra = 1; + ra.get() = 1; CHECK_EQUAL(1, a); CHECK_EQUAL(1, ra); } diff --git a/test/test_indirect_vector.cpp b/test/test_indirect_vector.cpp index 0415025a..24bbb0f7 100644 --- a/test/test_indirect_vector.cpp +++ b/test/test_indirect_vector.cpp @@ -136,6 +136,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::indirect_vector data{ NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + etl::indirect_vector check = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_destruct_via_ivector) { diff --git a/test/test_list.cpp b/test/test_list.cpp index ad674793..17f81e4b 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -106,6 +106,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + etl::list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_ilist) { diff --git a/test/test_list_shared_pool.cpp b/test/test_list_shared_pool.cpp index 5a557623..b006a1b2 100644 --- a/test/test_list_shared_pool.cpp +++ b/test/test_list_shared_pool.cpp @@ -106,6 +106,8 @@ namespace DataNDC data; CHECK_EQUAL(data.max_size(), 0U); + CHECK_EQUAL(data.size(), 0U); + CHECK(data.empty()); CHECK(data.has_shared_pool()); } @@ -115,6 +117,8 @@ namespace DataNDC data; CHECK_THROW(data.push_back(ItemNDC("1")), etl::list_no_pool); + CHECK_THROW(data.full(), etl::list_no_pool); + CHECK_THROW(data.available(), etl::list_no_pool); } //************************************************************************* @@ -125,6 +129,8 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); + CHECK(!data.full()); + CHECK_EQUAL(data.available(), SIZE); CHECK_EQUAL(data.max_size(), SIZE); CHECK(data.begin() == data.end()); @@ -524,12 +530,19 @@ namespace DataNDC data1(pool); DataNDC data2(pool); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); + data1.assign(compare_data.begin(), compare_data.end()); CHECK(!data1.empty()); CHECK(data2.empty()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); data2.assign(compare_data.begin(), compare_data.end()); CHECK(!data1.empty()); CHECK(!data2.empty()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); CHECK_EQUAL(compare_data.size(), data1.size()); CHECK_EQUAL(compare_data.size(), data2.size()); diff --git a/test/test_make_string.cpp b/test/test_make_string.cpp index 5d6035e1..202bc66d 100644 --- a/test/test_make_string.cpp +++ b/test/test_make_string.cpp @@ -30,7 +30,7 @@ SOFTWARE. #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/wstring.h" #include "etl/u16string.h" #include "etl/u32string.h" diff --git a/test/test_map.cpp b/test/test_map.cpp index d092c6af..08885eca 100755 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -225,6 +225,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::map data{ std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + etl::map check = { std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 8a01ecf8..68f86d43 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -887,7 +887,6 @@ namespace { etl::unique_ptr up(new int); - int* p = new int(1); up = nullptr; CHECK(up.get() == nullptr); @@ -1018,7 +1017,6 @@ namespace { etl::unique_ptr up(new int[4]); - int* p = new int[4]; up = nullptr; CHECK(up.get() == nullptr); diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index 86aaa4cc..ca1c8f7b 100755 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -227,6 +227,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::multimap data{ std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + etl::multimap check = { std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index d28f37e0..275b8daf 100755 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -234,6 +234,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::multiset data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::multiset check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_optional.cpp b/test/test_optional.cpp index d0171411..dfe3e386 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -68,7 +68,6 @@ namespace CHECK(!data1.has_value()); CHECK(!data2.has_value()); - data1 = Data("Hello"); CHECK(bool(data1)); CHECK(data1.has_value()); @@ -97,9 +96,22 @@ namespace data4 = etl::nullopt; CHECK(!bool(data4)); CHECK(!data4.has_value()); - } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_deduced_initialisation) + { + Data data("Hello"); + + etl::optional opt{ data }; + + CHECK(opt.has_value()); + CHECK(bool(opt)); + CHECK_EQUAL(data, opt); + } +#endif + //************************************************************************* TEST(test_emplace) { diff --git a/test/test_queue.cpp b/test/test_queue.cpp index f47a2842..2cf4824c 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -485,6 +485,10 @@ namespace etl::queue queue2; + // These should be overwritten. + queue2.push(5); + queue2.push(6); + queue2 = queue; CHECK(queue.size() == queue2.size()); diff --git a/test/test_set.cpp b/test/test_set.cpp index 458c100e..118024ce 100755 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -244,11 +244,30 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); - CHECK_EQUAL(data.capacity(), MAX_SIZE); - CHECK_EQUAL(data.max_size(), MAX_SIZE); + CHECK_EQUAL(MAX_SIZE, data.available()); + CHECK_EQUAL(MAX_SIZE, data.capacity()); + CHECK_EQUAL(MAX_SIZE, data.max_size()); CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::set data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::set check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_span.cpp b/test/test_span.cpp index cae33dd5..6ebdaade 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -247,6 +247,39 @@ namespace CHECK(isEqual); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::span span1{ data }; + etl::span span2{ data.begin(), data.end() }; + etl::span span3{ data.begin(), data.size() }; + etl::span span4{ span1 }; + + int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::span span5{ c_array }; + + bool isEqual = false; + + isEqual = std::equal(span1.begin(), span1.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span2.begin(), span2.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span3.begin(), span3.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span4.begin(), span4.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span5.begin(), span5.end(), c_array); + CHECK(isEqual); + } +#endif + //************************************************************************* TEST(test_constructor_range) { diff --git a/test/test_stack.cpp b/test/test_stack.cpp index e0138830..c1b187fb 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -437,6 +437,10 @@ namespace etl::stack stack2; + // These should be overwritten. + stack2.push(5); + stack2.push(6); + stack2 = stack; CHECK(stack.size() == stack2.size()); diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 261afe5c..e932bf94 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/fnv_1.h" #undef STR diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d4f8d9ff..62612d8b 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/fnv_1.h" #undef STR @@ -73,6 +73,9 @@ namespace Compare_Text short_text; const value_t* pinitial_text = STR("Hello World"); + + value_t array_text[12]; + value_t* p_text = array_text; //************************************************************************* template @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,59 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, p_text, etl::strlen(p_text) + 1); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, array_text, etl::size(array_text)); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { @@ -186,16 +244,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - Compare_Text compare_text(SIZE, STR('A')); + Compare_Text compare_text(SIZE, STR('A')); - TextBuffer buffer; - Text text(SIZE, STR('A'), buffer.data(), buffer.size()); + TextBuffer buffer; + Text text(SIZE, STR('A'), buffer.data(), buffer.size()); - CHECK(!text.empty()); + CHECK(!text.empty()); - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK(!text.truncated()); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -216,16 +274,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2); + Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2); - TextBuffer buffer; - Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); + TextBuffer buffer; + Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); - CHECK(!text.empty()); + CHECK(!text.empty()); - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK(!text.truncated()); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* diff --git a/test/test_string_stream.cpp b/test/test_string_stream.cpp index c2a7bb61..3aa81d03 100644 --- a/test/test_string_stream.cpp +++ b/test/test_string_stream.cpp @@ -33,7 +33,7 @@ SOFTWARE. #include #include "etl/string_stream.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/format_spec.h" #undef STR diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 08115e6b..b1487bcf 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,59 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, p_text, etl::strlen(p_text) + 1); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, array_text, etl::size(array_text)); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index cdc8d4a1..4e57284c 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,59 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, p_text, etl::strlen(p_text) + 1); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, array_text, etl::size(array_text)); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_utilities.cpp b/test/test_string_utilities.cpp index 19266338..67dc70f5 100644 --- a/test/test_string_utilities.cpp +++ b/test/test_string_utilities.cpp @@ -28,7 +28,7 @@ SOFTWARE. #include "UnitTest++/UnitTest++.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/string_view.h" #include "etl/string_utilities.h" #include "etl/vector.h" @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std.cpp b/test/test_string_utilities_std.cpp index 0d806a10..1b711c38 100644 --- a/test/test_string_utilities_std.cpp +++ b/test/test_string_utilities_std.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_u16.cpp b/test/test_string_utilities_std_u16.cpp index 18ad0dae..cdf38513 100644 --- a/test/test_string_utilities_std_u16.cpp +++ b/test/test_string_utilities_std_u16.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_u32.cpp b/test/test_string_utilities_std_u32.cpp index 6d90e111..fa3e8fcd 100644 --- a/test/test_string_utilities_std_u32.cpp +++ b/test/test_string_utilities_std_u32.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_wchar_t.cpp b/test/test_string_utilities_std_wchar_t.cpp index 6da25f17..775735a4 100644 --- a/test/test_string_utilities_std_wchar_t.cpp +++ b/test/test_string_utilities_std_wchar_t.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_u16.cpp b/test/test_string_utilities_u16.cpp index fd0e8e88..ecd1f235 100644 --- a/test/test_string_utilities_u16.cpp +++ b/test/test_string_utilities_u16.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_u32.cpp b/test/test_string_utilities_u32.cpp index 4c716e4c..a2c17923 100644 --- a/test/test_string_utilities_u32.cpp +++ b/test/test_string_utilities_u32.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_wchar_t.cpp b/test/test_string_utilities_wchar_t.cpp index 531701f9..e41f294a 100644 --- a/test/test_string_utilities_wchar_t.cpp +++ b/test/test_string_utilities_wchar_t.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 4da60391..c1445b6d 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -29,7 +29,7 @@ SOFTWARE. #include "UnitTest++/UnitTest++.h" #include "etl/string_view.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/wstring.h" #include "etl/u16string.h" #include "etl/u32string.h" diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index b6c851bc..7ab208fa 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,59 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, p_text, etl::strlen(p_text) + 1); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, array_text, etl::size(array_text)); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 2bbe5bf7..3f8ec92b 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -33,7 +33,7 @@ SOFTWARE. #include #include "etl/to_string.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/format_spec.h" #undef STR diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 72b36e51..8fc0701d 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -43,6 +43,7 @@ SOFTWARE. #include "data.h" #include "etl/unordered_map.h" +#include "etl/hash.h" namespace { @@ -73,19 +74,35 @@ namespace return true; } + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef ETL_OR_STD::pair ElementDC; + typedef ETL_OR_STD::pair ElementNDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const std::string& e) const + { + size_t sum = 0U; + return std::accumulate(e.begin(), e.end(), sum); + } + }; +} + +namespace +{ SUITE(test_unordered_map) { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; using DataM = etl::unordered_map>; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; - typedef etl::unordered_map DataDC; typedef etl::unordered_map DataNDC; typedef etl::iunordered_map IDataNDC; @@ -227,6 +244,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_map data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + etl::unordered_map check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 95d16f46..efea060e 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -42,6 +42,19 @@ SOFTWARE. #include "etl/unordered_multimap.h" +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const std::string& e) const + { + size_t sum = 0U; + return std::accumulate(e.begin(), e.end(), sum); + } + }; +} + namespace { //************************************************************************* @@ -71,6 +84,12 @@ namespace return true; } + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef ETL_OR_STD::pair ElementDC; + typedef ETL_OR_STD::pair ElementNDC; + SUITE(test_unordered_multimap) { static const size_t SIZE = 10; @@ -202,6 +221,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_multimap data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + etl::unordered_multimap check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 6dbb3dc7..d60fe472 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -42,15 +42,31 @@ SOFTWARE. #include "etl/unordered_multiset.h" #include "etl/checksum.h" +namespace +{ + typedef TestDataDC DC; + typedef TestDataNDC NDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const NDC& e) const + { + size_t sum = 0U; + return std::accumulate(e.value.begin(), e.value.end(), sum); + } + }; +} + namespace { SUITE(test_unordered_multiset) { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; struct simple_hash @@ -146,6 +162,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::unordered_multiset check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 5d316dd0..cb6c7f19 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -40,6 +40,26 @@ SOFTWARE. #include "etl/unordered_set.h" #include "etl/checksum.h" +#include "etl/hash.h" + +namespace +{ + typedef TestDataDC DC; + typedef TestDataNDC NDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const NDC& e) const + { + size_t sum = 0U; + return std::accumulate(e.value.begin(), e.value.end(), sum); + } + }; +} namespace { @@ -47,9 +67,6 @@ namespace { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; struct simple_hash @@ -138,6 +155,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_set data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::unordered_set check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_utility.cpp b/test/test_utility.cpp index ff39753a..37048471 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -60,7 +60,7 @@ namespace { etl::pair p1; - CHECK_EQUAL(int(), p1.first); + CHECK_EQUAL(int(), p1.first); CHECK_EQUAL(double(), p1.second); } @@ -69,16 +69,30 @@ namespace { etl::pair p1(1, 2.3); - CHECK_EQUAL(1, p1.first); + CHECK_EQUAL(1, p1.first); CHECK_EQUAL(2.3, p1.second); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_pair_construct) + { + etl::pair p1{ 1, 2.3 }; + + CHECK((std::is_same_v)); + CHECK((std::is_same_v)); + + CHECK_EQUAL(1, p1.first); + CHECK_EQUAL(2.3, p1.second); + } +#endif + //************************************************************************* TEST(test_pair_move_parameter_construct) { etl::pair p1(1, 2.3); - CHECK_EQUAL(1, p1.first.value); + CHECK_EQUAL(1, p1.first.value); CHECK_EQUAL(2.3, p1.second.value); } @@ -88,7 +102,7 @@ namespace etl::pair p1(1, 2.3); etl::pair p2(p1); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -101,7 +115,7 @@ namespace CHECK(!bool(p1.first)); CHECK(!bool(p1.second)); - CHECK_EQUAL(1, p2.first.value); + CHECK_EQUAL(1, p2.first.value); CHECK_EQUAL(2.3, p2.second.value); } @@ -111,7 +125,7 @@ namespace etl::pair p1(1, 2.3f); etl::pair p2(p1); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -122,7 +136,7 @@ namespace etl::pair p2; p2 = etl::make_pair(1, 2.3); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -146,10 +160,10 @@ namespace p1.swap(p2); - CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(2, p1.first); CHECK_EQUAL(3.4, p1.second); - CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(1, p2.first); CHECK_EQUAL(2.3, p2.second); } @@ -161,10 +175,10 @@ namespace swap(p1, p2); - CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(2, p1.first); CHECK_EQUAL(3.4, p1.second); - CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(1, p2.first); CHECK_EQUAL(2.3, p2.second); } diff --git a/test/test_vector.cpp b/test/test_vector.cpp index ac4549ea..a7f9e999 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -83,6 +83,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::vector check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 82d533f6..807a92d4 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -92,6 +92,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + etl::vector check = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_destruct_via_ivector) { diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 9bbff8b3..c056b8b5 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -55,26 +55,25 @@ namespace Compare_Data different_data; Compare_Data insert_data; + int n0 = 0; + int n1 = 1; + int n2 = 2; + int n3 = 3; + int n4 = 4; + int n5 = 5; + int n6 = 6; + int n7 = 7; + int n8 = 8; + int n9 = 9; + int n11 = 11; + int n12 = 12; + int n13 = 13; + //************************************************************************* struct SetupFixture { SetupFixture() { - int n0 = 0; - int n1 = 1; - int n2 = 2; - int n3 = 3; - int n4 = 4; - int n5 = 5; - int n6 = 6; - int n7 = 7; - int n8 = 8; - int n9 = 9; - int n11 = 11; - int n12 = 12; - int n13 = 13; - - int* n[] = { &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; int* n_insert[] = { &n11, &n12, &n13 }; int* n_less[] = { &n0, &n1, &n2, &n3, &n3, &n5, &n6, &n7, &n8, &n9 }; @@ -100,6 +99,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; + etl::vector check = { &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_default_constructor) { diff --git a/test/vs2019/etl.sln b/test/vs2019/etl.sln index 9f1b348f..ed4db4f9 100644 --- a/test/vs2019/etl.sln +++ b/test/vs2019/etl.sln @@ -27,6 +27,10 @@ Global Debug MSVC|x64 = Debug MSVC|x64 LLVM New|Win32 = LLVM New|Win32 LLVM New|x64 = LLVM New|x64 + MSVCDebugAppveyor|Win32 = MSVCDebugAppveyor|Win32 + MSVCDebugAppveyor|x64 = MSVCDebugAppveyor|x64 + MSVCDebugNoSTLAppveyor|Win32 = MSVCDebugNoSTLAppveyor|Win32 + MSVCDebugNoSTLAppveyor|x64 = MSVCDebugNoSTLAppveyor|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection @@ -71,6 +75,14 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|Win32.Build.0 = LLVM New|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|x64.ActiveCfg = LLVM New|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|x64.Build.0 = LLVM New|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|Win32.ActiveCfg = MSVCDebugAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|Win32.Build.0 = MSVCDebugAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|x64.ActiveCfg = MSVCDebugAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|x64.Build.0 = MSVCDebugAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|Win32.ActiveCfg = MSVCDebugNoSTLAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|Win32.Build.0 = MSVCDebugNoSTLAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|x64.ActiveCfg = MSVCDebugNoSTLAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|x64.Build.0 = MSVCDebugNoSTLAppveyor|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|Win32.ActiveCfg = Release|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|Win32.Build.0 = Release|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|x64.ActiveCfg = Release|x64 diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 262d2618..f3b511ab 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -89,6 +89,22 @@ LLVM New x64 + + MSVCDebugAppveyor + Win32 + + + MSVCDebugAppveyor + x64 + + + MSVCDebugNoSTLAppveyor + Win32 + + + MSVCDebugNoSTLAppveyor + x64 + Release Win32 @@ -112,6 +128,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -136,6 +158,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -166,6 +194,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -190,6 +224,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -258,6 +298,9 @@ + + + @@ -270,6 +313,9 @@ + + + @@ -285,6 +331,9 @@ + + + @@ -297,6 +346,9 @@ + + + @@ -333,6 +385,11 @@ true \$(IntDir) + + true + true + \$(IntDir) + true true @@ -353,6 +410,11 @@ true \$(IntDir) + + true + true + \$(IntDir) + true true @@ -377,6 +439,10 @@ true true + + true + true + true true @@ -393,6 +459,10 @@ true true + + true + true + true true @@ -455,6 +525,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED;%(PreprocessorDefinitions) + ../../../unittest-cpp/;../../include;../../test + + + false + stdcpp17 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -539,6 +630,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;ETL_NO_STL;ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED;%(PreprocessorDefinitions) + ./;../../../unittest-cpp/;../../include;../../test + + + false + stdcpp17 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -677,6 +789,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -761,6 +894,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -1015,6 +1169,7 @@ + @@ -1122,6 +1277,7 @@ + @@ -1154,7 +1310,6 @@ - @@ -1265,6 +1420,7 @@ + @@ -1304,21 +1460,25 @@ false false false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1343,21 +1503,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1377,21 +1541,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1401,21 +1569,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1425,21 +1597,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1449,21 +1625,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1473,21 +1653,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1502,21 +1686,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1530,21 +1718,25 @@ true true false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1563,21 +1755,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1672,6 +1868,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 849cf756..d4ddadfb 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -79,6 +79,12 @@ {c25471f3-451a-4279-925d-cbdcec912ef8} + + {586d2c92-e504-4dea-9b1f-42d725a5272c} + + + {74399f00-a7a3-47e3-9b27-d01fb2b5ce87} + @@ -666,9 +672,6 @@ ETL\Frameworks - - ETL\Strings - ETL\Strings @@ -876,6 +879,12 @@ ETL\Strings + + ETL\Pseudo Containers + + + ETL\Strings + @@ -1388,6 +1397,9 @@ Source Files + + Source Files + @@ -1447,6 +1459,9 @@ Resource Files\Make + + Resource Files\CI\Appveyor +