From 3f1aa09454304b6c9dd206d0252def42c2c4a576 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 001/216] Work in progress --- include/etl/chrono.h | 39 +++++ include/etl/hash.h | 4 +- include/etl/private/chrono/day.h | 224 ++++++++++++++++++++++++++ include/etl/private/chrono/duration.h | 139 ++++++++++++++++ test/CMakeLists.txt | 3 + test/test_chrono_day.cpp | 216 +++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 3 + test/vs2022/etl.vcxproj.filters | 15 ++ 8 files changed, 641 insertions(+), 2 deletions(-) create mode 100644 include/etl/chrono.h create mode 100644 include/etl/private/chrono/day.h create mode 100644 include/etl/private/chrono/duration.h create mode 100644 test/test_chrono_day.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h new file mode 100644 index 000000000..0cf26e5b4 --- /dev/null +++ b/include/etl/chrono.h @@ -0,0 +1,39 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_INCLUDED +#define ETL_CHRONO_INCLUDED + +#include "platform.h" + +#include "private/chrono/duration.h" +#include "private/chrono/day.h" + +#endif diff --git a/include/etl/hash.h b/include/etl/hash.h index 214ec8c51..9d012941a 100644 --- a/include/etl/hash.h +++ b/include/etl/hash.h @@ -156,8 +156,8 @@ namespace etl /// Specialisation for signed char. ///\ingroup hash //*************************************************************************** - template<> struct - hash + template <> + struct hash { ETL_STATIC_ASSERT(sizeof(size_t) >= sizeof(signed char), "size_t smaller than type"); diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h new file mode 100644 index 000000000..61d19e8b2 --- /dev/null +++ b/include/etl/private/chrono/day.h @@ -0,0 +1,224 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DAY_INCLUDED +#define ETL_CHRONO_DAY_INCLUDED + +#include "../../platform.h" +#include "../../hash.h" + +#include "duration.h" + +#include + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// day + //*********************************************************************** + class day + { + public: + + //*********************************************************************** + ETL_CONSTEXPR day() + : value(0) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(unsigned value_) + : value(value_) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(const etl::chrono::day& other) + : value(other.value) + { + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs) + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + template + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) + { + value = etl::chrono::duration_cast(rhs); + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator ++() ETL_NOEXCEPT + { + ++value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + ++value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator --() ETL_NOEXCEPT + { + --value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator --(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + --value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value += static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value -= static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value >= 1U) && (value <= 31U); + } + + //*********************************************************************** + ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + unsigned char value; + }; + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result -= ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + etl::chrono::days result; + + return etl::chrono::days(static_cast(d1) - static_cast(d2)); + } + } + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::day& d) const + { + unsigned value = d; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT + { + return etl::chrono::day(d); + } + } + } +} + +#endif \ No newline at end of file diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h new file mode 100644 index 000000000..3e4ec95e7 --- /dev/null +++ b/include/etl/private/chrono/duration.h @@ -0,0 +1,139 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DURATION_INCLUDED +#define ETL_CHRONO_DURATION_INCLUDED + +#include "../../platform.h" +#include "../../ratio.h" +#include "../../static_assert.h" +#include "../../limits.h" + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// duration + //*********************************************************************** + template > + class duration + { + public: + + //*********************************************************************** + ETL_CONSTEXPR duration() ETL_NOEXCEPT + { + } + + //*********************************************************************** + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + template< typename TValue2 > + ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT + : value(static_cast(value_)) + { + } + + //*********************************************************************** + template< typename TValue2, typename TPeriod2 > + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(static_cast(other.value)) + { + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + { + return etl::chrono::duration{ 0, TPeriod()}; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + { + return etl::chrono::duration { etl::numeric_limits::min() }; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + { + return etl::chrono::duration{ etl::numeric_limits::max() }; + } + + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR TValue count() const + { + return value; + } + + private: + + TValue value; + //TPeriod period; + }; + + //*********************************************************************** + /// Duration types + //*********************************************************************** +#if (ETL_USING_64BIT_TYPES) + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#else + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#endif + typedef etl::chrono::duration > minutes; + typedef etl::chrono::duration > hours; + typedef etl::chrono::duration > days; + typedef etl::chrono::duration > weeks; + typedef etl::chrono::duration > months; + typedef etl::chrono::duration > years; + + //*********************************************************************** + /// duration_cast + //*********************************************************************** + template + ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) + { + return TToDuration(); + } + } +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index af3359bd6..85265ab18 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,6 +45,9 @@ add_executable(etl_tests test_callback_timer_locked.cpp test_char_traits.cpp test_checksum.cpp + + test_chrono_day.cpp + test_circular_buffer.cpp test_circular_buffer_external_buffer.cpp test_circular_iterator.cpp diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp new file mode 100644 index 000000000..f8a3d4535 --- /dev/null +++ b/test/test_chrono_day.cpp @@ -0,0 +1,216 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#if ETL_USING_CPP20 + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +namespace +{ + SUITE(test_chrono_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + std::chrono::day std_day; + etl::chrono::day day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::day std_day(i); + etl::chrono::day day(i); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + ++std_day; + ++day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day++; + etl::chrono::day last_day = day++; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + --std_day; + --day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day--; + etl::chrono::day last_day = day--; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_plus_equal_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day += std_days; + day += days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_plus_days) + { + std::chrono::day std_day1(0); + std::chrono::day std_day2(0); + etl::chrono::day day1(0); + etl::chrono::day day2(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day1 = std_days + std_day1; + std_day2 = std_day2 + std_days; + + day1 = days + day1; + day2 = day2 + days; + + CHECK_EQUAL(std_day1.ok(), day1.ok()); + CHECK_EQUAL(std_day2.ok(), day2.ok()); + CHECK_EQUAL(unsigned(std_day1), unsigned(day1)); + CHECK_EQUAL(unsigned(std_day2), unsigned(day2)); + } + } + + //************************************************************************* + TEST(test_minus_equal_days) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day -= std_days; + day -= days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_literal_days) + { + using namespace std::literals::chrono_literals; + using namespace etl::literals::chrono_literals; + + std::chrono::day std_day = 25d; + etl::chrono::day day = 25_d; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 96785631a..6809a26e5 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -2942,6 +2942,7 @@ + @@ -3000,6 +3001,7 @@ + @@ -14337,6 +14339,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index e96c1b617..ee1bc81b4 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -220,6 +220,12 @@ {c75cedd3-8b6c-4662-b965-aecbe7fd5d1c} + + {46e23f29-ce01-418f-8331-9c739774414c} + + + {1b1afa65-108a-4665-9e74-3c67a27ff917} + @@ -1362,6 +1368,12 @@ ETL\Utilities + + ETL\Utilities + + + ETL\Private + @@ -3425,6 +3437,9 @@ Tests\Misc + + Tests\Chrono + From 8c78fdab0422a7bf5956fa2433d0d4bbd260a3f6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 002/216] Work in progress --- include/etl/chrono.h | 39 ++++ include/etl/hash.h | 4 +- include/etl/private/chrono/day.h | 271 +++++++++++++++++++++++ include/etl/private/chrono/duration.h | 139 ++++++++++++ test/CMakeLists.txt | 3 + test/test_chrono_day.cpp | 305 ++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 3 + test/vs2022/etl.vcxproj.filters | 15 ++ 8 files changed, 777 insertions(+), 2 deletions(-) create mode 100644 include/etl/chrono.h create mode 100644 include/etl/private/chrono/day.h create mode 100644 include/etl/private/chrono/duration.h create mode 100644 test/test_chrono_day.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h new file mode 100644 index 000000000..0cf26e5b4 --- /dev/null +++ b/include/etl/chrono.h @@ -0,0 +1,39 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_INCLUDED +#define ETL_CHRONO_INCLUDED + +#include "platform.h" + +#include "private/chrono/duration.h" +#include "private/chrono/day.h" + +#endif diff --git a/include/etl/hash.h b/include/etl/hash.h index 214ec8c51..9d012941a 100644 --- a/include/etl/hash.h +++ b/include/etl/hash.h @@ -156,8 +156,8 @@ namespace etl /// Specialisation for signed char. ///\ingroup hash //*************************************************************************** - template<> struct - hash + template <> + struct hash { ETL_STATIC_ASSERT(sizeof(size_t) >= sizeof(signed char), "size_t smaller than type"); diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h new file mode 100644 index 000000000..b04d3898d --- /dev/null +++ b/include/etl/private/chrono/day.h @@ -0,0 +1,271 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DAY_INCLUDED +#define ETL_CHRONO_DAY_INCLUDED + +#include "../../platform.h" +#include "../../hash.h" + +#include "duration.h" + +#include + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// day + //*********************************************************************** + class day + { + public: + + //*********************************************************************** + ETL_CONSTEXPR day() + : value(0) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(unsigned value_) + : value(value_) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(const etl::chrono::day& other) + : value(other.value) + { + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs) + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + template + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) + { + value = etl::chrono::duration_cast(rhs); + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator ++() ETL_NOEXCEPT + { + ++value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + ++value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator --() ETL_NOEXCEPT + { + --value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator --(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + --value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value += static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value -= static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value >= 1U) && (value <= 31U); + } + + //*********************************************************************** + ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + unsigned char value; + }; + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result -= ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return etl::chrono::days(static_cast(static_cast(d1)) - + static_cast(static_cast(d2))); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) == static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return !(d1 == d2); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) < static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) <= static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) > static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) >= static_cast(d2)); + } + + //*********************************************************************** +#if ETL_USING_CPP20 + ETL_CONSTEXPR auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) + { + return (static_cast(d1) <=> static_cast(d2)); + } +#endif + } + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::day& d) const + { + unsigned value = d; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for days + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT + { + return etl::chrono::day(d); + } + } + } +} +#endif + +#endif \ No newline at end of file diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h new file mode 100644 index 000000000..3e4ec95e7 --- /dev/null +++ b/include/etl/private/chrono/duration.h @@ -0,0 +1,139 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DURATION_INCLUDED +#define ETL_CHRONO_DURATION_INCLUDED + +#include "../../platform.h" +#include "../../ratio.h" +#include "../../static_assert.h" +#include "../../limits.h" + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// duration + //*********************************************************************** + template > + class duration + { + public: + + //*********************************************************************** + ETL_CONSTEXPR duration() ETL_NOEXCEPT + { + } + + //*********************************************************************** + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + template< typename TValue2 > + ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT + : value(static_cast(value_)) + { + } + + //*********************************************************************** + template< typename TValue2, typename TPeriod2 > + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(static_cast(other.value)) + { + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + { + return etl::chrono::duration{ 0, TPeriod()}; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + { + return etl::chrono::duration { etl::numeric_limits::min() }; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + { + return etl::chrono::duration{ etl::numeric_limits::max() }; + } + + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR TValue count() const + { + return value; + } + + private: + + TValue value; + //TPeriod period; + }; + + //*********************************************************************** + /// Duration types + //*********************************************************************** +#if (ETL_USING_64BIT_TYPES) + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#else + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#endif + typedef etl::chrono::duration > minutes; + typedef etl::chrono::duration > hours; + typedef etl::chrono::duration > days; + typedef etl::chrono::duration > weeks; + typedef etl::chrono::duration > months; + typedef etl::chrono::duration > years; + + //*********************************************************************** + /// duration_cast + //*********************************************************************** + template + ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) + { + return TToDuration(); + } + } +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index af3359bd6..85265ab18 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,6 +45,9 @@ add_executable(etl_tests test_callback_timer_locked.cpp test_char_traits.cpp test_checksum.cpp + + test_chrono_day.cpp + test_circular_buffer.cpp test_circular_buffer_external_buffer.cpp test_circular_iterator.cpp diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp new file mode 100644 index 000000000..e6de125c6 --- /dev/null +++ b/test/test_chrono_day.cpp @@ -0,0 +1,305 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#if ETL_USING_CPP20 + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +namespace +{ + SUITE(test_chrono_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + std::chrono::day std_day; + etl::chrono::day day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::day std_day(i); + etl::chrono::day day(i); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + ++std_day; + ++day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day++; + etl::chrono::day last_day = day++; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + --std_day; + --day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day--; + etl::chrono::day last_day = day--; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_plus_equal_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day += std_days; + day += days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_plus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day + std_days; + day = day + days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_days_plus_day) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_days + std_day; + day = days + day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_minus_equal_days) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day -= std_days; + day -= days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day - std_days; + day = day - days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_day) + { + for (int i = 1; i < 31; ++i) + { + std::chrono::day std_day1(i); + std::chrono::day std_day2(31 - i); + + etl::chrono::day day1(i); + etl::chrono::day day2(31 - i); + + std::chrono::days std_days = std_day1 - std_day2; + etl::chrono::days days = day1 - day2; + + CHECK_EQUAL(std_days.count(), days.count()); + } + } + + //************************************************************************* + TEST(test_literal_days) + { + using namespace std::literals::chrono_literals; + using namespace etl::literals::chrono_literals; + + std::chrono::day std_day = 25d; + etl::chrono::day day = 25_d; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + + //************************************************************************* + TEST(test_day_comparison_operators) + { + etl::chrono::day day10(10); + etl::chrono::day day20(20); + + CHECK_TRUE(day10 == day10); + CHECK_FALSE(day10 != day10); + CHECK_TRUE(day10 < day20); + CHECK_FALSE(day10 < day10); + CHECK_FALSE(day20 < day10); + CHECK_TRUE(day10 <= day20); + CHECK_TRUE(day10 <= day10); + CHECK_FALSE(day20 <= day10); + CHECK_FALSE(day10 > day20); + CHECK_FALSE(day10 > day10); + CHECK_TRUE(day20 > day10); + CHECK_FALSE(day10 >= day20); + CHECK_TRUE(day10 >= day10); + CHECK_TRUE(day20 >= day10); + +#if ETL_USING_CPP20 + CHECK_TRUE((day10 <=> day10) == 0); + CHECK_TRUE((day10 <=> day20) < 0); + CHECK_TRUE((day20 <=> day10) > 0); +#endif + } + + //************************************************************************* + TEST(test_day_hash) + { + etl::chrono::day day(10); + + size_t h = 0; + + h = etl::hash()(day); + + CHECK_TRUE(h != 0); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 96785631a..6809a26e5 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -2942,6 +2942,7 @@ + @@ -3000,6 +3001,7 @@ + @@ -14337,6 +14339,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index e96c1b617..ee1bc81b4 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -220,6 +220,12 @@ {c75cedd3-8b6c-4662-b965-aecbe7fd5d1c} + + {46e23f29-ce01-418f-8331-9c739774414c} + + + {1b1afa65-108a-4665-9e74-3c67a27ff917} + @@ -1362,6 +1368,12 @@ ETL\Utilities + + ETL\Utilities + + + ETL\Private + @@ -3425,6 +3437,9 @@ Tests\Misc + + Tests\Chrono + From fc0576ad9512f284bbbc726a56f65de2e83b1bf2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 003/216] Work in progress --- include/etl/chrono.h | 39 ++++ include/etl/hash.h | 4 +- include/etl/private/chrono/day.h | 271 +++++++++++++++++++++++ include/etl/private/chrono/duration.h | 139 ++++++++++++ test/CMakeLists.txt | 3 + test/test_chrono_day.cpp | 305 ++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 3 + test/vs2022/etl.vcxproj.filters | 15 ++ 8 files changed, 777 insertions(+), 2 deletions(-) create mode 100644 include/etl/chrono.h create mode 100644 include/etl/private/chrono/day.h create mode 100644 include/etl/private/chrono/duration.h create mode 100644 test/test_chrono_day.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h new file mode 100644 index 000000000..0cf26e5b4 --- /dev/null +++ b/include/etl/chrono.h @@ -0,0 +1,39 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_INCLUDED +#define ETL_CHRONO_INCLUDED + +#include "platform.h" + +#include "private/chrono/duration.h" +#include "private/chrono/day.h" + +#endif diff --git a/include/etl/hash.h b/include/etl/hash.h index 8066a0123..2397f0257 100644 --- a/include/etl/hash.h +++ b/include/etl/hash.h @@ -159,8 +159,8 @@ namespace etl /// Specialisation for signed char. ///\ingroup hash //*************************************************************************** - template<> struct - hash + template <> + struct hash { ETL_STATIC_ASSERT(sizeof(size_t) >= sizeof(signed char), "size_t smaller than type"); diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h new file mode 100644 index 000000000..b04d3898d --- /dev/null +++ b/include/etl/private/chrono/day.h @@ -0,0 +1,271 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DAY_INCLUDED +#define ETL_CHRONO_DAY_INCLUDED + +#include "../../platform.h" +#include "../../hash.h" + +#include "duration.h" + +#include + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// day + //*********************************************************************** + class day + { + public: + + //*********************************************************************** + ETL_CONSTEXPR day() + : value(0) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(unsigned value_) + : value(value_) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(const etl::chrono::day& other) + : value(other.value) + { + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs) + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + template + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) + { + value = etl::chrono::duration_cast(rhs); + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator ++() ETL_NOEXCEPT + { + ++value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + ++value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator --() ETL_NOEXCEPT + { + --value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator --(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + --value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value += static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value -= static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value >= 1U) && (value <= 31U); + } + + //*********************************************************************** + ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + unsigned char value; + }; + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result -= ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return etl::chrono::days(static_cast(static_cast(d1)) - + static_cast(static_cast(d2))); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) == static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return !(d1 == d2); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) < static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) <= static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) > static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) >= static_cast(d2)); + } + + //*********************************************************************** +#if ETL_USING_CPP20 + ETL_CONSTEXPR auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) + { + return (static_cast(d1) <=> static_cast(d2)); + } +#endif + } + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::day& d) const + { + unsigned value = d; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for days + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT + { + return etl::chrono::day(d); + } + } + } +} +#endif + +#endif \ No newline at end of file diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h new file mode 100644 index 000000000..3e4ec95e7 --- /dev/null +++ b/include/etl/private/chrono/duration.h @@ -0,0 +1,139 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DURATION_INCLUDED +#define ETL_CHRONO_DURATION_INCLUDED + +#include "../../platform.h" +#include "../../ratio.h" +#include "../../static_assert.h" +#include "../../limits.h" + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// duration + //*********************************************************************** + template > + class duration + { + public: + + //*********************************************************************** + ETL_CONSTEXPR duration() ETL_NOEXCEPT + { + } + + //*********************************************************************** + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + template< typename TValue2 > + ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT + : value(static_cast(value_)) + { + } + + //*********************************************************************** + template< typename TValue2, typename TPeriod2 > + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(static_cast(other.value)) + { + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + { + return etl::chrono::duration{ 0, TPeriod()}; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + { + return etl::chrono::duration { etl::numeric_limits::min() }; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + { + return etl::chrono::duration{ etl::numeric_limits::max() }; + } + + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR TValue count() const + { + return value; + } + + private: + + TValue value; + //TPeriod period; + }; + + //*********************************************************************** + /// Duration types + //*********************************************************************** +#if (ETL_USING_64BIT_TYPES) + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#else + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#endif + typedef etl::chrono::duration > minutes; + typedef etl::chrono::duration > hours; + typedef etl::chrono::duration > days; + typedef etl::chrono::duration > weeks; + typedef etl::chrono::duration > months; + typedef etl::chrono::duration > years; + + //*********************************************************************** + /// duration_cast + //*********************************************************************** + template + ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) + { + return TToDuration(); + } + } +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cad0feaeb..d152f2d6d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -57,6 +57,9 @@ add_executable(etl_tests test_callback_timer_locked.cpp test_char_traits.cpp test_checksum.cpp + + test_chrono_day.cpp + test_circular_buffer.cpp test_circular_buffer_external_buffer.cpp test_circular_iterator.cpp diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp new file mode 100644 index 000000000..e6de125c6 --- /dev/null +++ b/test/test_chrono_day.cpp @@ -0,0 +1,305 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#if ETL_USING_CPP20 + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +namespace +{ + SUITE(test_chrono_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + std::chrono::day std_day; + etl::chrono::day day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::day std_day(i); + etl::chrono::day day(i); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + ++std_day; + ++day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day++; + etl::chrono::day last_day = day++; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + --std_day; + --day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day--; + etl::chrono::day last_day = day--; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_plus_equal_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day += std_days; + day += days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_plus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day + std_days; + day = day + days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_days_plus_day) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_days + std_day; + day = days + day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_minus_equal_days) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day -= std_days; + day -= days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day - std_days; + day = day - days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_day) + { + for (int i = 1; i < 31; ++i) + { + std::chrono::day std_day1(i); + std::chrono::day std_day2(31 - i); + + etl::chrono::day day1(i); + etl::chrono::day day2(31 - i); + + std::chrono::days std_days = std_day1 - std_day2; + etl::chrono::days days = day1 - day2; + + CHECK_EQUAL(std_days.count(), days.count()); + } + } + + //************************************************************************* + TEST(test_literal_days) + { + using namespace std::literals::chrono_literals; + using namespace etl::literals::chrono_literals; + + std::chrono::day std_day = 25d; + etl::chrono::day day = 25_d; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + + //************************************************************************* + TEST(test_day_comparison_operators) + { + etl::chrono::day day10(10); + etl::chrono::day day20(20); + + CHECK_TRUE(day10 == day10); + CHECK_FALSE(day10 != day10); + CHECK_TRUE(day10 < day20); + CHECK_FALSE(day10 < day10); + CHECK_FALSE(day20 < day10); + CHECK_TRUE(day10 <= day20); + CHECK_TRUE(day10 <= day10); + CHECK_FALSE(day20 <= day10); + CHECK_FALSE(day10 > day20); + CHECK_FALSE(day10 > day10); + CHECK_TRUE(day20 > day10); + CHECK_FALSE(day10 >= day20); + CHECK_TRUE(day10 >= day10); + CHECK_TRUE(day20 >= day10); + +#if ETL_USING_CPP20 + CHECK_TRUE((day10 <=> day10) == 0); + CHECK_TRUE((day10 <=> day20) < 0); + CHECK_TRUE((day20 <=> day10) > 0); +#endif + } + + //************************************************************************* + TEST(test_day_hash) + { + etl::chrono::day day(10); + + size_t h = 0; + + h = etl::hash()(day); + + CHECK_TRUE(h != 0); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index c0aa5d92b..a75e23c5b 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3027,6 +3027,7 @@ + @@ -3091,6 +3092,7 @@ + @@ -7751,6 +7753,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 37ae37e69..1a3a341a1 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -220,6 +220,12 @@ {c75cedd3-8b6c-4662-b965-aecbe7fd5d1c} + + {46e23f29-ce01-418f-8331-9c739774414c} + + + {1b1afa65-108a-4665-9e74-3c67a27ff917} + {6bbca8f0-f707-45ee-9dad-6d41d401bbaf} @@ -1371,6 +1377,12 @@ ETL\Utilities + + ETL\Utilities + + + ETL\Utilities + ETL\Codecs @@ -2486,6 +2498,9 @@ Tests\Misc + + Tests\Chrono + Tests\Syntax Checks\Source From a90d0f4a89f28ae972e877319e605ef5366dfd22 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 29 Aug 2024 09:45:58 +0100 Subject: [PATCH 004/216] Fixed value type --- include/etl/private/chrono/day.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index b04d3898d..8079680d6 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -146,7 +146,7 @@ namespace etl private: - unsigned char value; + unsigned value; }; //*********************************************************************** From 10147a1868e404931ca1b8417b2430f35e74d41b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 30 Aug 2024 19:59:16 +0100 Subject: [PATCH 005/216] Updates to weekday --- include/etl/private/chrono/day.h | 28 +-- include/etl/private/chrono/duration.h | 21 +- include/etl/private/chrono/month.h | 30 +-- include/etl/private/chrono/weekday.h | 87 ++++----- include/etl/private/chrono/year.h | 30 +-- test/test_chrono_weekday.cpp | 263 +++++++++++++------------- test/test_chrono_year.cpp | 18 +- 7 files changed, 238 insertions(+), 239 deletions(-) diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 812ef06c5..91557a957 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -55,7 +55,7 @@ namespace etl /// Construct from unsigned //*********************************************************************** ETL_CONSTEXPR explicit day(unsigned value_) ETL_NOEXCEPT - : value(value_) + : value(static_cast(value_)) { } @@ -83,6 +83,8 @@ namespace etl ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) { value = etl::chrono::duration_cast(rhs); + + return *this; } //*********************************************************************** @@ -148,7 +150,7 @@ namespace etl //*********************************************************************** /// Returns true if the day is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (value >= 1U) && (value <= 31U); } @@ -164,7 +166,7 @@ namespace etl //*********************************************************************** /// The minimum day value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::day min() ETL_NOEXCEPT { return etl::chrono::day(1); } @@ -172,7 +174,7 @@ namespace etl //*********************************************************************** /// The maximum day value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::day max() ETL_NOEXCEPT { return etl::chrono::day(31); } @@ -185,7 +187,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) == static_cast(d2)); } @@ -193,7 +195,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return !(d1 == d2); } @@ -209,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) <= static_cast(d2)); } @@ -217,7 +219,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) > static_cast(d2)); } @@ -225,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return (static_cast(d1) >= static_cast(d2)); } @@ -244,7 +246,7 @@ namespace etl /// Add etl::chrono::days to etl::chrono::day ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -257,7 +259,7 @@ namespace etl /// Add etl::chrono::day to etl::chrono::days ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -270,7 +272,7 @@ namespace etl /// Subtract etl::chrono::days from etl::chrono::day ///\return etl::chrono::day //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { etl::chrono::day result(d); @@ -283,7 +285,7 @@ namespace etl /// Subtract etl::chrono::day from etl::chrono::day ///\return etl::chrono::days //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { return etl::chrono::days(static_cast(static_cast(d1)) - static_cast(static_cast(d2))); diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 553ba1234..b499f0f40 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -76,25 +76,25 @@ namespace etl } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT { return etl::chrono::duration{ 0, TPeriod()}; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT { return etl::chrono::duration { etl::numeric_limits::min() }; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT { return etl::chrono::duration{ etl::numeric_limits::max() }; } //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT + ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT { return value; } @@ -131,9 +131,16 @@ namespace etl template ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT { - return TToDuration(); + using to_value_type = typename TToDuration::value_type; + using to_period = typename TToDuration::period; + + // Calculate the conversion factor between the periods + ETL_CONSTEXPR auto conversion_factor = (static_cast(TPeriod::num) / TPeriod::den) * (to_period::den / to_period::num); + + // Convert the value + to_value_type converted_value = static_cast(d.count() * conversion_factor); + + return TToDuration(converted_value); } } } - -#endif diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 907b5d845..30653a589 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -150,7 +150,7 @@ namespace etl //*********************************************************************** /// Returns true if the month is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (value >= 1U) && (value <= 12U); } @@ -158,7 +158,7 @@ namespace etl //*********************************************************************** /// The minimum month value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::month min() ETL_NOEXCEPT { return etl::chrono::month(1); } @@ -166,7 +166,7 @@ namespace etl //*********************************************************************** /// The maximum month value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::month max() ETL_NOEXCEPT { return etl::chrono::month(12); } @@ -184,7 +184,7 @@ namespace etl //*********************************************************************** /// Normalise to a in-range month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT { value = ((value % 12U) == 0U) ? 12U : value; } @@ -195,7 +195,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) == static_cast(d2)); } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return !(d1 == d2); } @@ -211,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) < static_cast(d2)); } @@ -219,7 +219,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) <= static_cast(d2)); } @@ -227,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) > static_cast(d2)); } @@ -235,7 +235,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT { return (static_cast(d1) >= static_cast(d2)); } @@ -254,7 +254,7 @@ namespace etl /// Add etl::chrono::months to etl::chrono::month ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT { unsigned int value = static_cast(m); @@ -280,7 +280,7 @@ namespace etl /// Add etl::chrono::month to etl::chrono::months ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT { return m + ms; } @@ -289,7 +289,7 @@ namespace etl /// Subtract etl::chrono::months from etl::chrono::month ///\return etl::chrono::month //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT { return m + etl::chrono::months(-ms.count()); } @@ -298,7 +298,7 @@ namespace etl /// Subtract etl::chrono::month from etl::chrono::month ///\return etl::chrono::months //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT { if (m1.ok() && m2.ok()) { @@ -374,7 +374,7 @@ namespace etl //*********************************************************************** constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept { - return etl::chrono::month(m); + return etl::chrono::month(static_cast(m)); } } } diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index aafb8ee0f..fc4df27fa 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -64,7 +64,7 @@ namespace etl /// Construct from unsigned //*********************************************************************** ETL_CONSTEXPR explicit weekday(unsigned value_) ETL_NOEXCEPT - : value(value_) + : value(value_ == 7U ? 0U :value_) { } @@ -153,7 +153,7 @@ namespace etl //*********************************************************************** /// Returns true if the weekday is within the valid 1 to 31 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { return (c_encoding() <= 6U); } @@ -161,7 +161,7 @@ namespace etl //*********************************************************************** /// The minimum weekday value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT { return etl::chrono::weekday(0); } @@ -169,7 +169,7 @@ namespace etl //*********************************************************************** /// The maximum weekday value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT { return etl::chrono::weekday(6); } @@ -177,15 +177,15 @@ namespace etl //*********************************************************************** /// Get the C encoding of the weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT + ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT { - return (value == 7U) ? 0U : value; + return value; } //*********************************************************************** /// Get the ISO encoding of the weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT + ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT { return (value == 0U) ? 7U : value; } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Returns true if the day is a weekend. //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT + ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT { return (c_encoding() == 0U) || (c_encoding() == 6U); } @@ -213,7 +213,7 @@ namespace etl //*********************************************************************** /// Normalise to a in-range weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT { value %= 7U; } @@ -224,7 +224,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() == wd2.c_encoding()); } @@ -232,7 +232,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return !(wd1 == wd2); } @@ -240,7 +240,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() < wd2.c_encoding()); } @@ -248,7 +248,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() <= wd2.c_encoding()); } @@ -256,7 +256,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() > wd2.c_encoding()); } @@ -264,7 +264,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { return (wd1.c_encoding() >= wd2.c_encoding()); } @@ -283,15 +283,14 @@ namespace etl /// Add etl::chrono::days to etl::chrono::weekday ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT { - unsigned int value = wd.c_encoding(); - - value = value % 7U; - int delta = ds.count() % 7; + unsigned int value = wd.c_encoding(); + // Adjust to allow a limited +-7 weekday delta + value %= 7U; value += 7U; value += delta; value %= 7U; @@ -303,7 +302,7 @@ namespace etl /// Add etl::chrono::weekday to etl::chrono::days ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT { return wd + ds; } @@ -312,7 +311,7 @@ namespace etl /// Subtract etl::chrono::days from etl::chrono::weekday ///\return etl::chrono::weekday //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT { return m + etl::chrono::days(-ds.count()); } @@ -321,38 +320,34 @@ namespace etl /// Subtract etl::chrono::weekday from etl::chrono::weekday ///\return etl::chrono::days //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT { if (wd1.ok() && wd2.ok()) { - etl::chrono::days ds(static_cast(wd1.c_encoding()) - - static_cast(wd2.c_encoding()) % 12); - - if (wd1 == (wd2 + ds)) - { - return ds; - } + int diff = static_cast(wd1.c_encoding()) - static_cast(wd2.c_encoding()); + + return etl::chrono::days((diff + 7) % 7); } - return etl::chrono::days(); + return etl::chrono::days(0); } #if ETL_USING_CPP17 - inline constexpr etl::chrono::weekday Sunday{ 0 }; - inline constexpr etl::chrono::weekday Monday{ 1 }; - inline constexpr etl::chrono::weekday Tuesday{ 2 }; - inline constexpr etl::chrono::weekday Wednesday{ 3 }; - inline constexpr etl::chrono::weekday Thursday{ 4 }; - inline constexpr etl::chrono::weekday Friday{ 5 }; - inline constexpr etl::chrono::weekday Saturday{ 6 }; + inline constexpr etl::chrono::weekday Sunday{ 0U }; + inline constexpr etl::chrono::weekday Monday{ 1U }; + inline constexpr etl::chrono::weekday Tuesday{ 2U }; + inline constexpr etl::chrono::weekday Wednesday{ 3U }; + inline constexpr etl::chrono::weekday Thursday{ 4U }; + inline constexpr etl::chrono::weekday Friday{ 5U }; + inline constexpr etl::chrono::weekday Saturday{ 6U }; #else - static ETL_CONSTANT etl::chrono::weekday Sunday{ 0 }; - static ETL_CONSTANT etl::chrono::weekday Monday{ 1 }; - static ETL_CONSTANT etl::chrono::weekday Tuesday{ 2 }; - static ETL_CONSTANT etl::chrono::weekday Wednesday{ 3 }; - static ETL_CONSTANT etl::chrono::weekday Thursday{ 4 }; - static ETL_CONSTANT etl::chrono::weekday Friday{ 5 }; - static ETL_CONSTANT etl::chrono::weekday Saturday{ 6 }; + static ETL_CONSTANT etl::chrono::weekday Sunday{ 0U }; + static ETL_CONSTANT etl::chrono::weekday Monday{ 1U }; + static ETL_CONSTANT etl::chrono::weekday Tuesday{ 2U }; + static ETL_CONSTANT etl::chrono::weekday Wednesday{ 3U }; + static ETL_CONSTANT etl::chrono::weekday Thursday{ 4U }; + static ETL_CONSTANT etl::chrono::weekday Friday{ 5U }; + static ETL_CONSTANT etl::chrono::weekday Saturday{ 6U }; #endif } @@ -387,7 +382,7 @@ namespace etl //*********************************************************************** constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept { - return etl::chrono::weekday(m); + return etl::chrono::weekday(static_cast(m)); } } } diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index 1b8cb517d..ff873e37b 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -142,15 +142,15 @@ namespace etl //*********************************************************************** /// Returns true if the year is within the valid -32767 to 32767 range //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { - return (value >= -32767) && (value <= 32767); + return (value != -32768); } //*********************************************************************** /// The minimum year value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::year min() ETL_NOEXCEPT { return etl::chrono::year(-32767); } @@ -158,7 +158,7 @@ namespace etl //*********************************************************************** /// The maximum year value for which ok() will return true //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::year max() ETL_NOEXCEPT { return etl::chrono::year(32767); } @@ -166,7 +166,7 @@ namespace etl //*********************************************************************** /// Returns true if the year is a leap year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT + ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT { return ((value % 4) == 0) && !((value % 400) == 0); } @@ -187,7 +187,7 @@ namespace etl //*********************************************************************** /// Equality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) == static_cast(y2)); } @@ -195,7 +195,7 @@ namespace etl //*********************************************************************** /// Inequality operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return !(y1 == y2); } @@ -203,7 +203,7 @@ namespace etl //*********************************************************************** /// Less-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) < static_cast(y2)); } @@ -211,7 +211,7 @@ namespace etl //*********************************************************************** /// Less-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) <= static_cast(y2)); } @@ -219,7 +219,7 @@ namespace etl //*********************************************************************** /// Greater-than operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) > static_cast(y2)); } @@ -227,7 +227,7 @@ namespace etl //*********************************************************************** /// Greater-than-or-equal operator //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return (static_cast(y1) >= static_cast(y2)); } @@ -246,7 +246,7 @@ namespace etl /// Add etl::chrono::years to etl::chrono::year ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -259,7 +259,7 @@ namespace etl /// Add etl::chrono::year to etl::chrono::years ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -272,7 +272,7 @@ namespace etl /// Subtract etl::chrono::years from etl::chrono::year ///\return etl::chrono::year //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT { etl::chrono::year result(y); @@ -285,7 +285,7 @@ namespace etl /// Subtract etl::chrono::year from etl::chrono::year ///\return etl::chrono::years //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return etl::chrono::years(static_cast(static_cast(y1)) - static_cast(static_cast(y2))); diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index 0594ea758..c4cbe05d8 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -30,13 +30,12 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" #include + #include #include @@ -47,129 +46,138 @@ namespace //************************************************************************* TEST(test_default_constructor) { - std::chrono::weekday std_weekday; etl::chrono::weekday weekday; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); + CHECK_FALSE(weekday.ok()); } //************************************************************************* TEST(test_constructor_in_range) { - for (unsigned i = 0U; i < 256U; ++i) + for (unsigned i = 0U; i < 7U; ++i) { - std::chrono::weekday std_weekday(i); etl::chrono::weekday weekday(i); - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); } } //************************************************************************* - TEST(test_encodings) + TEST(test_constructor_out_of_range) { - std::chrono::weekday std_weekday; - etl::chrono::weekday weekday; - - for (unsigned i = 0U; i < 256; ++i) + for (unsigned i = 8U; i < 256U; ++i) { - std_weekday = std::chrono::weekday(i); - weekday = etl::chrono::weekday(i); + etl::chrono::weekday weekday(i); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); - CHECK_EQUAL(std_weekday.iso_encoding(), weekday.iso_encoding()); + CHECK_FALSE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::weekday std_weekday(0); etl::chrono::weekday weekday(0); + unsigned count = 0; for (int i = 0; i < 255; ++i) { - ++std_weekday; ++weekday; + ++count; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_post_increment) { - std::chrono::weekday std_weekday(0); etl::chrono::weekday weekday(0); + unsigned count = 0; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - std::chrono::weekday std_last_weekday = std_weekday++; - etl::chrono::weekday last_weekday = weekday++; + etl::chrono::weekday last_weekday = weekday++; + unsigned last_count = count++; - CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok()); - CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding()); + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::weekday std_weekday(255); - etl::chrono::weekday weekday(255); + etl::chrono::weekday weekday(255U); + unsigned count = 255U; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - --std_weekday; --weekday; + --count; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::weekday std_weekday(255); - etl::chrono::weekday weekday(255); + etl::chrono::weekday weekday(255U); + unsigned count = 255U; - for (int i = 0; i < 256; ++i) + for (int i = 0; i < 255; ++i) { - std::chrono::weekday std_last_weekday = std_weekday--; etl::chrono::weekday last_weekday = weekday--; + unsigned last_count = count--; - CHECK_EQUAL(std_last_weekday.ok(), last_weekday.ok()); - CHECK_EQUAL(std_last_weekday.c_encoding(), last_weekday.c_encoding()); + if (last_count == 255U) + { + CHECK_FALSE(last_weekday.ok()); + CHECK_EQUAL(255U, last_weekday.c_encoding()); + CHECK_EQUAL(255U, last_weekday.iso_encoding()); + } + else + { + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); + } - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); } } //************************************************************************* TEST(test_plus_equal_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday += days; - std_weekday += std_days; - weekday += days; + unsigned expected = (wd + ds) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -177,21 +185,19 @@ namespace //************************************************************************* TEST(test_weekday_plus_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday + days; - std_weekday = std_weekday + std_days; - weekday = weekday + days; + unsigned expected = (wd + ds) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -199,21 +205,19 @@ namespace //************************************************************************* TEST(test_days_plus_weekday) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday + days; - std_weekday = std_days + std_weekday; - weekday = days + weekday; + unsigned expected = (ds + wd) % 7; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -221,21 +225,19 @@ namespace //************************************************************************* TEST(test_minus_equal_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday -= days; - std_weekday -= std_days; - weekday -= days; + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -243,21 +245,19 @@ namespace //************************************************************************* TEST(test_weekday_minus_days) { - for (int wd = 0; wd <= 6; ++wd) + for (unsigned wd = 0; wd <= 6; ++wd) { - for (int ds = 0; ds <= 14; ++ds) + for (unsigned ds = 0; ds <= 14; ++ds) { - std::chrono::weekday std_weekday(wd); etl::chrono::weekday weekday(wd); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); + weekday = weekday - days; - std_weekday = std_weekday - std_days; - weekday = weekday - days; + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; - CHECK_EQUAL(std_weekday.ok(), weekday.ok()); - CHECK_EQUAL(std_weekday.c_encoding(), weekday.c_encoding()); + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); } } } @@ -265,20 +265,20 @@ namespace //************************************************************************* TEST(test_weekday_minus_weekday) { - for (int m = 0; m < 256; ++m) + for (int m = 0; m < 7; ++m) { + etl::chrono::weekday weekday1(m); + etl::chrono::weekday weekday2(7 - m); + std::chrono::weekday std_weekday1(m); - std::chrono::weekday std_weekday2(255 - m); + std::chrono::weekday std_weekday2(7 - m); - std::chrono::weekday weekday1(m); - std::chrono::weekday weekday2(255 - m); + auto days12 = weekday1 - weekday2; + auto days21 = weekday2 - weekday1; auto std_days12 = std_weekday1 - std_weekday2; auto std_days21 = std_weekday2 - std_weekday1; - auto days12 = weekday1 - weekday2; - auto days21 = weekday2 - weekday1; - CHECK_EQUAL(std_days12.count(), days12.count()); CHECK_EQUAL(std_days21.count(), days21.count()); } @@ -292,7 +292,19 @@ namespace } //************************************************************************* - TEST(test_literal_weekday) + TEST(test_weekday_constants) + { + CHECK_EQUAL(0U, etl::chrono::Sunday.c_encoding()); + CHECK_EQUAL(1U, etl::chrono::Monday.c_encoding()); + CHECK_EQUAL(2U, etl::chrono::Tuesday.c_encoding()); + CHECK_EQUAL(3U, etl::chrono::Wednesday.c_encoding()); + CHECK_EQUAL(4U, etl::chrono::Thursday.c_encoding()); + CHECK_EQUAL(5U, etl::chrono::Friday.c_encoding()); + CHECK_EQUAL(6U, etl::chrono::Saturday.c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_literals) { using namespace etl::literals::chrono_literals; @@ -324,28 +336,28 @@ namespace //************************************************************************* TEST(test_weekday_comparison_operators) { - etl::chrono::weekday weekday1(1); - etl::chrono::weekday weekday2(2); - - CHECK_TRUE(weekday1 == weekday1); - CHECK_FALSE(weekday1 != weekday1); - CHECK_TRUE(weekday1 < weekday2); - CHECK_FALSE(weekday1 < weekday1); - CHECK_FALSE(weekday2 < weekday1); - CHECK_TRUE(weekday1 <= weekday2); - CHECK_TRUE(weekday1 <= weekday1); - CHECK_FALSE(weekday2 <= weekday1); - CHECK_FALSE(weekday1 > weekday2); - CHECK_FALSE(weekday1 > weekday1); - CHECK_TRUE(weekday2 > weekday1); - CHECK_FALSE(weekday1 >= weekday2); - CHECK_TRUE(weekday1 >= weekday1); - CHECK_TRUE(weekday2 >= weekday1); + etl::chrono::weekday weekday1(1); + etl::chrono::weekday weekday2(2); + + CHECK_TRUE(weekday1 == weekday1); + CHECK_FALSE(weekday1 != weekday1); + CHECK_TRUE(weekday1 < weekday2); + CHECK_FALSE(weekday1 < weekday1); + CHECK_FALSE(weekday2 < weekday1); + CHECK_TRUE(weekday1 <= weekday2); + CHECK_TRUE(weekday1 <= weekday1); + CHECK_FALSE(weekday2 <= weekday1); + CHECK_FALSE(weekday1 > weekday2); + CHECK_FALSE(weekday1 > weekday1); + CHECK_TRUE(weekday2 > weekday1); + CHECK_FALSE(weekday1 >= weekday2); + CHECK_TRUE(weekday1 >= weekday1); + CHECK_TRUE(weekday2 >= weekday1); #if ETL_USING_CPP20 - CHECK_TRUE((weekday1 <=> weekday1) == 0); - CHECK_TRUE((weekday1 <=> weekday2) < 0); - CHECK_TRUE((weekday2 <=> weekday1) > 0); + CHECK_TRUE((weekday1 <=> weekday1) == 0); + CHECK_TRUE((weekday1 <=> weekday2) < 0); + CHECK_TRUE((weekday2 <=> weekday1) > 0); #endif } @@ -363,24 +375,5 @@ namespace (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } - - //************************************************************************* - TEST(test_weekday_types) - { - CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); - CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); - CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); - CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); - CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); - CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); - CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); - CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); - CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); - CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); - CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); - CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); - } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index e927668f7..dacb9c06b 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include "etl/chrono.h" #include +#include namespace { @@ -59,24 +60,25 @@ namespace std::chrono::year std_year(i); etl::chrono::year year(i); - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(i, int(year)); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::year std_year(-32767); etl::chrono::year year(-32767); + int count = int(year); - for (int32_t i = 0; i < 65536; ++i) + for (int32_t i = 0; i < 65534; ++i) { - ++std_year; - ++year; + ++count; + etl::chrono::year this_year = ++year; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, year); + CHECK_EQUAL(this_year, year); } } From b532aa685f924fee30f1f6b4f014488ed32ab7b4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 006/216] Work in progress --- include/etl/chrono.h | 39 ++++ include/etl/hash.h | 4 +- include/etl/private/chrono/day.h | 271 +++++++++++++++++++++++ include/etl/private/chrono/duration.h | 139 ++++++++++++ test/CMakeLists.txt | 3 + test/test_chrono_day.cpp | 305 ++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 3 + test/vs2022/etl.vcxproj.filters | 15 ++ 8 files changed, 777 insertions(+), 2 deletions(-) create mode 100644 include/etl/chrono.h create mode 100644 include/etl/private/chrono/day.h create mode 100644 include/etl/private/chrono/duration.h create mode 100644 test/test_chrono_day.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h new file mode 100644 index 000000000..0cf26e5b4 --- /dev/null +++ b/include/etl/chrono.h @@ -0,0 +1,39 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_INCLUDED +#define ETL_CHRONO_INCLUDED + +#include "platform.h" + +#include "private/chrono/duration.h" +#include "private/chrono/day.h" + +#endif diff --git a/include/etl/hash.h b/include/etl/hash.h index 8066a0123..2397f0257 100644 --- a/include/etl/hash.h +++ b/include/etl/hash.h @@ -159,8 +159,8 @@ namespace etl /// Specialisation for signed char. ///\ingroup hash //*************************************************************************** - template<> struct - hash + template <> + struct hash { ETL_STATIC_ASSERT(sizeof(size_t) >= sizeof(signed char), "size_t smaller than type"); diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h new file mode 100644 index 000000000..b04d3898d --- /dev/null +++ b/include/etl/private/chrono/day.h @@ -0,0 +1,271 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DAY_INCLUDED +#define ETL_CHRONO_DAY_INCLUDED + +#include "../../platform.h" +#include "../../hash.h" + +#include "duration.h" + +#include + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// day + //*********************************************************************** + class day + { + public: + + //*********************************************************************** + ETL_CONSTEXPR day() + : value(0) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(unsigned value_) + : value(value_) + { + } + + //*********************************************************************** + ETL_CONSTEXPR day(const etl::chrono::day& other) + : value(other.value) + { + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::day& rhs) + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + template + ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) + { + value = etl::chrono::duration_cast(rhs); + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator ++() ETL_NOEXCEPT + { + ++value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + ++value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator --() ETL_NOEXCEPT + { + --value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::day operator --(int) ETL_NOEXCEPT + { + const etl::chrono::day temp = *this; + --value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value += static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + value -= static_cast(ds.count()); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value >= 1U) && (value <= 31U); + } + + //*********************************************************************** + ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + unsigned char value; + }; + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result += ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT + { + etl::chrono::day result(d); + + result -= ds; + + return result; + } + + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return etl::chrono::days(static_cast(static_cast(d1)) - + static_cast(static_cast(d2))); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) == static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return !(d1 == d2); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) < static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) <= static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) > static_cast(d2)); + } + + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) >= static_cast(d2)); + } + + //*********************************************************************** +#if ETL_USING_CPP20 + ETL_CONSTEXPR auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) + { + return (static_cast(d1) <=> static_cast(d2)); + } +#endif + } + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::day& d) const + { + unsigned value = d; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for days + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT + { + return etl::chrono::day(d); + } + } + } +} +#endif + +#endif \ No newline at end of file diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h new file mode 100644 index 000000000..3e4ec95e7 --- /dev/null +++ b/include/etl/private/chrono/duration.h @@ -0,0 +1,139 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_CHRONO_DURATION_INCLUDED +#define ETL_CHRONO_DURATION_INCLUDED + +#include "../../platform.h" +#include "../../ratio.h" +#include "../../static_assert.h" +#include "../../limits.h" + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// duration + //*********************************************************************** + template > + class duration + { + public: + + //*********************************************************************** + ETL_CONSTEXPR duration() ETL_NOEXCEPT + { + } + + //*********************************************************************** + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + template< typename TValue2 > + ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT + : value(static_cast(value_)) + { + } + + //*********************************************************************** + template< typename TValue2, typename TPeriod2 > + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(static_cast(other.value)) + { + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + { + return etl::chrono::duration{ 0, TPeriod()}; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + { + return etl::chrono::duration { etl::numeric_limits::min() }; + } + + //*********************************************************************** + static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + { + return etl::chrono::duration{ etl::numeric_limits::max() }; + } + + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR TValue count() const + { + return value; + } + + private: + + TValue value; + //TPeriod period; + }; + + //*********************************************************************** + /// Duration types + //*********************************************************************** +#if (ETL_USING_64BIT_TYPES) + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#else + typedef etl::chrono::duration nanoseconds; + typedef etl::chrono::duration microseconds; + typedef etl::chrono::duration milliseconds; + typedef etl::chrono::duration > seconds; +#endif + typedef etl::chrono::duration > minutes; + typedef etl::chrono::duration > hours; + typedef etl::chrono::duration > days; + typedef etl::chrono::duration > weeks; + typedef etl::chrono::duration > months; + typedef etl::chrono::duration > years; + + //*********************************************************************** + /// duration_cast + //*********************************************************************** + template + ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) + { + return TToDuration(); + } + } +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce9e2a664..029c0443a 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -58,6 +58,9 @@ add_executable(etl_tests test_callback_timer_locked.cpp test_char_traits.cpp test_checksum.cpp + + test_chrono_day.cpp + test_circular_buffer.cpp test_circular_buffer_external_buffer.cpp test_circular_iterator.cpp diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp new file mode 100644 index 000000000..e6de125c6 --- /dev/null +++ b/test/test_chrono_day.cpp @@ -0,0 +1,305 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#if ETL_USING_CPP20 + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +namespace +{ + SUITE(test_chrono_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + std::chrono::day std_day; + etl::chrono::day day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::day std_day(i); + etl::chrono::day day(i); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + ++std_day; + ++day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day++; + etl::chrono::day last_day = day++; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + --std_day; + --day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + for (int i = 0; i < 255; ++i) + { + std::chrono::day std_last_day = std_day--; + etl::chrono::day last_day = day--; + + CHECK_EQUAL(std_last_day.ok(), last_day.ok()); + CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_plus_equal_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day += std_days; + day += days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_plus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day + std_days; + day = day + days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_days_plus_day) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_days + std_day; + day = days + day; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_minus_equal_days) + { + std::chrono::day std_day(256); + etl::chrono::day day(256); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day -= std_days; + day -= days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_days) + { + std::chrono::day std_day(0); + etl::chrono::day day(0); + + std::chrono::days std_days(2); + etl::chrono::days days(2); + + for (int i = 0; i < 128; ++i) + { + std_day = std_day - std_days; + day = day - days; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + } + + //************************************************************************* + TEST(test_day_minus_day) + { + for (int i = 1; i < 31; ++i) + { + std::chrono::day std_day1(i); + std::chrono::day std_day2(31 - i); + + etl::chrono::day day1(i); + etl::chrono::day day2(31 - i); + + std::chrono::days std_days = std_day1 - std_day2; + etl::chrono::days days = day1 - day2; + + CHECK_EQUAL(std_days.count(), days.count()); + } + } + + //************************************************************************* + TEST(test_literal_days) + { + using namespace std::literals::chrono_literals; + using namespace etl::literals::chrono_literals; + + std::chrono::day std_day = 25d; + etl::chrono::day day = 25_d; + + CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_EQUAL(unsigned(std_day), unsigned(day)); + } + + //************************************************************************* + TEST(test_day_comparison_operators) + { + etl::chrono::day day10(10); + etl::chrono::day day20(20); + + CHECK_TRUE(day10 == day10); + CHECK_FALSE(day10 != day10); + CHECK_TRUE(day10 < day20); + CHECK_FALSE(day10 < day10); + CHECK_FALSE(day20 < day10); + CHECK_TRUE(day10 <= day20); + CHECK_TRUE(day10 <= day10); + CHECK_FALSE(day20 <= day10); + CHECK_FALSE(day10 > day20); + CHECK_FALSE(day10 > day10); + CHECK_TRUE(day20 > day10); + CHECK_FALSE(day10 >= day20); + CHECK_TRUE(day10 >= day10); + CHECK_TRUE(day20 >= day10); + +#if ETL_USING_CPP20 + CHECK_TRUE((day10 <=> day10) == 0); + CHECK_TRUE((day10 <=> day20) < 0); + CHECK_TRUE((day20 <=> day10) > 0); +#endif + } + + //************************************************************************* + TEST(test_day_hash) + { + etl::chrono::day day(10); + + size_t h = 0; + + h = etl::hash()(day); + + CHECK_TRUE(h != 0); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 7506cfa14..8c675a44a 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3027,6 +3027,7 @@ + @@ -3091,6 +3092,7 @@ + @@ -7947,6 +7949,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 2da095b94..470fb7767 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -220,6 +220,12 @@ {c75cedd3-8b6c-4662-b965-aecbe7fd5d1c} + + {46e23f29-ce01-418f-8331-9c739774414c} + + + {1b1afa65-108a-4665-9e74-3c67a27ff917} + {6bbca8f0-f707-45ee-9dad-6d41d401bbaf} @@ -1371,6 +1377,12 @@ ETL\Utilities + + ETL\Utilities + + + ETL\Utilities + ETL\Codecs @@ -2486,6 +2498,9 @@ Tests\Misc + + Tests\Chrono + Tests\Syntax Checks\Source From bfa5f391fbe482ccc6afd9410fc240beeee8139e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 29 Aug 2024 09:45:58 +0100 Subject: [PATCH 007/216] Fixed value type --- include/etl/private/chrono/day.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index b04d3898d..8079680d6 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -146,7 +146,7 @@ namespace etl private: - unsigned char value; + unsigned value; }; //*********************************************************************** From ae31d581e2ea1d807aca4c8dbee5d3871e4b0be6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 008/216] Work in progress --- .gitignore | 1 + include/etl/private/chrono/day.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8f313ddbc..ab33079c2 100644 --- a/.gitignore +++ b/.gitignore @@ -388,3 +388,4 @@ support/time remaining test.xlsx test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt +test/reflog.txt diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 8079680d6..b04d3898d 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -146,7 +146,7 @@ namespace etl private: - unsigned value; + unsigned char value; }; //*********************************************************************** From d15f35c78fea39eeef880ad93580394cf07d6843 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Sep 2023 11:15:49 +0100 Subject: [PATCH 009/216] Work in progress --- include/etl/private/chrono/day.h | 51 +------------ test/test_chrono_day.cpp | 119 ++++--------------------------- 2 files changed, 17 insertions(+), 153 deletions(-) diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index b04d3898d..61d19e8b2 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -182,53 +182,10 @@ namespace etl //*********************************************************************** ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { - return etl::chrono::days(static_cast(static_cast(d1)) - - static_cast(static_cast(d2))); - } - - //*********************************************************************** - ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return (static_cast(d1) == static_cast(d2)); - } - - //*********************************************************************** - ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return !(d1 == d2); - } - - //*********************************************************************** - ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return (static_cast(d1) < static_cast(d2)); - } - - //*********************************************************************** - ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return (static_cast(d1) <= static_cast(d2)); - } - - //*********************************************************************** - ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return (static_cast(d1) > static_cast(d2)); - } + etl::chrono::days result; - //*********************************************************************** - ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT - { - return (static_cast(d1) >= static_cast(d2)); + return etl::chrono::days(static_cast(d1) - static_cast(d2)); } - - //*********************************************************************** -#if ETL_USING_CPP20 - ETL_CONSTEXPR auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) - { - return (static_cast(d1) <=> static_cast(d2)); - } -#endif } //************************************************************************* @@ -249,15 +206,12 @@ namespace etl #endif } -#if ETL_USING_CPP11 namespace etl { namespace literals { namespace chrono_literals { - //*********************************************************************** - /// Literal for days //*********************************************************************** ETL_CONSTEXPR etl::chrono::day operator ""_d(unsigned long long d) ETL_NOEXCEPT { @@ -266,6 +220,5 @@ namespace etl } } } -#endif #endif \ No newline at end of file diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp index e6de125c6..f8a3d4535 100644 --- a/test/test_chrono_day.cpp +++ b/test/test_chrono_day.cpp @@ -154,40 +154,28 @@ namespace } //************************************************************************* - TEST(test_day_plus_days) + TEST(test_plus_days) { - std::chrono::day std_day(0); - etl::chrono::day day(0); + std::chrono::day std_day1(0); + std::chrono::day std_day2(0); + etl::chrono::day day1(0); + etl::chrono::day day2(0); std::chrono::days std_days(2); etl::chrono::days days(2); for (int i = 0; i < 128; ++i) { - std_day = std_day + std_days; - day = day + days; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } - } - - //************************************************************************* - TEST(test_days_plus_day) - { - std::chrono::day std_day(0); - etl::chrono::day day(0); - - std::chrono::days std_days(2); - etl::chrono::days days(2); - - for (int i = 0; i < 128; ++i) - { - std_day = std_days + std_day; - day = days + day; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + std_day1 = std_days + std_day1; + std_day2 = std_day2 + std_days; + + day1 = days + day1; + day2 = day2 + days; + + CHECK_EQUAL(std_day1.ok(), day1.ok()); + CHECK_EQUAL(std_day2.ok(), day2.ok()); + CHECK_EQUAL(unsigned(std_day1), unsigned(day1)); + CHECK_EQUAL(unsigned(std_day2), unsigned(day2)); } } @@ -210,43 +198,6 @@ namespace } } - //************************************************************************* - TEST(test_day_minus_days) - { - std::chrono::day std_day(0); - etl::chrono::day day(0); - - std::chrono::days std_days(2); - etl::chrono::days days(2); - - for (int i = 0; i < 128; ++i) - { - std_day = std_day - std_days; - day = day - days; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } - } - - //************************************************************************* - TEST(test_day_minus_day) - { - for (int i = 1; i < 31; ++i) - { - std::chrono::day std_day1(i); - std::chrono::day std_day2(31 - i); - - etl::chrono::day day1(i); - etl::chrono::day day2(31 - i); - - std::chrono::days std_days = std_day1 - std_day2; - etl::chrono::days days = day1 - day2; - - CHECK_EQUAL(std_days.count(), days.count()); - } - } - //************************************************************************* TEST(test_literal_days) { @@ -259,46 +210,6 @@ namespace CHECK_EQUAL(std_day.ok(), day.ok()); CHECK_EQUAL(unsigned(std_day), unsigned(day)); } - - //************************************************************************* - TEST(test_day_comparison_operators) - { - etl::chrono::day day10(10); - etl::chrono::day day20(20); - - CHECK_TRUE(day10 == day10); - CHECK_FALSE(day10 != day10); - CHECK_TRUE(day10 < day20); - CHECK_FALSE(day10 < day10); - CHECK_FALSE(day20 < day10); - CHECK_TRUE(day10 <= day20); - CHECK_TRUE(day10 <= day10); - CHECK_FALSE(day20 <= day10); - CHECK_FALSE(day10 > day20); - CHECK_FALSE(day10 > day10); - CHECK_TRUE(day20 > day10); - CHECK_FALSE(day10 >= day20); - CHECK_TRUE(day10 >= day10); - CHECK_TRUE(day20 >= day10); - -#if ETL_USING_CPP20 - CHECK_TRUE((day10 <=> day10) == 0); - CHECK_TRUE((day10 <=> day20) < 0); - CHECK_TRUE((day20 <=> day10) > 0); -#endif - } - - //************************************************************************* - TEST(test_day_hash) - { - etl::chrono::day day(10); - - size_t h = 0; - - h = etl::hash()(day); - - CHECK_TRUE(h != 0); - } }; } From e732f205acb530617cddd6e1d2480934a1014b62 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 30 Aug 2024 19:59:16 +0100 Subject: [PATCH 010/216] Updates to weekday --- include/etl/private/chrono/day.h | 96 ++++++- include/etl/private/chrono/duration.h | 21 +- include/etl/private/chrono/month.h | 383 +++++++++++++++++++++++++ include/etl/private/chrono/weekday.h | 391 ++++++++++++++++++++++++++ include/etl/private/chrono/year.h | 332 ++++++++++++++++++++++ test/test_chrono_weekday.cpp | 379 +++++++++++++++++++++++++ test/test_chrono_year.cpp | 317 +++++++++++++++++++++ 7 files changed, 1910 insertions(+), 9 deletions(-) create mode 100644 include/etl/private/chrono/month.h create mode 100644 include/etl/private/chrono/weekday.h create mode 100644 include/etl/private/chrono/year.h create mode 100644 test/test_chrono_weekday.cpp create mode 100644 test/test_chrono_year.cpp diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 61d19e8b2..e21181723 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -56,8 +56,10 @@ namespace etl } //*********************************************************************** - ETL_CONSTEXPR day(unsigned value_) - : value(value_) + /// Construct from unsigned + //*********************************************************************** + ETL_CONSTEXPR explicit day(unsigned value_) ETL_NOEXCEPT + : value(static_cast(value_)) { } @@ -80,6 +82,8 @@ namespace etl ETL_CONSTEXPR etl::chrono::day& operator =(const etl::chrono::duration& rhs) { value = etl::chrono::duration_cast(rhs); + + return *this; } //*********************************************************************** @@ -132,6 +136,8 @@ namespace etl return *this; } + //*********************************************************************** + /// Returns true if the day is within the valid 1 to 31 range //*********************************************************************** ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { @@ -144,11 +150,88 @@ namespace etl return static_cast(value); } + //*********************************************************************** + /// The minimum day value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::day min() ETL_NOEXCEPT + { + return etl::chrono::day(1); + } + + //*********************************************************************** + /// The maximum day value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::day max() ETL_NOEXCEPT + { + return etl::chrono::day(31); + } + private: unsigned char value; }; + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) == static_cast(d2)); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return !(d1 == d2); + } + + //*********************************************************************** + /// Less-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) < static_cast(d2)); + } + + //*********************************************************************** + /// Less-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) <= static_cast(d2)); + } + + //*********************************************************************** + /// Greater-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) > static_cast(d2)); + } + + //*********************************************************************** + /// Greater-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT + { + return (static_cast(d1) >= static_cast(d2)); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::day& d1, const etl::chrono::day& d2) noexcept + { + return (static_cast(d1) <=> static_cast(d2)); + } +#endif + + //*********************************************************************** + /// Add etl::chrono::days to etl::chrono::day + ///\return etl::chrono::day //*********************************************************************** ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { @@ -159,6 +242,9 @@ namespace etl return result; } + //*********************************************************************** + /// Add etl::chrono::day to etl::chrono::days + ///\return etl::chrono::day //*********************************************************************** ETL_CONSTEXPR etl::chrono::day operator +(const etl::chrono::days& ds, const etl::chrono::day& d) ETL_NOEXCEPT { @@ -169,6 +255,9 @@ namespace etl return result; } + //*********************************************************************** + /// Subtract etl::chrono::days from etl::chrono::day + ///\return etl::chrono::day //*********************************************************************** ETL_CONSTEXPR etl::chrono::day operator -(const etl::chrono::day& d, const etl::chrono::days& ds) ETL_NOEXCEPT { @@ -179,6 +268,9 @@ namespace etl return result; } + //*********************************************************************** + /// Subtract etl::chrono::day from etl::chrono::day + ///\return etl::chrono::days //*********************************************************************** ETL_CONSTEXPR etl::chrono::days operator -(const etl::chrono::day& d1, const etl::chrono::day& d2) ETL_NOEXCEPT { diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 3e4ec95e7..fdb8d9b5f 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -75,25 +75,25 @@ namespace etl } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT { return etl::chrono::duration{ 0, TPeriod()}; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT { return etl::chrono::duration { etl::numeric_limits::min() }; } //*********************************************************************** - static ETL_NODISCARD ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT { return etl::chrono::duration{ etl::numeric_limits::max() }; } //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR TValue count() const + ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT { return value; } @@ -131,9 +131,16 @@ namespace etl template ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) { - return TToDuration(); + using to_value_type = typename TToDuration::value_type; + using to_period = typename TToDuration::period; + + // Calculate the conversion factor between the periods + ETL_CONSTEXPR auto conversion_factor = (static_cast(TPeriod::num) / TPeriod::den) * (to_period::den / to_period::num); + + // Convert the value + to_value_type converted_value = static_cast(d.count() * conversion_factor); + + return TToDuration(converted_value); } } } - -#endif diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h new file mode 100644 index 000000000..30653a589 --- /dev/null +++ b/include/etl/private/chrono/month.h @@ -0,0 +1,383 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + class month; + + ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT; + ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT; + ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT; + + //*********************************************************************** + /// month + //*********************************************************************** + class month + { + public: + + //*********************************************************************** + /// Default constructor + //*********************************************************************** + ETL_CONSTEXPR month() ETL_NOEXCEPT + : value(0) + { + } + + //*********************************************************************** + /// Construct from unsigned + //*********************************************************************** + ETL_CONSTEXPR explicit month(unsigned value_) ETL_NOEXCEPT + : value(value_) + { + } + + //*********************************************************************** + /// Copy constructor + //*********************************************************************** + ETL_CONSTEXPR month(const etl::chrono::month& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + /// Assignment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month& operator =(const etl::chrono::month& rhs) ETL_NOEXCEPT + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + /// Pre-increment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month& operator ++() ETL_NOEXCEPT + { + *this += etl::chrono::months(1); + + return *this; + } + + //*********************************************************************** + /// Post-increment operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::month operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::month temp = *this; + + *this += etl::chrono::months(1); + + return temp; + } + + //*********************************************************************** + /// Pre-decrement operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month& operator --() ETL_NOEXCEPT + { + *this -= etl::chrono::months(1); + + return *this; + } + + //*********************************************************************** + /// Post-decrement operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::month operator --(int) ETL_NOEXCEPT + { + etl::chrono::month temp = *this; + + *this -= etl::chrono::months(1); + + return temp; + } + + //*********************************************************************** + /// Plus-equals operator adding etl::chrono::months + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month& operator +=(const etl::chrono::months& ms) ETL_NOEXCEPT + { + *this = *this + ms; + + return *this; + } + + //*********************************************************************** + /// Minus-equals operator subtracting etl::chrono::months + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month& operator -=(const etl::chrono::months& ms) ETL_NOEXCEPT + { + *this = *this - ms; + + return *this; + } + + //*********************************************************************** + /// Returns true if the month is within the valid 1 to 31 range + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value >= 1U) && (value <= 12U); + } + + //*********************************************************************** + /// The minimum month value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::month min() ETL_NOEXCEPT + { + return etl::chrono::month(1); + } + + //*********************************************************************** + /// The maximum month value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::month max() ETL_NOEXCEPT + { + return etl::chrono::month(12); + } + + //*********************************************************************** + /// Conversion operator to unsigned int + //*********************************************************************** + ETL_CONSTEXPR operator unsigned() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + //*********************************************************************** + /// Normalise to a in-range month + //*********************************************************************** + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + { + value = ((value % 12U) == 0U) ? 12U : value; + } + + unsigned char value; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return (static_cast(d1) == static_cast(d2)); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return !(d1 == d2); + } + + //*********************************************************************** + /// Less-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return (static_cast(d1) < static_cast(d2)); + } + + //*********************************************************************** + /// Less-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return (static_cast(d1) <= static_cast(d2)); + } + + //*********************************************************************** + /// Greater-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return (static_cast(d1) > static_cast(d2)); + } + + //*********************************************************************** + /// Greater-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::month& d1, const etl::chrono::month& d2) ETL_NOEXCEPT + { + return (static_cast(d1) >= static_cast(d2)); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month& d1, const etl::chrono::month& d2) noexcept + { + return (static_cast(d1) <=> static_cast(d2)); + } +#endif + + //*********************************************************************** + /// Add etl::chrono::months to etl::chrono::month + ///\return etl::chrono::month + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::month operator +(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + { + unsigned int value = static_cast(m); + + value = value % 12U; + + if (value == 0U) + { + value = 12U; + } + + int delta = ms.count() % 12; + + // Adjust to allow a limited +-11 month delta + value += 11U; + value += delta; + value %= 12U; + ++value; + + return etl::chrono::month(value); + } + + //*********************************************************************** + /// Add etl::chrono::month to etl::chrono::months + ///\return etl::chrono::month + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT + { + return m + ms; + } + + //*********************************************************************** + /// Subtract etl::chrono::months from etl::chrono::month + ///\return etl::chrono::month + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT + { + return m + etl::chrono::months(-ms.count()); + } + + //*********************************************************************** + /// Subtract etl::chrono::month from etl::chrono::month + ///\return etl::chrono::months + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::month& m1, const etl::chrono::month& m2) ETL_NOEXCEPT + { + if (m1.ok() && m2.ok()) + { + etl::chrono::months ms(static_cast(static_cast(m1)) - + static_cast(static_cast(m2)) % 12); + + if (m1 == (m2 + ms)) + { + return ms; + } + } + + return etl::chrono::months(); + } + +#if ETL_USING_CPP17 + inline constexpr etl::chrono::month January{ 1 }; + inline constexpr etl::chrono::month February{ 2 }; + inline constexpr etl::chrono::month March{ 3 }; + inline constexpr etl::chrono::month April{ 4 }; + inline constexpr etl::chrono::month May{ 5 }; + inline constexpr etl::chrono::month June{ 6 }; + inline constexpr etl::chrono::month July{ 7 }; + inline constexpr etl::chrono::month August{ 8 }; + inline constexpr etl::chrono::month September{ 9 }; + inline constexpr etl::chrono::month October{ 10 }; + inline constexpr etl::chrono::month November{ 11 }; + inline constexpr etl::chrono::month December{ 12 }; +#else + static ETL_CONSTANT etl::chrono::month January{ 1 }; + static ETL_CONSTANT etl::chrono::month February{ 2 }; + static ETL_CONSTANT etl::chrono::month March{ 3 }; + static ETL_CONSTANT etl::chrono::month April{ 4 }; + static ETL_CONSTANT etl::chrono::month May{ 5 }; + static ETL_CONSTANT etl::chrono::month June{ 6 }; + static ETL_CONSTANT etl::chrono::month July{ 7 }; + static ETL_CONSTANT etl::chrono::month August{ 8 }; + static ETL_CONSTANT etl::chrono::month September{ 9 }; + static ETL_CONSTANT etl::chrono::month October{ 10 }; + static ETL_CONSTANT etl::chrono::month November{ 11 }; + static ETL_CONSTANT etl::chrono::month December{ 12 }; +#endif + } + + //************************************************************************* + /// Hash function for etl::chrono::month + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month& m) const + { + unsigned value = m; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +#if ETL_HAS_CHRONO_LITERALS_MONTH +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for months + //*********************************************************************** + constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept + { + return etl::chrono::month(static_cast(m)); + } + } + } +} +#endif +#endif diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h new file mode 100644 index 000000000..fc4df27fa --- /dev/null +++ b/include/etl/private/chrono/weekday.h @@ -0,0 +1,391 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + class weekday; + class weekday_indexed; + class weekday_last; + struct last_spec; + + ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT; + ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& m) ETL_NOEXCEPT; + ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT; + + //*********************************************************************** + /// weekday + //*********************************************************************** + class weekday + { + public: + + //*********************************************************************** + /// Default constructor + //*********************************************************************** + ETL_CONSTEXPR weekday() ETL_NOEXCEPT + : value(255U) + { + } + + //*********************************************************************** + /// Construct from unsigned + //*********************************************************************** + ETL_CONSTEXPR explicit weekday(unsigned value_) ETL_NOEXCEPT + : value(value_ == 7U ? 0U :value_) + { + } + + //*********************************************************************** + /// Copy constructor + //*********************************************************************** + ETL_CONSTEXPR weekday(const etl::chrono::weekday& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + /// Assignment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday& operator =(const etl::chrono::weekday& rhs) ETL_NOEXCEPT + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + /// Pre-increment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday& operator ++() ETL_NOEXCEPT + { + *this += etl::chrono::days(1); + + return *this; + } + + //*********************************************************************** + /// Post-increment operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::weekday operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::weekday temp = *this; + + *this += etl::chrono::days(1); + + return temp; + } + + //*********************************************************************** + /// Pre-decrement operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday& operator --() ETL_NOEXCEPT + { + *this -= etl::chrono::days(1); + + return *this; + } + + //*********************************************************************** + /// Post-decrement operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::weekday operator --(int) ETL_NOEXCEPT + { + etl::chrono::weekday temp = *this; + + *this -= etl::chrono::days(1); + + return temp; + } + + //*********************************************************************** + /// Plus-equals operator adding etl::chrono::days + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday& operator +=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + *this = *this + ds; + + return *this; + } + + //*********************************************************************** + /// Minus-equals operator subtracting etl::chrono::days + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday& operator -=(const etl::chrono::days& ds) ETL_NOEXCEPT + { + *this = *this - ds; + + return *this; + } + + //*********************************************************************** + /// Returns true if the weekday is within the valid 1 to 31 range + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (c_encoding() <= 6U); + } + + //*********************************************************************** + /// The minimum weekday value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT + { + return etl::chrono::weekday(0); + } + + //*********************************************************************** + /// The maximum weekday value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT + { + return etl::chrono::weekday(6); + } + + //*********************************************************************** + /// Get the C encoding of the weekday + //*********************************************************************** + ETL_CONSTEXPR unsigned c_encoding() const ETL_NOEXCEPT + { + return value; + } + + //*********************************************************************** + /// Get the ISO encoding of the weekday + //*********************************************************************** + ETL_CONSTEXPR unsigned iso_encoding() const ETL_NOEXCEPT + { + return (value == 0U) ? 7U : value; + } + + //*********************************************************************** + /// Index operator from index + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday_indexed operator[](unsigned index) const ETL_NOEXCEPT; + + //*********************************************************************** + /// Index operator from etl::chrono::last_spec + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday_last operator[](etl::chrono::last_spec) const ETL_NOEXCEPT; + + //*********************************************************************** + /// Returns true if the day is a weekend. + //*********************************************************************** + ETL_CONSTEXPR14 bool is_weekend() ETL_NOEXCEPT + { + return (c_encoding() == 0U) || (c_encoding() == 6U); + } + + private: + + //*********************************************************************** + /// Normalise to a in-range weekday + //*********************************************************************** + ETL_CONSTEXPR void normalise() ETL_NOEXCEPT + { + value %= 7U; + } + + unsigned char value; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return (wd1.c_encoding() == wd2.c_encoding()); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return !(wd1 == wd2); + } + + //*********************************************************************** + /// Less-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return (wd1.c_encoding() < wd2.c_encoding()); + } + + //*********************************************************************** + /// Less-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return (wd1.c_encoding() <= wd2.c_encoding()); + } + + //*********************************************************************** + /// Greater-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return (wd1.c_encoding() > wd2.c_encoding()); + } + + //*********************************************************************** + /// Greater-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + return (wd1.c_encoding() >= wd2.c_encoding()); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) noexcept + { + return (wd1.c_encoding() <=> wd2.c_encoding()); + } +#endif + + //*********************************************************************** + /// Add etl::chrono::days to etl::chrono::weekday + ///\return etl::chrono::weekday + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::weekday operator +(const etl::chrono::weekday& wd, const etl::chrono::days& ds) ETL_NOEXCEPT + { + int delta = ds.count() % 7; + + unsigned int value = wd.c_encoding(); + + // Adjust to allow a limited +-7 weekday delta + value %= 7U; + value += 7U; + value += delta; + value %= 7U; + + return etl::chrono::weekday(value); + } + + //*********************************************************************** + /// Add etl::chrono::weekday to etl::chrono::days + ///\return etl::chrono::weekday + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday operator +(const etl::chrono::days& ds, const etl::chrono::weekday& wd) ETL_NOEXCEPT + { + return wd + ds; + } + + //*********************************************************************** + /// Subtract etl::chrono::days from etl::chrono::weekday + ///\return etl::chrono::weekday + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday operator -(const etl::chrono::weekday& m, const etl::chrono::days& ds) ETL_NOEXCEPT + { + return m + etl::chrono::days(-ds.count()); + } + + //*********************************************************************** + /// Subtract etl::chrono::weekday from etl::chrono::weekday + ///\return etl::chrono::days + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::days operator -(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT + { + if (wd1.ok() && wd2.ok()) + { + int diff = static_cast(wd1.c_encoding()) - static_cast(wd2.c_encoding()); + + return etl::chrono::days((diff + 7) % 7); + } + + return etl::chrono::days(0); + } + +#if ETL_USING_CPP17 + inline constexpr etl::chrono::weekday Sunday{ 0U }; + inline constexpr etl::chrono::weekday Monday{ 1U }; + inline constexpr etl::chrono::weekday Tuesday{ 2U }; + inline constexpr etl::chrono::weekday Wednesday{ 3U }; + inline constexpr etl::chrono::weekday Thursday{ 4U }; + inline constexpr etl::chrono::weekday Friday{ 5U }; + inline constexpr etl::chrono::weekday Saturday{ 6U }; +#else + static ETL_CONSTANT etl::chrono::weekday Sunday{ 0U }; + static ETL_CONSTANT etl::chrono::weekday Monday{ 1U }; + static ETL_CONSTANT etl::chrono::weekday Tuesday{ 2U }; + static ETL_CONSTANT etl::chrono::weekday Wednesday{ 3U }; + static ETL_CONSTANT etl::chrono::weekday Thursday{ 4U }; + static ETL_CONSTANT etl::chrono::weekday Friday{ 5U }; + static ETL_CONSTANT etl::chrono::weekday Saturday{ 6U }; +#endif + } + + //************************************************************************* + /// Hash function for etl::chrono::weekday + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::weekday& wd) const + { + unsigned value = wd.c_encoding(); + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif +} + +#if ETL_HAS_CHRONO_LITERALS_WEEKDAY +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for weekdays + //*********************************************************************** + constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept + { + return etl::chrono::weekday(static_cast(m)); + } + } + } +} +#endif +#endif diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h new file mode 100644 index 000000000..ff873e37b --- /dev/null +++ b/include/etl/private/chrono/year.h @@ -0,0 +1,332 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //*********************************************************************** + /// year + //*********************************************************************** + class year + { + public: + + //*********************************************************************** + /// Default constructor + //*********************************************************************** + ETL_CONSTEXPR year() ETL_NOEXCEPT + : value(0) + { + } + + //*********************************************************************** + /// Construct from unsigned + //*********************************************************************** + ETL_CONSTEXPR explicit year(unsigned value_) ETL_NOEXCEPT + : value(value_) + { + } + + //*********************************************************************** + /// Copy constructor + //*********************************************************************** + ETL_CONSTEXPR year(const etl::chrono::year& other) ETL_NOEXCEPT + : value(other.value) + { + } + + //*********************************************************************** + /// Assignment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year& operator =(const etl::chrono::year& rhs) ETL_NOEXCEPT + { + value = rhs.value; + + return *this; + } + + //*********************************************************************** + /// Pre-increment operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year& operator ++() ETL_NOEXCEPT + { + ++value; + + return *this; + } + + //*********************************************************************** + /// Post-increment operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::year operator ++(int) ETL_NOEXCEPT + { + const etl::chrono::year temp = *this; + ++value; + + return temp; + } + + //*********************************************************************** + /// Pre-decrement operator + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year& operator --() ETL_NOEXCEPT + { + --value; + + return *this; + } + + //*********************************************************************** + /// Post-decrement operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::year operator --(int) ETL_NOEXCEPT + { + const etl::chrono::year temp = *this; + --value; + + return temp; + } + + //*********************************************************************** + /// Plus-equals operator adding etl::chrono::years + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year& operator +=(const etl::chrono::years& ys) ETL_NOEXCEPT + { + value += static_cast(ys.count()); + + return *this; + } + + //*********************************************************************** + /// Minus-equals operator subtracting etl::chrono::years + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year& operator -=(const etl::chrono::years& ys) ETL_NOEXCEPT + { + value -= static_cast(ys.count()); + + return *this; + } + + //*********************************************************************** + /// Returns true if the year is within the valid -32767 to 32767 range + //*********************************************************************** + ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return (value != -32768); + } + + //*********************************************************************** + /// The minimum year value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::year min() ETL_NOEXCEPT + { + return etl::chrono::year(-32767); + } + + //*********************************************************************** + /// The maximum year value for which ok() will return true + //*********************************************************************** + static ETL_CONSTEXPR etl::chrono::year max() ETL_NOEXCEPT + { + return etl::chrono::year(32767); + } + + //*********************************************************************** + /// Returns true if the year is a leap year + //*********************************************************************** + ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT + { + return ((value % 4) == 0) && !((value % 400) == 0); + } + + //*********************************************************************** + /// Conversion operator to unsigned int + //*********************************************************************** + ETL_CONSTEXPR operator int() const ETL_NOEXCEPT + { + return static_cast(value); + } + + private: + + int16_t value; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return (static_cast(y1) == static_cast(y2)); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return !(y1 == y2); + } + + //*********************************************************************** + /// Less-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return (static_cast(y1) < static_cast(y2)); + } + + //*********************************************************************** + /// Less-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator <=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return (static_cast(y1) <= static_cast(y2)); + } + + //*********************************************************************** + /// Greater-than operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return (static_cast(y1) > static_cast(y2)); + } + + //*********************************************************************** + /// Greater-than-or-equal operator + //*********************************************************************** + ETL_CONSTEXPR bool operator >=(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return (static_cast(y1) >= static_cast(y2)); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::year& y1, const etl::chrono::year& y2) noexcept + { + return (static_cast(y1) <=> static_cast(y2)); + } +#endif + + //*********************************************************************** + /// Add etl::chrono::years to etl::chrono::year + ///\return etl::chrono::year + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + { + etl::chrono::year result(y); + + result += ys; + + return result; + } + + //*********************************************************************** + /// Add etl::chrono::year to etl::chrono::years + ///\return etl::chrono::year + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year operator +(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT + { + etl::chrono::year result(y); + + result += ys; + + return result; + } + + //*********************************************************************** + /// Subtract etl::chrono::years from etl::chrono::year + ///\return etl::chrono::year + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::year& y, const etl::chrono::years& ys) ETL_NOEXCEPT + { + etl::chrono::year result(y); + + result -= ys; + + return result; + } + + //*********************************************************************** + /// Subtract etl::chrono::year from etl::chrono::year + ///\return etl::chrono::years + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT + { + return etl::chrono::years(static_cast(static_cast(y1)) - + static_cast(static_cast(y2))); + } + } + + //************************************************************************* + /// Hash function for etl::chrono::year + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year& y) const + { + int value = y; + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(int)); + } + }; +#endif +} + +#if ETL_HAS_CHRONO_LITERALS_YEAR +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for years + //*********************************************************************** + constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept + { + return etl::chrono::year(static_cast(y)); + } + } + } +} +#endif +#endif diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp new file mode 100644 index 000000000..c4cbe05d8 --- /dev/null +++ b/test/test_chrono_weekday.cpp @@ -0,0 +1,379 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +#include +#include + +namespace +{ + SUITE(test_chrono_weekday) + { + //************************************************************************* + TEST(test_default_constructor) + { + etl::chrono::weekday weekday; + + CHECK_FALSE(weekday.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 7U; ++i) + { + etl::chrono::weekday weekday(i); + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_constructor_out_of_range) + { + for (unsigned i = 8U; i < 256U; ++i) + { + etl::chrono::weekday weekday(i); + + CHECK_FALSE(weekday.ok()); + CHECK_EQUAL(i, weekday.c_encoding()); + CHECK_EQUAL((i == 0U) ? 7U : i, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + etl::chrono::weekday weekday(0); + unsigned count = 0; + + for (int i = 0; i < 255; ++i) + { + ++weekday; + ++count; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + etl::chrono::weekday weekday(0); + unsigned count = 0; + + for (int i = 0; i < 255; ++i) + { + etl::chrono::weekday last_weekday = weekday++; + unsigned last_count = count++; + + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + etl::chrono::weekday weekday(255U); + unsigned count = 255U; + + for (int i = 0; i < 255; ++i) + { + --weekday; + --count; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + etl::chrono::weekday weekday(255U); + unsigned count = 255U; + + for (int i = 0; i < 255; ++i) + { + etl::chrono::weekday last_weekday = weekday--; + unsigned last_count = count--; + + if (last_count == 255U) + { + CHECK_FALSE(last_weekday.ok()); + CHECK_EQUAL(255U, last_weekday.c_encoding()); + CHECK_EQUAL(255U, last_weekday.iso_encoding()); + } + else + { + CHECK_TRUE(last_weekday.ok()); + CHECK_EQUAL(last_count % 7, last_weekday.c_encoding()); + CHECK_EQUAL((last_count % 7 == 0U) ? 7U : last_count % 7, last_weekday.iso_encoding()); + } + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(count % 7, weekday.c_encoding()); + CHECK_EQUAL((count % 7 == 0U) ? 7U : count % 7, weekday.iso_encoding()); + } + } + + //************************************************************************* + TEST(test_plus_equal_days) + { + for (unsigned wd = 0; wd <= 6; ++wd) + { + for (unsigned ds = 0; ds <= 14; ++ds) + { + etl::chrono::weekday weekday(wd); + etl::chrono::days days(ds); + weekday += days; + + unsigned expected = (wd + ds) % 7; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); + } + } + } + + //************************************************************************* + TEST(test_weekday_plus_days) + { + for (unsigned wd = 0; wd <= 6; ++wd) + { + for (unsigned ds = 0; ds <= 14; ++ds) + { + etl::chrono::weekday weekday(wd); + etl::chrono::days days(ds); + weekday = weekday + days; + + unsigned expected = (wd + ds) % 7; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); + } + } + } + + //************************************************************************* + TEST(test_days_plus_weekday) + { + for (unsigned wd = 0; wd <= 6; ++wd) + { + for (unsigned ds = 0; ds <= 14; ++ds) + { + etl::chrono::weekday weekday(wd); + etl::chrono::days days(ds); + weekday = weekday + days; + + unsigned expected = (ds + wd) % 7; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); + } + } + } + + //************************************************************************* + TEST(test_minus_equal_days) + { + for (unsigned wd = 0; wd <= 6; ++wd) + { + for (unsigned ds = 0; ds <= 14; ++ds) + { + etl::chrono::weekday weekday(wd); + etl::chrono::days days(ds); + weekday -= days; + + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); + } + } + } + + //************************************************************************* + TEST(test_weekday_minus_days) + { + for (unsigned wd = 0; wd <= 6; ++wd) + { + for (unsigned ds = 0; ds <= 14; ++ds) + { + etl::chrono::weekday weekday(wd); + etl::chrono::days days(ds); + weekday = weekday - days; + + unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; + + CHECK_TRUE(weekday.ok()); + CHECK_EQUAL(expected, weekday.c_encoding()); + CHECK_EQUAL((expected == 0U) ? 7U : expected, weekday.iso_encoding()); + } + } + } + + //************************************************************************* + TEST(test_weekday_minus_weekday) + { + for (int m = 0; m < 7; ++m) + { + etl::chrono::weekday weekday1(m); + etl::chrono::weekday weekday2(7 - m); + + std::chrono::weekday std_weekday1(m); + std::chrono::weekday std_weekday2(7 - m); + + auto days12 = weekday1 - weekday2; + auto days21 = weekday2 - weekday1; + + auto std_days12 = std_weekday1 - std_weekday2; + auto std_days21 = std_weekday2 - std_weekday1; + + CHECK_EQUAL(std_days12.count(), days12.count()); + CHECK_EQUAL(std_days21.count(), days21.count()); + } + } + + //************************************************************************* + TEST(test_min_max_weekday) + { + CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), etl::chrono::weekday::min().c_encoding()); + CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), etl::chrono::weekday::max().c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_constants) + { + CHECK_EQUAL(0U, etl::chrono::Sunday.c_encoding()); + CHECK_EQUAL(1U, etl::chrono::Monday.c_encoding()); + CHECK_EQUAL(2U, etl::chrono::Tuesday.c_encoding()); + CHECK_EQUAL(3U, etl::chrono::Wednesday.c_encoding()); + CHECK_EQUAL(4U, etl::chrono::Thursday.c_encoding()); + CHECK_EQUAL(5U, etl::chrono::Friday.c_encoding()); + CHECK_EQUAL(6U, etl::chrono::Saturday.c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_literals) + { + using namespace etl::literals::chrono_literals; + + etl::chrono::weekday weekday0 = 0_weekday; + etl::chrono::weekday weekday1 = 1_weekday; + etl::chrono::weekday weekday2 = 2_weekday; + etl::chrono::weekday weekday3 = 3_weekday; + etl::chrono::weekday weekday4 = 4_weekday; + etl::chrono::weekday weekday5 = 5_weekday; + etl::chrono::weekday weekday6 = 6_weekday; + + CHECK_TRUE(weekday0.ok()); + CHECK_TRUE(weekday1.ok()); + CHECK_TRUE(weekday2.ok()); + CHECK_TRUE(weekday3.ok()); + CHECK_TRUE(weekday4.ok()); + CHECK_TRUE(weekday5.ok()); + CHECK_TRUE(weekday6.ok()); + + CHECK_EQUAL(0U, weekday0.c_encoding()); + CHECK_EQUAL(1U, weekday1.c_encoding()); + CHECK_EQUAL(2U, weekday2.c_encoding()); + CHECK_EQUAL(3U, weekday3.c_encoding()); + CHECK_EQUAL(4U, weekday4.c_encoding()); + CHECK_EQUAL(5U, weekday5.c_encoding()); + CHECK_EQUAL(6U, weekday6.c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_comparison_operators) + { + etl::chrono::weekday weekday1(1); + etl::chrono::weekday weekday2(2); + + CHECK_TRUE(weekday1 == weekday1); + CHECK_FALSE(weekday1 != weekday1); + CHECK_TRUE(weekday1 < weekday2); + CHECK_FALSE(weekday1 < weekday1); + CHECK_FALSE(weekday2 < weekday1); + CHECK_TRUE(weekday1 <= weekday2); + CHECK_TRUE(weekday1 <= weekday1); + CHECK_FALSE(weekday2 <= weekday1); + CHECK_FALSE(weekday1 > weekday2); + CHECK_FALSE(weekday1 > weekday1); + CHECK_TRUE(weekday2 > weekday1); + CHECK_FALSE(weekday1 >= weekday2); + CHECK_TRUE(weekday1 >= weekday1); + CHECK_TRUE(weekday2 >= weekday1); + +#if ETL_USING_CPP20 + CHECK_TRUE((weekday1 <=> weekday1) == 0); + CHECK_TRUE((weekday1 <=> weekday2) < 0); + CHECK_TRUE((weekday2 <=> weekday1) > 0); +#endif + } + + //************************************************************************* + TEST(test_weekday_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::weekday(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } + }; +} diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp new file mode 100644 index 000000000..dacb9c06b --- /dev/null +++ b/test/test_chrono_year.cpp @@ -0,0 +1,317 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2023 John Wellbelove + +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 "etl/platform.h" + +#if ETL_USING_CPP20 + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +namespace +{ + SUITE(test_chrono_year) + { + //************************************************************************* + TEST(test_default_constructor) + { + std::chrono::year std_year; + etl::chrono::year year; + + CHECK_EQUAL(std_year.ok(), year.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (int32_t i = -32767; i <= 32767; ++i) + { + std::chrono::year std_year(i); + etl::chrono::year year(i); + + CHECK_TRUE(year.ok()); + CHECK_EQUAL(i, int(year)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + etl::chrono::year year(-32767); + int count = int(year); + + for (int32_t i = 0; i < 65534; ++i) + { + ++count; + etl::chrono::year this_year = ++year; + + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, year); + CHECK_EQUAL(this_year, year); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::year std_year(-32767); + etl::chrono::year year(-32767); + + for (int32_t i = 0; i < 65536; ++i) + { + std::chrono::year std_last_year = std_year++; + etl::chrono::year last_year = year++; + + CHECK_EQUAL(std_last_year.ok(), last_year.ok()); + CHECK_EQUAL(int(std_last_year), int(last_year)); + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::year std_year(256); + etl::chrono::year year(256); + + for (int i = 0; i < 255; ++i) + { + --std_year; + --year; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::year std_year(256); + etl::chrono::year year(256); + + for (int i = 0; i < 255; ++i) + { + std::chrono::year std_last_year = std_year--; + etl::chrono::year last_year = year--; + + CHECK_EQUAL(std_last_year.ok(), last_year.ok()); + CHECK_EQUAL(int(std_last_year), int(last_year)); + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_plus_equal_years) + { + std::chrono::year std_year(0); + etl::chrono::year year(0); + + std::chrono::years std_years(2); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) + { + std_year += std_years; + year += years; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_year_plus_years) + { + std::chrono::year std_year(0); + etl::chrono::year year(0); + + std::chrono::years std_years(2); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) + { + std_year = std_year + std_years; + year = year + years; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_years_plus_year) + { + std::chrono::year std_year(0); + etl::chrono::year year(0); + + std::chrono::years std_years(2); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) + { + std_year = std_years + std_year; + year = years + year; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_minus_equal_years) + { + std::chrono::year std_year(256); + etl::chrono::year year(256); + + std::chrono::years std_years(2); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) + { + std_year -= std_years; + year -= years; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_year_minus_years) + { + std::chrono::year std_year(0); + etl::chrono::year year(0); + + std::chrono::years std_years(2); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) + { + std_year = std_year - std_years; + year = year - years; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + } + + //************************************************************************* + TEST(test_year_minus_year) + { + for (int i = 1; i < 31; ++i) + { + std::chrono::year std_year1(i); + std::chrono::year std_year2(31 - i); + + etl::chrono::year year1(i); + etl::chrono::year year2(31 - i); + + std::chrono::years std_years = std_year1 - std_year2; + etl::chrono::years years = year1 - year2; + + CHECK_EQUAL(std_years.count(), years.count()); + } + } + + //************************************************************************* + TEST(test_min_max_year) + { + CHECK_EQUAL(-32767, etl::chrono::year::min()); + CHECK_EQUAL(32767, etl::chrono::year::max()); + } + + //************************************************************************* + TEST(test_literal_year) + { + using namespace std::literals::chrono_literals; + using namespace etl::literals::chrono_literals; + + std::chrono::year std_year = 25y; + etl::chrono::year year = 25_year; + + CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_EQUAL(int(std_year), int(year)); + } + + //************************************************************************* + TEST(test_year_comparison_operators) + { + etl::chrono::year year10(10); + etl::chrono::year year20(20); + + CHECK_TRUE(year10 == year10); + CHECK_FALSE(year10 != year10); + CHECK_TRUE(year10 < year20); + CHECK_FALSE(year10 < year10); + CHECK_FALSE(year20 < year10); + CHECK_TRUE(year10 <= year20); + CHECK_TRUE(year10 <= year10); + CHECK_FALSE(year20 <= year10); + CHECK_FALSE(year10 > year20); + CHECK_FALSE(year10 > year10); + CHECK_TRUE(year20 > year10); + CHECK_FALSE(year10 >= year20); + CHECK_TRUE(year10 >= year10); + CHECK_TRUE(year20 >= year10); + +#if ETL_USING_CPP20 + CHECK_TRUE((year10 <=> year10) == 0); + CHECK_TRUE((year10 <=> year20) < 0); + CHECK_TRUE((year20 <=> year10) > 0); +#endif + } + + //************************************************************************* + TEST(test_year_hashes_are_unique) + { + std::vector hashes; + + for (int32_t i = -32767; i < 32768; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::year(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(65535U, hashes.size()); + } + }; +} + +#endif \ No newline at end of file From e6c47a198cfdd04d65e7acb3f7e5cdb81b0ca3e2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 8 Sep 2024 17:28:52 +0100 Subject: [PATCH 011/216] Added tests for weekday_indexed and weekday_last --- include/etl/private/chrono/weekday_indexed.h | 6 +- include/etl/private/chrono/weekday_last.h | 25 +--- test/test_chrono_weekday_indexed.cpp | 149 +++++++++++++++++++ test/test_chrono_weekday_last.cpp | 120 +++++++++++++++ test/vs2022/etl.vcxproj | 2 + 5 files changed, 276 insertions(+), 26 deletions(-) create mode 100644 test/test_chrono_weekday_indexed.cpp create mode 100644 test/test_chrono_weekday_last.cpp diff --git a/include/etl/private/chrono/weekday_indexed.h b/include/etl/private/chrono/weekday_indexed.h index 6c2f37e39..46bc2354e 100644 --- a/include/etl/private/chrono/weekday_indexed.h +++ b/include/etl/private/chrono/weekday_indexed.h @@ -47,11 +47,13 @@ namespace etl /// Default constructor //*********************************************************************** ETL_CONSTEXPR weekday_indexed() ETL_NOEXCEPT + : wd() + , i() { } //*********************************************************************** - /// Construct from unsigned + /// Construct from weekday and index //*********************************************************************** ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday& wd_, unsigned index_) ETL_NOEXCEPT : wd(wd_) @@ -100,7 +102,7 @@ namespace etl //*********************************************************************** ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { - return wd.ok() && (i >= 1U) && (i <= 5); + return wd.ok() && (i >= 1U) && (i <= 5U); } private: diff --git a/include/etl/private/chrono/weekday_last.h b/include/etl/private/chrono/weekday_last.h index e61890f9a..62dc337a2 100644 --- a/include/etl/private/chrono/weekday_last.h +++ b/include/etl/private/chrono/weekday_last.h @@ -43,17 +43,10 @@ namespace etl { public: - //*********************************************************************** - /// Default constructor - //*********************************************************************** - ETL_CONSTEXPR weekday_last() ETL_NOEXCEPT - { - } - //*********************************************************************** /// Construct from unsigned //*********************************************************************** - ETL_CONSTEXPR weekday_last(const etl::chrono::weekday& wd_) ETL_NOEXCEPT + ETL_CONSTEXPR explicit weekday_last(const etl::chrono::weekday& wd_) ETL_NOEXCEPT : wd(wd_) { } @@ -104,22 +97,6 @@ namespace etl { return (wd1.weekday() == wd2.weekday()); } - - //*********************************************************************** - /// Inequality operator - //*********************************************************************** - ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday_last& wd1, const etl::chrono::weekday_last& wd2) ETL_NOEXCEPT - { - return !(wd1 == wd2); - } - - //*********************************************************************** - /// weekday index operator from index - //*********************************************************************** - ETL_CONSTEXPR etl::chrono::weekday_last etl::chrono::weekday::operator[](etl::chrono::last_spec) const ETL_NOEXCEPT - { - return etl::chrono::weekday_last(*this); - } } //************************************************************************* diff --git a/test/test_chrono_weekday_indexed.cpp b/test/test_chrono_weekday_indexed.cpp new file mode 100644 index 000000000..faa555969 --- /dev/null +++ b/test/test_chrono_weekday_indexed.cpp @@ -0,0 +1,149 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +#include +#include + +namespace +{ + SUITE(test_chrono_weekday_indexed) + { + //************************************************************************* + TEST(test_default_constructor) + { + etl::chrono::weekday_indexed weekday_indexed; + + CHECK_FALSE(weekday_indexed.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 1U; i < 5U; ++i) + { + etl::chrono::weekday_indexed weekday_indexed_monday(etl::chrono::Monday, i); + etl::chrono::weekday_indexed weekday_indexed_tuesday(etl::chrono::Tuesday, i); + etl::chrono::weekday_indexed weekday_indexed_wednesday(etl::chrono::Wednesday, i); + etl::chrono::weekday_indexed weekday_indexed_thursday(etl::chrono::Thursday, i); + etl::chrono::weekday_indexed weekday_indexed_friday(etl::chrono::Friday, i); + etl::chrono::weekday_indexed weekday_indexed_saturday(etl::chrono::Saturday, i); + etl::chrono::weekday_indexed weekday_indexed_sunday(etl::chrono::Sunday, i); + + CHECK_TRUE(weekday_indexed_monday.ok()); + CHECK_TRUE(weekday_indexed_tuesday.ok()); + CHECK_TRUE(weekday_indexed_wednesday.ok()); + CHECK_TRUE(weekday_indexed_thursday.ok()); + CHECK_TRUE(weekday_indexed_friday.ok()); + CHECK_TRUE(weekday_indexed_saturday.ok()); + CHECK_TRUE(weekday_indexed_sunday.ok()); + + CHECK_EQUAL(etl::chrono::Monday.c_encoding(), weekday_indexed_monday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), weekday_indexed_tuesday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), weekday_indexed_wednesday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), weekday_indexed_thursday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Friday.c_encoding(), weekday_indexed_friday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), weekday_indexed_saturday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), weekday_indexed_sunday.weekday().c_encoding()); + + CHECK_EQUAL(i, weekday_indexed_monday.index()); + CHECK_EQUAL(i, weekday_indexed_tuesday.index()); + CHECK_EQUAL(i, weekday_indexed_wednesday.index()); + CHECK_EQUAL(i, weekday_indexed_thursday.index()); + CHECK_EQUAL(i, weekday_indexed_friday.index()); + CHECK_EQUAL(i, weekday_indexed_saturday.index()); + CHECK_EQUAL(i, weekday_indexed_sunday.index()); + } + } + + //************************************************************************* + TEST(test_constructor_out_of_range) + { + for (unsigned i = 6U; i < 256U; ++i) + { + etl::chrono::weekday_indexed weekday_indexed_monday(etl::chrono::Monday, i); + etl::chrono::weekday_indexed weekday_indexed_tuesday(etl::chrono::Tuesday, i); + etl::chrono::weekday_indexed weekday_indexed_wednesday(etl::chrono::Wednesday, i); + etl::chrono::weekday_indexed weekday_indexed_thursday(etl::chrono::Thursday, i); + etl::chrono::weekday_indexed weekday_indexed_friday(etl::chrono::Friday, i); + etl::chrono::weekday_indexed weekday_indexed_saturday(etl::chrono::Saturday, i); + etl::chrono::weekday_indexed weekday_indexed_sunday(etl::chrono::Sunday, i); + + CHECK_FALSE(weekday_indexed_monday.ok()); + CHECK_FALSE(weekday_indexed_tuesday.ok()); + CHECK_FALSE(weekday_indexed_wednesday.ok()); + CHECK_FALSE(weekday_indexed_thursday.ok()); + CHECK_FALSE(weekday_indexed_friday.ok()); + CHECK_FALSE(weekday_indexed_saturday.ok()); + CHECK_FALSE(weekday_indexed_sunday.ok()); + } + } + + //************************************************************************* + TEST(test_weekday_indexed_comparison_operators) + { + etl::chrono::weekday_indexed weekday_indexed1(etl::chrono::Monday, 1); + etl::chrono::weekday_indexed weekday_indexed2(etl::chrono::Monday, 1); + etl::chrono::weekday_indexed weekday_indexed3(etl::chrono::Monday, 2); + etl::chrono::weekday_indexed weekday_indexed4(etl::chrono::Tuesday, 1); + + CHECK_TRUE(weekday_indexed1 == weekday_indexed2); + CHECK_FALSE(weekday_indexed1 == weekday_indexed3); + CHECK_FALSE(weekday_indexed1 == weekday_indexed4); + } + + //************************************************************************* + TEST(test_weekday_indexed_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 6; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Monday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Tuesday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Wednesday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Thursday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Friday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Saturday, i))); + hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Sunday, i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + } + }; +} diff --git a/test/test_chrono_weekday_last.cpp b/test/test_chrono_weekday_last.cpp new file mode 100644 index 000000000..09c8f8d61 --- /dev/null +++ b/test/test_chrono_weekday_last.cpp @@ -0,0 +1,120 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include + +#include +#include + +namespace +{ + SUITE(test_chrono_weekday_last) + { + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 1U; i < 5U; ++i) + { + etl::chrono::weekday_last weekday_last_monday(etl::chrono::Monday); + etl::chrono::weekday_last weekday_last_tuesday(etl::chrono::Tuesday); + etl::chrono::weekday_last weekday_last_wednesday(etl::chrono::Wednesday); + etl::chrono::weekday_last weekday_last_thursday(etl::chrono::Thursday); + etl::chrono::weekday_last weekday_last_friday(etl::chrono::Friday); + etl::chrono::weekday_last weekday_last_saturday(etl::chrono::Saturday); + etl::chrono::weekday_last weekday_last_sunday(etl::chrono::Sunday); + + CHECK_TRUE(weekday_last_monday.ok()); + CHECK_TRUE(weekday_last_tuesday.ok()); + CHECK_TRUE(weekday_last_wednesday.ok()); + CHECK_TRUE(weekday_last_thursday.ok()); + CHECK_TRUE(weekday_last_friday.ok()); + CHECK_TRUE(weekday_last_saturday.ok()); + CHECK_TRUE(weekday_last_sunday.ok()); + + CHECK_EQUAL(etl::chrono::Monday.c_encoding(), weekday_last_monday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), weekday_last_tuesday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), weekday_last_wednesday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), weekday_last_thursday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Friday.c_encoding(), weekday_last_friday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), weekday_last_saturday.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), weekday_last_sunday.weekday().c_encoding()); + } + } + + //************************************************************************* + TEST(test_constructor_out_of_range) + { + for (unsigned i = 8U; i < 256U; ++i) + { + auto wd = etl::chrono::weekday(i); + etl::chrono::weekday_last weekday_last(wd); + + CHECK_FALSE(weekday_last.ok()); + } + } + + //************************************************************************* + TEST(test_weekday_last_comparison_operators) + { + etl::chrono::weekday_last weekday_last1(etl::chrono::Monday); + etl::chrono::weekday_last weekday_last2(etl::chrono::Monday); + etl::chrono::weekday_last weekday_last3(etl::chrono::Tuesday); + + CHECK_TRUE(weekday_last1 == weekday_last2); + CHECK_FALSE(weekday_last1 == weekday_last3); + } + + //************************************************************************* + TEST(test_weekday_last_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 6; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Monday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Tuesday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Wednesday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Thursday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Friday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Saturday))); + hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Sunday))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + } + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 20c4b6d4b..01e8ce6e9 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -7959,6 +7959,8 @@ + + From 4942ff840e27580b9a12ad5b4e65bf5c72e76fe6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Sep 2024 14:03:05 +0100 Subject: [PATCH 012/216] etl::duration work in progress --- include/etl/private/chrono/duration.h | 220 ++++++++++++++++++++++---- include/etl/ratio.h | 70 +++++++- test/test_chrono_duration.cpp | 209 ++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 9 ++ 5 files changed, 475 insertions(+), 34 deletions(-) create mode 100644 test/test_chrono_duration.cpp diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index b499f0f40..2163b9255 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -40,14 +40,65 @@ namespace etl { namespace chrono { + namespace private_chrono + { + // Helper to find the greatest common divisor + template + struct gcd + { + static ETL_CONSTANT intmax_t value = gcd::value; + }; + + template + struct gcd + { + static ETL_CONSTANT intmax_t value = A; + }; + + // Helper to find the least common multiple + template + struct lcm + { + static ETL_CONSTANT intmax_t value = (A / gcd::value) * B; + }; + } + + //*********************************************************************** + /// duration_values + //*********************************************************************** + template + struct duration_values + { + //*********************************************************************** + static ETL_CONSTEXPR TRep zero() + { + return TRep(0); + } + + //*********************************************************************** + static ETL_CONSTEXPR TRep min() + { + return etl::numeric_limits::min(); + } + + //*********************************************************************** + static ETL_CONSTEXPR TRep max() + { + return etl::numeric_limits::max(); + } + }; + //*********************************************************************** /// duration //*********************************************************************** - template > + template > class duration { public: + typedef TRep rep; + typedef TPeriod period; + //*********************************************************************** ETL_CONSTEXPR duration() ETL_NOEXCEPT : value(0) @@ -55,53 +106,53 @@ namespace etl } //*********************************************************************** - ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT : value(other.value) { } //*********************************************************************** - template< typename TValue2 > - ETL_CONSTEXPR explicit duration(const TValue2& value_) ETL_NOEXCEPT - : value(static_cast(value_)) + template + ETL_CONSTEXPR explicit duration(const TRep2& value_) ETL_NOEXCEPT + : value(static_cast(value_)) { } //*********************************************************************** - template< typename TValue2, typename TPeriod2 > - ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT - : value(static_cast(other.value)) + template + ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT + : value(static_cast(other.count())) { - ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); } //*********************************************************************** - static ETL_CONSTEXPR etl::chrono::duration< TValue, TPeriod> zero() ETL_NOEXCEPT + ETL_CONSTEXPR TRep count() const ETL_NOEXCEPT { - return etl::chrono::duration{ 0, TPeriod()}; + return value; } //*********************************************************************** - static ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration zero() ETL_NOEXCEPT { - return etl::chrono::duration { etl::numeric_limits::min() }; + return etl::chrono::duration(etl::chrono::duration_values::zero()); } //*********************************************************************** - static ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration min() ETL_NOEXCEPT { - return etl::chrono::duration{ etl::numeric_limits::max() }; + return etl::chrono::duration(etl::chrono::duration_values::min()); } //*********************************************************************** - ETL_CONSTEXPR TValue count() const ETL_NOEXCEPT + static ETL_CONSTEXPR etl::chrono::duration max() ETL_NOEXCEPT { - return value; + return etl::chrono::duration(etl::chrono::duration_values::max()); } private: - TValue value; + TRep value; }; //*********************************************************************** @@ -128,19 +179,134 @@ namespace etl //*********************************************************************** /// duration_cast //*********************************************************************** - template - ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT + template + ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT + { + typedef TRep from_rep; + typedef TPeriod from_period; + + typedef typename TToDuration::rep to_rep; + typedef typename TToDuration::period to_period; + + typedef typename etl::ratio_divide::type ratio_divide_t; + typedef typename etl::common_type::type common_t; + + common_t ct_count = static_cast(d.count()); + common_t ct_num = static_cast(ratio_divide_t::type::num); + common_t ct_den = static_cast(ratio_divide_t::type::den); + + if ETL_IF_CONSTEXPR((from_period::num == to_period::num) && (from_period::den == to_period::den)) + { + return TToDuration(static_cast(d.count())); + } + else if ETL_IF_CONSTEXPR(ratio_divide_t::num == 1) + { + return TToDuration(static_cast(ct_count / ct_den)); + } + else if ETL_IF_CONSTEXPR(ratio_divide_t::den == 1) + { + return TToDuration(static_cast(ct_count * ct_num)); + } + else + { + return TToDuration(static_cast((ct_count * ct_num) / ct_den)); + } + } + } + + //************************************************************************* + /// Hash function for etl::chrono::duration + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template + struct hash > + { + size_t operator()(const etl::chrono::duration& d) const { - using to_value_type = typename TToDuration::value_type; - using to_period = typename TToDuration::period; + TRep value = d.count(); + size_t num = TPeriod::num; + size_t den = TPeriod::den; + + return 0; //etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif + + //*********************************************************************** + /// Find the common type of two duration types. + //*********************************************************************** + template + struct common_type, etl::chrono::duration > + { + private: - // Calculate the conversion factor between the periods - ETL_CONSTEXPR auto conversion_factor = (static_cast(TPeriod::num) / TPeriod::den) * (to_period::den / to_period::num); + typedef typename etl::common_type::type value_type; + typedef etl::ratio::value, + etl::chrono::private_chrono::lcm::value> period_type; + + public: + + using type = etl::chrono::duration; + }; +} + +#if ETL_HAS_CHRONO_LITERALS_DAY +#if ETL_USING_CPP11 +namespace etl +{ + namespace literals + { + namespace chrono_literals + { + //*********************************************************************** + /// Literal for hours duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::hours operator ""_hours(unsigned long long h) noexcept + { + return etl::chrono::hours(static_cast(h)); + } - // Convert the value - to_value_type converted_value = static_cast(d.count() * conversion_factor); + //*********************************************************************** + /// Literal for minutes duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::hours operator ""_minutes(unsigned long long m) noexcept + { + return etl::chrono::minutes(static_cast(m)); + } - return TToDuration(converted_value); + //*********************************************************************** + /// Literal for seconds duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::seconds operator ""_seconds(unsigned long long s) noexcept + { + return etl::chrono::seconds(static_cast(s)); + } + + //*********************************************************************** + /// Literal for milliseconds duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) noexcept + { + return etl::chrono::milliseconds(static_cast(s)); + } + + //*********************************************************************** + /// Literal for microseconds duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::microseconds operator ""_microseconds(unsigned long long s) noexcept + { + return etl::chrono::microseconds(static_cast(s)); + } + + //*********************************************************************** + /// Literal for nanoseconds duration + //*********************************************************************** + ETL_IF_CONSTEXPR etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) noexcept + { + return etl::chrono::nanoseconds(static_cast(s)); + } } } } +#endif +#endif diff --git a/include/etl/ratio.h b/include/etl/ratio.h index 8c7fa81d9..b5034c3fe 100644 --- a/include/etl/ratio.h +++ b/include/etl/ratio.h @@ -41,19 +41,72 @@ SOFTWARE. namespace etl { - template + namespace private_ratio + { + // Helper to find the greatest common divisor + template + struct gcd + { + static ETL_CONSTANT intmax_t value = gcd::value; + }; + + template + struct gcd + { + static ETL_CONSTANT intmax_t value = A; + }; + + // Helper to find the least common multiple + template + struct lcm + { + static ETL_CONSTANT intmax_t value = (A / gcd::value) * B; + }; + } + + //*********************************************************************** + /// ratio + //*********************************************************************** + template struct ratio { - static ETL_CONSTANT intmax_t num = NUM; - static ETL_CONSTANT intmax_t den = DEN; + ETL_STATIC_ASSERT(Num != 0, "Numerator cannot be zero"); + + static ETL_CONSTANT intmax_t num = Num / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t den = Den / private_ratio::gcd::value; + + typedef etl::ratio type; }; - template - ETL_CONSTANT intmax_t ratio::num; + template + ETL_CONSTANT intmax_t ratio::num; + + template + ETL_CONSTANT intmax_t ratio::den; + + //*********************************************************************** + /// ratio_divide + //*********************************************************************** + template + struct ratio_divide + { + private: + + static ETL_CONSTANT intmax_t N = TRatio1::num * TRatio2::den; + static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::num; + + static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + + public: + + typedef etl::ratio type; + }; - template - ETL_CONSTANT intmax_t ratio::den; + //*********************************************************************** + /// Predefined ration types. + //*********************************************************************** #if INT_MAX > INT32_MAX typedef ratio<1, 1000000000000000000000000> yocto; typedef ratio<1, 1000000000000000000000> zepto; @@ -95,6 +148,9 @@ namespace etl /// An approximation of root 2. typedef ratio<239, 169> ratio_root2; + /// An approximation of 1 over root 2. + typedef ratio<169, 239> ratio_1_over_root2; + /// An approximation of e. typedef ratio<326, 120> ratio_e; } diff --git a/test/test_chrono_duration.cpp b/test/test_chrono_duration.cpp new file mode 100644 index 000000000..e8eddac8b --- /dev/null +++ b/test/test_chrono_duration.cpp @@ -0,0 +1,209 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include +#include + +namespace +{ + SUITE(test_chrono_duration) + { + //************************************************************************* + TEST(test_default_constructor) + { + using duration_type = etl::chrono::duration; + + duration_type duration; + + CHECK_TRUE((etl::is_same::value)); + CHECK_TRUE((etl::is_same::value)); + CHECK_EQUAL(0, duration.count()); + } + + //************************************************************************* + TEST(test_duration_values_zero_min_max) + { + using duration_values_type = etl::chrono::duration_values; + + CHECK_EQUAL(size_t(0), duration_values_type::zero()); + CHECK_EQUAL(std::numeric_limits::min(), duration_values_type::min()); + CHECK_EQUAL(std::numeric_limits::max(), duration_values_type::max()); + } + + //************************************************************************* + TEST(test_duration_zero_min_max) + { + using duration_type = etl::chrono::duration; + + //CHECK_EQUAL(duration_type(0), duration_type::zero()); + //CHECK_EQUAL(duration_type(std::numeric_limits::min()), duration_type::min()); + //CHECK_EQUAL(duration_type(std::numeric_limits::max()), duration_type::max()); + } + + //************************************************************************* + TEST(test_predefined_duration_types) + { + CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::num), etl::chrono::nanoseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::den), etl::chrono::nanoseconds::period::den); + + CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::num), etl::chrono::microseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::den), etl::chrono::microseconds::period::den); + + CHECK_EQUAL((etl::ratio<1U, 1000U>::type::num), etl::chrono::milliseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000U>::type::den), etl::chrono::milliseconds::period::den); + + CHECK_EQUAL(etl::ratio<1U>::type::num, etl::chrono::seconds::period::num); + CHECK_EQUAL(etl::ratio<1U>::type::den, etl::chrono::seconds::period::den); + + CHECK_EQUAL(etl::ratio<60U>::type::num, etl::chrono::minutes::period::num); + CHECK_EQUAL(etl::ratio<60U>::type::den, etl::chrono::minutes::period::den); + + CHECK_EQUAL(etl::ratio<3600U>::type::num, etl::chrono::hours::period::num); + CHECK_EQUAL(etl::ratio<3600U>::type::den, etl::chrono::hours::period::den); + + CHECK_EQUAL(etl::ratio<86400U>::type::num, etl::chrono::days::period::num); + CHECK_EQUAL(etl::ratio<86400U>::type::den, etl::chrono::days::period::den); + + CHECK_EQUAL(etl::ratio<604800U>::type::num, etl::chrono::weeks::period::num); + CHECK_EQUAL(etl::ratio<604800U>::type::den, etl::chrono::weeks::period::den); + + CHECK_EQUAL(etl::ratio<604800U>::type::num, etl::chrono::weeks::period::num); + CHECK_EQUAL(etl::ratio<604800U>::type::den, etl::chrono::weeks::period::den); + + CHECK_EQUAL(etl::ratio<2629746U>::type::num, etl::chrono::months::period::num); + CHECK_EQUAL(etl::ratio<2629746U>::type::den, etl::chrono::months::period::den); + + CHECK_EQUAL(etl::ratio<31556952U>::type::num, etl::chrono::years::period::num); + CHECK_EQUAL(etl::ratio<31556952U>::type::den, etl::chrono::years::period::den); + } + + //************************************************************************* + TEST(test_duration_common_type) + { + using duration_type1 = etl::chrono::duration; + using duration_type2 = etl::chrono::duration; + + using duration_type = etl::common_type::type; + + CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); + } + + //************************************************************************* + TEST(test_duration_cast_with_same_rep_and_period_for_duration_type1_and_duration_type2) + { + using duration_type1 = etl::chrono::duration; + using duration_type2 = etl::chrono::duration>; + + duration_type1 dur1(245); + duration_type2 dur2 = etl::chrono::duration_cast(dur1); + + CHECK_EQUAL(duration_type1::period::num, duration_type2::period::num); + CHECK_EQUAL(duration_type1::period::den, duration_type2::period::den); + CHECK_EQUAL(dur1.count(), dur2.count()); + } + + //************************************************************************* + TEST(test_duration_cast_where_ratio_divide_of_periods_num_is_1) + { + using duration_type1 = etl::chrono::duration; + using duration_type2 = etl::chrono::duration; + + duration_type1 dur1(245000); + duration_type2 dur2 = etl::chrono::duration_cast(dur1); + + typedef typename etl::ratio_divide::type ratio_divide_t; + + int multiplier = duration_type1::period::den / duration_type2::period::den; + + CHECK_EQUAL(1, ratio_divide_t::num); + CHECK_EQUAL(dur1.count(), dur2.count() * multiplier); + } + + //************************************************************************* + TEST(test_duration_cast_where_ratio_divide_of_periods_den_is_1) + { + using duration_type1 = etl::chrono::duration; + using duration_type2 = etl::chrono::duration; + + duration_type1 dur1(245); + duration_type2 dur2 = etl::chrono::duration_cast(dur1); + + typedef typename etl::ratio_divide::type ratio_divide_t; + + int multiplier = duration_type2::period::den / duration_type1::period::den; + + CHECK_EQUAL(1, ratio_divide_t::den); + CHECK_EQUAL(dur1.count() * multiplier, dur2.count()); + } + + //************************************************************************* + TEST(test_duration_cast_when_rep_and_period_are_not_equal_and_ratio_divide_of_periods_num_and_den_are_not_1) + { + using duration_type1 = etl::chrono::duration>; + using duration_type2 = etl::chrono::duration>; + + duration_type1 dur1(245); + duration_type2 dur2 = etl::chrono::duration_cast(dur1); + + typedef typename etl::ratio_divide::type ratio_divide_t; + + CHECK_FALSE((duration_type1::period::num == duration_type2::period::num) && (duration_type1::period::den == duration_type2::period::den)); + CHECK_FALSE(1 == ratio_divide_t::num); + CHECK_FALSE(1 == ratio_divide_t::den); + CHECK_EQUAL(dur1.count(), (dur2.count() * duration_type2::period::num) / duration_type1::period::num); + } + + //************************************************************************* + TEST(test_duration_hashes_are_unique) + { + using duration_type = etl::chrono::duration; + + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(duration_type(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 01e8ce6e9..1d21befcd 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -7957,6 +7957,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 6ab086e78..d0b889615 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3434,6 +3434,15 @@ Tests\Syntax Checks\Source + + Tests\Chrono + + + Tests\Chrono + + + Tests\Chrono + From 0d0b9be310725beb13b5a6001e6e6ee2d619082b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 13 Sep 2024 19:55:18 +0100 Subject: [PATCH 013/216] etl::duration work in progress --- include/etl/private/chrono/duration.h | 115 ++++++++++++++++++++++++-- test/test_chrono_duration.cpp | 105 +++++++++++++++++++++-- 2 files changed, 204 insertions(+), 16 deletions(-) diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 2163b9255..9cc58ea9c 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -35,6 +35,7 @@ SOFTWARE. #include "../../ratio.h" #include "../../static_assert.h" #include "../../limits.h" +#include "../../type_traits.h" namespace etl { @@ -88,6 +89,12 @@ namespace etl } }; + template + class duration; + + template + ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT; + //*********************************************************************** /// duration //*********************************************************************** @@ -96,8 +103,8 @@ namespace etl { public: - typedef TRep rep; - typedef TPeriod period; + typedef TRep rep; + typedef typename TPeriod::type period; //*********************************************************************** ETL_CONSTEXPR duration() ETL_NOEXCEPT @@ -119,19 +126,47 @@ namespace etl } //*********************************************************************** - template + template ::type::den == 1, int>::type = 0> ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT - : value(static_cast(other.count())) + : value(etl::chrono::duration_cast >(other).count()) { + + bool b = etl::ratio_divide::type::den == 1; + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); } + //*********************************************************************** + template + ETL_CONSTEXPR14 + typename etl::enable_if::type::den == 1, etl::chrono::duration&>::type + operator =(const etl::chrono::duration& other) ETL_NOEXCEPT + { + bool b = etl::ratio_divide::type::den == 1; + + value = etl::chrono::duration_cast >(other).count(); + + return *this; + } + //*********************************************************************** ETL_CONSTEXPR TRep count() const ETL_NOEXCEPT { return value; } + //*********************************************************************** + ETL_CONSTEXPR etl::common_type_t operator +() const + { + return etl::common_type_t(*this); + } + + //*********************************************************************** + ETL_CONSTEXPR etl::common_type_t operator -() const + { + return etl::common_type_t(-value); + } + //*********************************************************************** static ETL_CONSTEXPR etl::chrono::duration zero() ETL_NOEXCEPT { @@ -152,7 +187,7 @@ namespace etl private: - TRep value; + TRep value; }; //*********************************************************************** @@ -180,7 +215,7 @@ namespace etl /// duration_cast //*********************************************************************** template - ETL_CONSTEXPR TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT + ETL_CONSTEXPR14 TToDuration duration_cast(const etl::chrono::duration& d) ETL_NOEXCEPT { typedef TRep from_rep; typedef TPeriod from_period; @@ -221,7 +256,7 @@ namespace etl template struct hash > { - size_t operator()(const etl::chrono::duration& d) const + ETL_CONSTEXPR14 size_t operator()(const etl::chrono::duration& d) const { TRep value = d.count(); size_t num = TPeriod::num; @@ -248,6 +283,70 @@ namespace etl using type = etl::chrono::duration; }; + + //*********************************************************************** + /// Check equality. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator ==(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + typedef typename etl::common_type, etl::chrono::duration >::type common_t; + + common_t l = etl::chrono::duration_cast(lhs); + common_t r = etl::chrono::duration_cast(rhs); + + return l.count() == r.count(); + } + + //*********************************************************************** + /// Check inequality. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator !=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Less-than. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator <(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + typedef typename etl::common_type, etl::chrono::duration >::type common_t; + + common_t l = etl::chrono::duration_cast(lhs); + common_t r = etl::chrono::duration_cast(rhs); + + return l.count() < r.count(); + } + + //*********************************************************************** + /// Less-than-or-equal. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator <=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + return !(rhs < lhs); + } + + //*********************************************************************** + /// Greater-than. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator >(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + return rhs < lhs; + } + + //*********************************************************************** + /// Greater-than-or-equal. + //*********************************************************************** + template + ETL_CONSTEXPR14 bool operator >=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + return !(lhs < rhs); + } } #if ETL_HAS_CHRONO_LITERALS_DAY @@ -269,7 +368,7 @@ namespace etl //*********************************************************************** /// Literal for minutes duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::hours operator ""_minutes(unsigned long long m) noexcept + ETL_IF_CONSTEXPR etl::chrono::minutes operator ""_minutes(unsigned long long m) noexcept { return etl::chrono::minutes(static_cast(m)); } diff --git a/test/test_chrono_duration.cpp b/test/test_chrono_duration.cpp index e8eddac8b..f20ed3fc2 100644 --- a/test/test_chrono_duration.cpp +++ b/test/test_chrono_duration.cpp @@ -38,6 +38,7 @@ SOFTWARE. #include #include #include +#include namespace { @@ -70,13 +71,13 @@ namespace { using duration_type = etl::chrono::duration; - //CHECK_EQUAL(duration_type(0), duration_type::zero()); - //CHECK_EQUAL(duration_type(std::numeric_limits::min()), duration_type::min()); - //CHECK_EQUAL(duration_type(std::numeric_limits::max()), duration_type::max()); + CHECK_EQUAL(duration_type(0).count(), duration_type::zero().count()); + CHECK_EQUAL(duration_type(std::numeric_limits::min()).count(), duration_type::min().count()); + CHECK_EQUAL(duration_type(std::numeric_limits::max()).count(), duration_type::max().count()); } //************************************************************************* - TEST(test_predefined_duration_types) + TEST(test_predefined_duration_periods) { CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::num), etl::chrono::nanoseconds::period::num); CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::den), etl::chrono::nanoseconds::period::den); @@ -149,10 +150,10 @@ namespace typedef typename etl::ratio_divide::type ratio_divide_t; - int multiplier = duration_type1::period::den / duration_type2::period::den; + int microseonds_per_millisecond = duration_type1::period::den / duration_type2::period::den; CHECK_EQUAL(1, ratio_divide_t::num); - CHECK_EQUAL(dur1.count(), dur2.count() * multiplier); + CHECK_EQUAL(dur1.count(), dur2.count() * microseonds_per_millisecond); } //************************************************************************* @@ -166,10 +167,10 @@ namespace typedef typename etl::ratio_divide::type ratio_divide_t; - int multiplier = duration_type2::period::den / duration_type1::period::den; + int microseonds_per_millisecond = duration_type2::period::den / duration_type1::period::den; CHECK_EQUAL(1, ratio_divide_t::den); - CHECK_EQUAL(dur1.count() * multiplier, dur2.count()); + CHECK_EQUAL(dur1.count() * microseonds_per_millisecond, dur2.count()); } //************************************************************************* @@ -189,6 +190,94 @@ namespace CHECK_EQUAL(dur1.count(), (dur2.count() * duration_type2::period::num) / duration_type1::period::num); } + //************************************************************************* + TEST(test_duration_assignment) + { + int Two_Hours = 2; + int Four_Hours = 4; + + etl::chrono::hours hours1(Two_Hours); + etl::chrono::hours hours2(Four_Hours); + etl::chrono::seconds seconds(0); + + seconds = hours1; + int seconds_per_hour = etl::chrono::hours::period::num / etl::chrono::seconds::period::num; + CHECK_EQUAL(seconds.count(), hours1.count() * seconds_per_hour); + CHECK_EQUAL(Two_Hours, hours1.count()); + + hours1 = hours2; + CHECK_EQUAL(Four_Hours, hours1.count()); + CHECK_EQUAL(Four_Hours, hours2.count()); + } + + //************************************************************************* + TEST(test_duration_comparison_operators) + { + using duration_type1 = etl::chrono::duration; + using duration_type2 = etl::chrono::duration; + + duration_type1 dur1a(245); + duration_type1 dur1b(245); + duration_type1 dur1c(246); + duration_type2 dur2b(245000); + duration_type2 dur2c(245001); + + // Same duration types + CHECK_TRUE(dur1a == dur1b); + CHECK_TRUE(dur1a != dur1c); + CHECK_FALSE(dur1a < dur1b); + CHECK_TRUE(dur1a <= dur1b); + CHECK_FALSE(dur1a > dur1b); + CHECK_TRUE(dur1a >= dur1b); + + CHECK_TRUE(dur1a < dur1c); + CHECK_FALSE(dur1c < dur1a); + CHECK_TRUE(dur1a <= dur1c); + CHECK_FALSE(dur1c <= dur1a); + CHECK_FALSE(dur1a > dur1c); + CHECK_TRUE(dur1c > dur1a); + CHECK_FALSE(dur1a >= dur1c); + CHECK_TRUE(dur1c >= dur1a); + + // Different duration types + CHECK_TRUE(dur1a == dur2b); + CHECK_TRUE(dur2b == dur1a); + CHECK_TRUE(dur2c != dur1a); + CHECK_TRUE(dur1a != dur2c); + + CHECK_FALSE(dur1a < dur2b); + CHECK_FALSE(dur2b < dur1a); + CHECK_TRUE(dur1a <= dur2b); + CHECK_TRUE(dur2b <= dur1a); + CHECK_FALSE(dur1a > dur2b); + CHECK_FALSE(dur2b > dur1a); + CHECK_TRUE(dur1a >= dur2b); + CHECK_TRUE(dur2b >= dur1a); + + CHECK_TRUE(dur1a < dur2c); + CHECK_FALSE(dur2c < dur1a); + CHECK_TRUE(dur1a <= dur2c); + CHECK_FALSE(dur2c <= dur1a); + CHECK_FALSE(dur1a > dur2c); + CHECK_TRUE(dur2c > dur1a); + CHECK_FALSE(dur1a >= dur2c); + CHECK_TRUE(dur2c >= dur1a); + } + + //************************************************************************* + TEST(test_duration_unary_operators) + { + using duration_type = etl::chrono::duration; + + duration_type dur(245); + + duration_type positive = +dur; + duration_type negative = -dur; + + CHECK_EQUAL(245, positive.count()); + CHECK_EQUAL(-245, negative.count()); + } + //************************************************************************* TEST(test_duration_hashes_are_unique) { From 4741c71e340888c4dff8488f546fca8ddc554cd4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 14 Sep 2024 20:02:25 +0100 Subject: [PATCH 014/216] etl::ratio work-in-progress --- include/etl/ratio.h | 62 +++++++++++++++++++-- test/test_ratio.cpp | 133 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+), 4 deletions(-) create mode 100644 test/test_ratio.cpp diff --git a/include/etl/ratio.h b/include/etl/ratio.h index b5034c3fe..77a89093d 100644 --- a/include/etl/ratio.h +++ b/include/etl/ratio.h @@ -32,6 +32,7 @@ SOFTWARE. #define ETL_RATIO_INCLUDED #include "platform.h" +#include "static_assert.h" #include #include @@ -71,6 +72,7 @@ namespace etl struct ratio { ETL_STATIC_ASSERT(Num != 0, "Numerator cannot be zero"); + ETL_STATIC_ASSERT(Den != 0, "Denominator cannot be zero"); static ETL_CONSTANT intmax_t num = Num / private_ratio::gcd::value; static ETL_CONSTANT intmax_t den = Den / private_ratio::gcd::value; @@ -103,13 +105,67 @@ namespace etl typedef etl::ratio type; }; + //*********************************************************************** + /// ratio_multiply + //*********************************************************************** + template + struct ratio_multiply + { + private: + + static ETL_CONSTANT intmax_t N = TRatio1::num * TRatio2::num; + static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den; + + static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + + public: + + typedef etl::ratio type; + }; + + //*********************************************************************** + /// ratio_add + //*********************************************************************** + template + struct ratio_add + { + private: + + static ETL_CONSTANT intmax_t N = (TRatio1::num * TRatio2::den) + (TRatio2::num * TRatio1::den); + static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den;; + + static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + + public: + + typedef etl::ratio type; + }; + + //*********************************************************************** + /// ratio_subtract + //*********************************************************************** + template + struct ratio_subtract + { + private: + + static ETL_CONSTANT intmax_t N = (TRatio1::num * TRatio2::den) - (TRatio2::num * TRatio1::den); + static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den;; + + static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + + public: + + typedef etl::ratio type; + }; //*********************************************************************** /// Predefined ration types. //*********************************************************************** #if INT_MAX > INT32_MAX - typedef ratio<1, 1000000000000000000000000> yocto; - typedef ratio<1, 1000000000000000000000> zepto; typedef ratio<1, 1000000000000000000> atto; typedef ratio<1, 1000000000000000> femto; typedef ratio<1, 1000000000000> pico; @@ -138,8 +194,6 @@ namespace etl typedef ratio<1000000000000, 1> tera; typedef ratio<1000000000000000, 1> peta; typedef ratio<1000000000000000000, 1> exa; - typedef ratio<1000000000000000000000, 1> zetta; - typedef ratio<1000000000000000000000000, 1> yotta; #endif /// An approximation of PI to 6 digits. diff --git a/test/test_ratio.cpp b/test/test_ratio.cpp new file mode 100644 index 000000000..7f061d49e --- /dev/null +++ b/test/test_ratio.cpp @@ -0,0 +1,133 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "unit_test_framework.h" + +#include "etl/ratio.h" + +namespace +{ + // Helper to find the greatest common divisor + template + struct gcd + { + static ETL_CONSTANT intmax_t value = gcd::value; + }; + + template + struct gcd + { + static ETL_CONSTANT intmax_t value = A; + }; + + // Helper to find the least common multiple + template + struct lcm + { + static ETL_CONSTANT intmax_t value = (A / gcd::value) * B; + }; + + SUITE(test_ratio) + { + //************************************************************************* + TEST(test_constructor) + { + constexpr intmax_t Num = 20; + constexpr intmax_t Den = 600; + + intmax_t N = Num / gcd::value; + intmax_t D = Den / gcd::value; + + using ratio = etl::ratio; + using ratio_type = ratio::type; + + CHECK_FALSE((std::is_same::value)); + + CHECK_EQUAL(N, ratio::num); + CHECK_EQUAL(D, ratio::den); + + CHECK_EQUAL(N, ratio_type::num); + CHECK_EQUAL(D, ratio_type::den); + } + + //************************************************************************* + TEST(test_predefined_ratios) + { +#if INT_MAX > INT32_MAX + CHECK_EQUAL(etl::atto::num, 1); + CHECK_EQUAL(etl::atto::den, 1000000000000000000); + CHECK_EQUAL(etl::femto::num, 1); + CHECK_EQUAL(etl::femto::den, 1000000000000000); + CHECK_EQUAL(etl::pico::num, 1); + CHECK_EQUAL(etl::pico::den, 1000000000000); +#endif +#if (INT_MAX >= INT32_MAX) + CHECK_EQUAL(etl::nano::num, 1); + CHECK_EQUAL(etl::nano::den, 1000000000); + CHECK_EQUAL(etl::micro::num, 1); + CHECK_EQUAL(etl::micro::den, 1000000); +#endif +#if (INT_MAX >= INT16_MAX) + CHECK_EQUAL(etl::milli::num, 1); + CHECK_EQUAL(etl::milli::den, 1000); + CHECK_EQUAL(etl::centi::num, 1); + CHECK_EQUAL(etl::centi::den, 100); + CHECK_EQUAL(etl::deci::num, 1); + CHECK_EQUAL(etl::deci::den, 10); + CHECK_EQUAL(etl::deca::num, 10); + CHECK_EQUAL(etl::deca::den, 1); + CHECK_EQUAL(etl::hecto::num, 100); + CHECK_EQUAL(etl::hecto::den, 1); + CHECK_EQUAL(etl::kilo::num, 1000); + CHECK_EQUAL(etl::kilo::den, 1); +#endif +#if (INT_MAX >= INT32_MAX) + CHECK_EQUAL(etl::mega::num, 1000000); + CHECK_EQUAL(etl::mega::den, 1); + CHECK_EQUAL(etl::giga::num, 1000000000); + CHECK_EQUAL(etl::giga::den, 1); +#endif + +#if INT_MAX > INT32_MAX + CHECK_EQUAL(etl::tera::num, 1000000000000); + CHECK_EQUAL(etl::tera::den, 1); + CHECK_EQUAL(etl::peta::num, 1000000000000000); + CHECK_EQUAL(etl::peta::den, 1); + CHECK_EQUAL(etl::exa::num, 1000000000000000000); + CHECK_EQUAL(etl::exa::den, 1); +#endif + + double expected_pi = 3.1415926535897931; + double actual_pi = double(etl::ratio_pi::num) / double(etl::ratio_pi::den); + + CHECK_CLOSE(expected_pi, actual_pi, 0.0000003); + } + }; +} From bec9f4a2dffd1a89778b3bd0d0f41061ab2b3c5c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 15 Sep 2024 14:12:40 +0100 Subject: [PATCH 015/216] Added etl::ratio tests --- include/etl/chrono.h | 9 +- include/etl/gcd.h | 16 +++ include/etl/lcm.h | 10 ++ include/etl/private/chrono/duration.h | 10 +- include/etl/ratio.h | 124 ++++++++++------------- test/test_ratio.cpp | 136 ++++++++++++++++++++++++-- test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 3 + 8 files changed, 219 insertions(+), 90 deletions(-) diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 8972d49ef..51fd1fd8e 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -34,6 +34,10 @@ SOFTWARE. #define ETL_IN_CHRONO_H #include "platform.h" + +#if ETL_NOT_USING_CPP11 + #error NOT SUPPORTED FOR C++03 OR BELOW +#else #include "hash.h" #include @@ -45,8 +49,9 @@ SOFTWARE. #include "private/chrono/weekday_indexed.h" #include "private/chrono/weekday_last.h" #include "private/chrono/month.h" -#include "private/chrono/year.h" - +#include "private/chrono/year.h" +#endif + #undef ETL_IN_CHRONO_H #endif diff --git a/include/etl/gcd.h b/include/etl/gcd.h index aea495e53..77df935c7 100644 --- a/include/etl/gcd.h +++ b/include/etl/gcd.h @@ -37,6 +37,22 @@ SOFTWARE. namespace etl { + //*************************************************************************** + // Greatest Common Divisor. + // Compile time. + //*************************************************************************** + template + struct gcd_const + { + static ETL_CONSTANT intmax_t value = gcd_const::value; + }; + + template + struct gcd_const + { + static ETL_CONSTANT intmax_t value = A; + }; + //*************************************************************************** // Greatest Common Divisor. // For unsigned types. diff --git a/include/etl/lcm.h b/include/etl/lcm.h index 43bb00215..575ff576c 100644 --- a/include/etl/lcm.h +++ b/include/etl/lcm.h @@ -38,6 +38,16 @@ SOFTWARE. namespace etl { + //*************************************************************************** + // Least Common Multiple. + // Compile time. + //*************************************************************************** + template + struct lcm_const + { + static ETL_CONSTANT intmax_t value = (A / gcd_const::value) * B; + }; + //*************************************************************************** // Least Common Multiple. // For unsigned types. diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 9cc58ea9c..6d4a53340 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -126,12 +126,12 @@ namespace etl } //*********************************************************************** - template ::type::den == 1, int>::type = 0> + template ::den == 1, int>::type = 0> ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT : value(etl::chrono::duration_cast >(other).count()) { - bool b = etl::ratio_divide::type::den == 1; + bool b = etl::ratio_divide::den == 1; ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); } @@ -139,10 +139,10 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 - typename etl::enable_if::type::den == 1, etl::chrono::duration&>::type + typename etl::enable_if::den == 1, etl::chrono::duration&>::type operator =(const etl::chrono::duration& other) ETL_NOEXCEPT { - bool b = etl::ratio_divide::type::den == 1; + bool b = etl::ratio_divide::den == 1; value = etl::chrono::duration_cast >(other).count(); @@ -223,7 +223,7 @@ namespace etl typedef typename TToDuration::rep to_rep; typedef typename TToDuration::period to_period; - typedef typename etl::ratio_divide::type ratio_divide_t; + typedef typename etl::ratio_divide ratio_divide_t; typedef typename etl::common_type::type common_t; common_t ct_count = static_cast(d.count()); diff --git a/include/etl/ratio.h b/include/etl/ratio.h index 77a89093d..f2bc38e9c 100644 --- a/include/etl/ratio.h +++ b/include/etl/ratio.h @@ -33,6 +33,7 @@ SOFTWARE. #include "platform.h" #include "static_assert.h" +#include "gcd.h" #include #include @@ -42,29 +43,6 @@ SOFTWARE. namespace etl { - namespace private_ratio - { - // Helper to find the greatest common divisor - template - struct gcd - { - static ETL_CONSTANT intmax_t value = gcd::value; - }; - - template - struct gcd - { - static ETL_CONSTANT intmax_t value = A; - }; - - // Helper to find the least common multiple - template - struct lcm - { - static ETL_CONSTANT intmax_t value = (A / gcd::value) * B; - }; - } - //*********************************************************************** /// ratio //*********************************************************************** @@ -74,8 +52,8 @@ namespace etl ETL_STATIC_ASSERT(Num != 0, "Numerator cannot be zero"); ETL_STATIC_ASSERT(Den != 0, "Denominator cannot be zero"); - static ETL_CONSTANT intmax_t num = Num / private_ratio::gcd::value; - static ETL_CONSTANT intmax_t den = Den / private_ratio::gcd::value; + static ETL_CONSTANT intmax_t num = Num / etl::gcd_const::value; + static ETL_CONSTANT intmax_t den = Den / etl::gcd_const::value; typedef etl::ratio type; }; @@ -86,80 +64,78 @@ namespace etl template ETL_CONSTANT intmax_t ratio::den; +#if ETL_USING_CPP11 //*********************************************************************** - /// ratio_divide + /// ratio_add //*********************************************************************** template - struct ratio_divide - { - private: + using ratio_add = etl::ratio<(TRatio1::num * TRatio2::den) + (TRatio2::num * TRatio1::den), TRatio1::den * TRatio2::den>; - static ETL_CONSTANT intmax_t N = TRatio1::num * TRatio2::den; - static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::num; + //*********************************************************************** + /// ratio_subtract + //*********************************************************************** + template + using ratio_subtract = etl::ratio<(TRatio1::num * TRatio2::den) - (TRatio2::num * TRatio1::den), TRatio1::den * TRatio2::den>; - static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; - static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + //*********************************************************************** + /// ratio_multiply + //*********************************************************************** + template + using ratio_multiply = etl::ratio; - public: + //*********************************************************************** + /// ratio_divide + //*********************************************************************** + template + using ratio_divide = etl::ratio; +#endif - typedef etl::ratio type; + //*********************************************************************** + /// ratio_equal + //*********************************************************************** + template + struct ratio_equal : etl::bool_constant<(TRatio1::num == TRatio2::num) && (TRatio1::den == TRatio2::den)> + { }; //*********************************************************************** - /// ratio_multiply + /// ratio_not_equal //*********************************************************************** template - struct ratio_multiply + struct ratio_not_equal : etl::bool_constant::value> { - private: - - static ETL_CONSTANT intmax_t N = TRatio1::num * TRatio2::num; - static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den; - - static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; - static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; - - public: - - typedef etl::ratio type; }; //*********************************************************************** - /// ratio_add + /// ratio_less //*********************************************************************** template - struct ratio_add + struct ratio_less : etl::bool_constant<(TRatio1::num * TRatio2::den) < (TRatio2::num * TRatio1::den)> { - private: - - static ETL_CONSTANT intmax_t N = (TRatio1::num * TRatio2::den) + (TRatio2::num * TRatio1::den); - static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den;; - - static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; - static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; - - public: - - typedef etl::ratio type; }; //*********************************************************************** - /// ratio_subtract + /// ratio_less_equal //*********************************************************************** template - struct ratio_subtract + struct ratio_less_equal : etl::bool_constant::value> { - private: - - static ETL_CONSTANT intmax_t N = (TRatio1::num * TRatio2::den) - (TRatio2::num * TRatio1::den); - static ETL_CONSTANT intmax_t D = TRatio1::den * TRatio2::den;; - - static ETL_CONSTANT intmax_t Num = N / private_ratio::gcd::value; - static ETL_CONSTANT intmax_t Den = D / private_ratio::gcd::value; + }; - public: + //*********************************************************************** + /// ratio_greater + //*********************************************************************** + template + struct ratio_greater : etl::bool_constant::value> + { + }; - typedef etl::ratio type; + //*********************************************************************** + /// ratio_greater_equal + //*********************************************************************** + template + struct ratio_greater_equal : etl::bool_constant::value> + { }; //*********************************************************************** @@ -196,7 +172,7 @@ namespace etl typedef ratio<1000000000000000000, 1> exa; #endif - /// An approximation of PI to 6 digits. + /// An approximation of Pi. typedef ratio<355, 113> ratio_pi; /// An approximation of root 2. @@ -206,7 +182,7 @@ namespace etl typedef ratio<169, 239> ratio_1_over_root2; /// An approximation of e. - typedef ratio<326, 120> ratio_e; + typedef ratio<106, 39> ratio_e; } #endif diff --git a/test/test_ratio.cpp b/test/test_ratio.cpp index 7f061d49e..fc7d5f065 100644 --- a/test/test_ratio.cpp +++ b/test/test_ratio.cpp @@ -47,17 +47,10 @@ namespace static ETL_CONSTANT intmax_t value = A; }; - // Helper to find the least common multiple - template - struct lcm - { - static ETL_CONSTANT intmax_t value = (A / gcd::value) * B; - }; - SUITE(test_ratio) { //************************************************************************* - TEST(test_constructor) + TEST(test_definitions) { constexpr intmax_t Num = 20; constexpr intmax_t Den = 600; @@ -77,6 +70,120 @@ namespace CHECK_EQUAL(D, ratio_type::den); } + //************************************************************************* + TEST(test_ratio_add) + { + using two_thirds = etl::ratio<2, 3>; + using one_sixth = etl::ratio<1, 6>; + using ratio = etl::ratio_add; + + CHECK_TRUE((std::is_same>::value)); + CHECK_EQUAL(5, ratio::num); + CHECK_EQUAL(6, ratio::den); + } + + //************************************************************************* + TEST(test_ratio_subtract) + { + using two_thirds = etl::ratio<2, 3>; + using one_sixth = etl::ratio<1, 6>; + using ratio = etl::ratio_subtract; + + CHECK_TRUE((std::is_same>::value)); + CHECK_EQUAL(1, ratio::num); + CHECK_EQUAL(2, ratio::den); + } + + //************************************************************************* + TEST(test_ratio_multiply) + { + using two_thirds = etl::ratio<2, 3>; + using one_sixth = etl::ratio<1, 6>; + using ratio = etl::ratio_multiply; + + CHECK_TRUE((std::is_same>::value)); + CHECK_EQUAL(1, ratio::num); + CHECK_EQUAL(9, ratio::den); + } + + //************************************************************************* + TEST(test_ratio_divide) + { + using two_thirds = etl::ratio<2, 3>; + using one_sixth = etl::ratio<1, 6>; + using ratio = etl::ratio_divide; + + CHECK_TRUE((std::is_same>::value)); + CHECK_EQUAL(4, ratio::num); + CHECK_EQUAL(1, ratio::den); + } + + //************************************************************************* + TEST(test_ratio_equal) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_TRUE((etl::ratio_equal::value)); + CHECK_FALSE((etl::ratio_equal::value)); + CHECK_FALSE((etl::ratio_equal::value)); + } + + //************************************************************************* + TEST(test_ratio_not_equal) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_FALSE((etl::ratio_not_equal::value)); + CHECK_TRUE((etl::ratio_not_equal::value)); + CHECK_TRUE((etl::ratio_not_equal::value)); + } + + //************************************************************************* + TEST(test_ratio_less) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_FALSE((etl::ratio_less::value)); + CHECK_TRUE((etl::ratio_less::value)); + CHECK_FALSE((etl::ratio_less::value)); + } + + //************************************************************************* + TEST(test_ratio_less_equal) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_TRUE((etl::ratio_less_equal::value)); + CHECK_TRUE((etl::ratio_less_equal::value)); + CHECK_FALSE((etl::ratio_less_equal::value)); + } + + //************************************************************************* + TEST(test_ratio_greater) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_FALSE((etl::ratio_greater::value)); + CHECK_FALSE((etl::ratio_greater::value)); + CHECK_TRUE((etl::ratio_greater::value)); + } + + //************************************************************************* + TEST(test_ratio_greater_equal) + { + using ratio1 = etl::ratio<5, 32>; + using ratio2 = etl::ratio<3, 16>; // 6/32 + + CHECK_TRUE((etl::ratio_greater_equal::value)); + CHECK_FALSE((etl::ratio_greater_equal::value)); + CHECK_TRUE((etl::ratio_greater_equal::value)); + } + //************************************************************************* TEST(test_predefined_ratios) { @@ -126,8 +233,19 @@ namespace double expected_pi = 3.1415926535897931; double actual_pi = double(etl::ratio_pi::num) / double(etl::ratio_pi::den); - CHECK_CLOSE(expected_pi, actual_pi, 0.0000003); + + double expected_root_2 = 1.414213562373095; + double actual_root_2 = double(etl::ratio_root2::num) / double(etl::ratio_root2::den); + CHECK_CLOSE(expected_root_2, actual_root_2, 0.00002); + + double expected_1_over_root_2 = 1.0 / 1.414213562373095; + double actual_1_over_root_2 = double(etl::ratio_1_over_root2::num) / double(etl::ratio_1_over_root2::den); + CHECK_CLOSE(expected_1_over_root_2, actual_1_over_root_2, 0.000007); + + double expected_e = 2.7182818284590451; + double actual_e = double(etl::ratio_e::num) / double(etl::ratio_e::den); + CHECK_CLOSE(expected_e, actual_e, 0.0004); } }; } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 1d21befcd..1ce125eb5 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -8899,6 +8899,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index d0b889615..69327b6f1 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3443,6 +3443,9 @@ Tests\Chrono + + Tests\Misc + From a28cbddd4bafe232778f92890ac8df00ed814edb Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Feb 2025 10:02:56 +0000 Subject: [PATCH 016/216] Added etl::create_linked_list and etl::detach_linked_list to the intrusive link utilities --- include/etl/intrusive_links.h | 196 ++++++++++++++++++++ test/test_intrusive_links.cpp | 337 ++++++++++++++++++++++++++++++++++ 2 files changed, 533 insertions(+) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 577f50108..1ca2479e6 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -404,6 +404,112 @@ namespace etl } } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, current = &links), ...); + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, (*links)...); + } + else + { + return nullptr; + } + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first); + } + else + { + return ETL_NULLPTR; + } + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A bidirectional link. //*************************************************************************** @@ -829,6 +935,96 @@ namespace etl etl::link_clear_range(*start); } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + TLink* current = first; + ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } +#elif ETL_USING_CPP11 + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + next.etl_previous = &first; + + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A binary tree link. //*************************************************************************** diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 13a09c5b7..cdfa1d8c4 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include "etl/intrusive_links.h" +#include + namespace { //******************************************************* @@ -157,6 +159,166 @@ namespace CHECK_EQUAL(0, pdata->value); } + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_forward_link_get_set) { @@ -537,6 +699,181 @@ namespace data2.BLink0::unlink(); } + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_previous == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_bidirectional_link_get_set) { From 260a3f4a48c39504f21a96879ad59871e7af7e84 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:39:51 +0000 Subject: [PATCH 017/216] Added variadic constructors --- include/etl/intrusive_forward_list.h | 49 +++++++++++++++++++++++++ include/etl/intrusive_list.h | 54 ++++++++++++++++++++++++++++ test/test_intrusive_forward_list.cpp | 23 ++++++++++++ test/test_intrusive_list.cpp | 23 ++++++++++++ 4 files changed, 149 insertions(+) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 84d0aa94e..a466337f1 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -629,6 +629,20 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_forward_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->start.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + last->etl_next = &this->terminator; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_forward_list. //************************************************************************* @@ -1169,6 +1183,41 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + return &first; + } + + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + return make_linked_list(count, next, static_cast(links)...); + } +#endif + //************************************************************************* /// Get the next value. //************************************************************************* diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f5..a8da751ee 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -685,6 +685,22 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->terminal_link.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + first.etl_previous = &this->terminal_link; + last->etl_next = &this->terminal_link; + this->terminal_link.etl_previous = last; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_list. //************************************************************************* @@ -1194,6 +1210,44 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + next.etl_previous = &first; + + return make_linked_list(count, next, static_cast(links)...); + } +#endif + // Disabled. intrusive_list(const intrusive_list& other); intrusive_list& operator = (const intrusive_list& rhs); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 20c8d830c..50ac48836 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -183,6 +183,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 33aa44679..48081e355 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -196,6 +196,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { From acc0b4bb89f294fc71ca50b3980857a2845b7369 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:40:49 +0000 Subject: [PATCH 018/216] Modified create_linked_list functions to not null terminal link pointers --- include/etl/intrusive_links.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 1ca2479e6..9c0e471c0 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -945,8 +945,7 @@ namespace etl { TLink* current = &first; ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); - current->etl_next = ETL_NULLPTR; - + return current; } @@ -959,12 +958,10 @@ namespace etl { TLink* current = first; ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); - current->etl_next = ETL_NULLPTR; return current; } #elif ETL_USING_CPP11 - //*************************************************************************** /// Create a linked list from a number of bidirectional_link nodes. //*************************************************************************** From 4e4f7ddbb1a23399a3b06b7b745a1261862ee5f5 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 18:57:27 +0100 Subject: [PATCH 019/216] Cleanup (#1039) --- include/etl/bit_stream.h | 6 +++--- include/etl/intrusive_forward_list.h | 6 +----- include/etl/private/delegate_cpp03.h | 10 +++++----- include/etl/vector.h | 1 - 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/etl/bit_stream.h b/include/etl/bit_stream.h index 7c5b557ef..b58c58820 100644 --- a/include/etl/bit_stream.h +++ b/include/etl/bit_stream.h @@ -236,8 +236,8 @@ namespace etl while (nbits != 0) { unsigned char mask_width = static_cast(etl::min(nbits, bits_available_in_char)); - - typedef typename etl::make_unsigned::type chunk_t; + + typedef typename etl::make_unsigned::type chunk_t; chunk_t chunk = get_chunk(mask_width); nbits -= mask_width; @@ -529,7 +529,7 @@ namespace etl typedef char value_type; typedef value_type* iterator; - typedef const value_type* const_iterator; + typedef const value_type* const_iterator; typedef etl::span callback_parameter_type; typedef etl::delegate callback_type; diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index a466337f1..929a69d03 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -351,11 +351,7 @@ namespace etl } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 250fff6f6..382e6504f 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -66,11 +66,11 @@ namespace etl //*********************************** template struct call_if_impl - { + { etl::optional call_if(TParam param) { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + etl::optional result; if (d.is_valid()) @@ -88,8 +88,8 @@ namespace etl { bool call_if() { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + if (d.is_valid()) { d(); diff --git a/include/etl/vector.h b/include/etl/vector.h index 80994bd58..f2c1b6461 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -47,7 +47,6 @@ SOFTWARE. #include "functional.h" #include "static_assert.h" #include "placement_new.h" -#include "algorithm.h" #include "initializer_list.h" #include From 2746cf4060d5821feded821fcfc335ff978e9042 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:30:54 +0000 Subject: [PATCH 020/216] Added variadic contruction Added erase from pointer to node --- include/etl/intrusive_forward_list.h | 75 +++++++++++++++++++++---- test/test_intrusive_forward_list.cpp | 84 ++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 11 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 84d0aa94e..566c0e41f 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -338,24 +338,20 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(link_type& search_link) + link_type* is_link_in_list(const link_type* search_link) { link_type* p_link = start.etl_next; link_type* p_previous = &start; while (p_link != ETL_NULLPTR) { - if (&search_link == p_link) + if (search_link == p_link) { return p_previous; } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; @@ -366,7 +362,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; @@ -374,7 +370,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link_after(*p_previous); @@ -629,6 +625,20 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_forward_list(link_type& first, TLinks&... links) + { + this->current_size = 0; + this->start.etl_next = &first; + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); + last->etl_next = &this->terminator; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_forward_list. //************************************************************************* @@ -787,9 +797,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) + { + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -1169,6 +1187,41 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + link_type* current = &first; + ++count; + ((current->etl_next = &links, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + return &first; + } + + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + return make_linked_list(count, next, static_cast(links)...); + } +#endif + //************************************************************************* /// Get the next value. //************************************************************************* diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 20c8d830c..ca1ce4136 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -699,6 +699,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_front(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_after_range) { From 68dac39104dab737fec1ba7850455163bfca215d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:31:14 +0000 Subject: [PATCH 021/216] Added erase from pointer to node --- include/etl/intrusive_list.h | 20 ++++++--- test/test_intrusive_list.cpp | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f5..84453b2ec 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -379,13 +379,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(link_type& search_link) const + bool is_link_in_list(const link_type* search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (&search_link == p_link) + if (search_link == p_link) { return true; } @@ -400,13 +400,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link(link); @@ -843,9 +843,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 33aa44679..ab13d2bec 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -840,6 +840,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_back(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { From 6459ce7b5f3ba998165fa5ae1a3f7fa7635dcb17 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 09:43:31 +0000 Subject: [PATCH 022/216] Improved implementation of etl::is_base_of_all --- .../etl/generators/type_traits_generator.h | 16 ++++++++-------- include/etl/type_traits.h | 19 ++++++++++--------- test/test_type_traits.cpp | 2 ++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index e55d12217..bc5edbeab 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1405,19 +1405,19 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; -#endif #if ETL_USING_CPP17 template diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 327f164be..b75118edc 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1398,23 +1398,24 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; + template + inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; #endif #if ETL_USING_CPP11 diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 4316a697f..37d620cdd 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1320,9 +1320,11 @@ namespace struct D4 {}; #if ETL_USING_CPP17 + CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_FALSE(bool(etl::is_base_of_all_v)); #else + CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_FALSE(bool(etl::is_base_of_all::value)); #endif From abe765a9cfcca5b037e1a87842b45fcd75e7bc44 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 10:20:44 +0000 Subject: [PATCH 023/216] Added static assert for variadic constructor Fixed missing this-> prefix for current_size --- include/etl/intrusive_forward_list.h | 2 ++ include/etl/intrusive_list.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 566c0e41f..12e3c3d3c 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -632,6 +632,8 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + this->current_size = 0; this->start.etl_next = &first; link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 30cf7d505..49bfea05e 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -692,9 +692,11 @@ namespace etl template intrusive_list(link_type& first, TLinks&... links) { - current_size = 0; + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; this->terminal_link.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); first.etl_previous = &this->terminal_link; last->etl_next = &this->terminal_link; this->terminal_link.etl_previous = last; From 64ae22a093ce1c4df7d6d287aff6e99d41069dec Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 19:24:30 +0100 Subject: [PATCH 024/216] Intrusive forward list add remove by pointer (#1026) * Add intrusive_forward_list::remove() element by pointer * Add test --- include/etl/intrusive_forward_list.h | 23 ++++++++++++++++++++++ test/test_intrusive_forward_list.cpp | 29 ++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 12e3c3d3c..307f110b8 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -1011,6 +1011,29 @@ namespace etl } } + //************************************************************************* + // Removes the element specified by pointer. + //************************************************************************* + void remove(const_pointer element) + { + iterator i_item = begin(); + iterator i_last_item = before_begin(); + + while (i_item != end()) + { + if (&i_item == element) + { + i_item = erase_after(i_last_item); + return; + } + else + { + ++i_item; + ++i_last_item; + } + } + } + //************************************************************************* /// Removes according to a predicate. //************************************************************************* diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 84bfa1396..a7d21da8a 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -966,6 +966,35 @@ namespace CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_remove_by_pointer) + { + std::forward_list compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + auto it = data0.begin(); + for (int i = 0; i < 7; ++i) + { + it++; + } + ItemNDCNode* element = ⁢ + + compare_data.remove(ItemNDCNode("7")); + data0.remove(*element); + + bool are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); + CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); + + are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); + CHECK(are_equal); + CHECK_EQUAL(sorted_data.size(), data1.size()); + CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_remove_if) { From 12743be9e29127686f1c1c66a951700ac1ba687a Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sun, 2 Mar 2025 12:09:32 +0100 Subject: [PATCH 025/216] Add contains() and contains_node() to etl::intrusive_forward_list and etl::intrusive_list (#1036) Co-authored-by: John Wellbelove --- include/etl/intrusive_forward_list.h | 42 ++++++++++++++++ include/etl/intrusive_list.h | 44 ++++++++++++++++- test/test_intrusive_forward_list.cpp | 72 ++++++++++++++++++++++++++++ test/test_intrusive_list.cpp | 72 ++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 1 deletion(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 307f110b8..238aca102 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -253,6 +253,27 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type& search_link) const + { + const link_type* p_link = start.etl_next; + + while (p_link != ETL_NULLPTR) + { + if (&search_link == p_link) + { + return true; + } + + p_link = p_link->link_type::etl_next; + } + + return false; + } + protected: link_type start; ///< The link pointer that acts as the intrusive_forward_list start. @@ -1210,6 +1231,27 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: #if ETL_USING_CPP17 diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 49bfea05e..673852c12 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -255,6 +255,27 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(link_type& search_link) const + { + link_type* p_link = terminal_link.link_type::etl_next; + + while (p_link != &terminal_link) + { + if (&search_link == p_link) + { + return true; + } + + p_link = p_link->link_type::etl_next; + } + + return false; + } + protected: /// The link that acts as the intrusive_list start & end. @@ -404,7 +425,7 @@ namespace etl { link_type* result = ETL_NULLPTR; - if (is_link_in_list(link)) + if (contains_node(link)) { link_type* p_next = link->etl_next; @@ -1218,6 +1239,27 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: #if ETL_USING_CPP17 diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index a7d21da8a..d39ca7dc5 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -1302,5 +1302,77 @@ namespace CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 8006af29d..9d5a08db4 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -1519,5 +1519,77 @@ namespace CHECK_EQUAL(data0.size(), compare0.size()); CHECK_EQUAL(data1.size(), compare1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } From 5327b5584bdfe7d1319603b0e720a3760299e5aa Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Feb 2025 10:02:56 +0000 Subject: [PATCH 026/216] Added etl::create_linked_list and etl::detach_linked_list to the intrusive link utilities --- include/etl/intrusive_links.h | 196 ++++++++++++++++++++ test/test_intrusive_links.cpp | 337 ++++++++++++++++++++++++++++++++++ 2 files changed, 533 insertions(+) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 577f50108..1ca2479e6 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -404,6 +404,112 @@ namespace etl } } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, current = &links), ...); + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, (*links)...); + } + else + { + return nullptr; + } + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first); + } + else + { + return ETL_NULLPTR; + } + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A bidirectional link. //*************************************************************************** @@ -829,6 +935,96 @@ namespace etl etl::link_clear_range(*start); } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + TLink* current = first; + ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } +#elif ETL_USING_CPP11 + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + next.etl_previous = &first; + + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A binary tree link. //*************************************************************************** diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 13a09c5b7..cdfa1d8c4 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include "etl/intrusive_links.h" +#include + namespace { //******************************************************* @@ -157,6 +159,166 @@ namespace CHECK_EQUAL(0, pdata->value); } + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_forward_link_get_set) { @@ -537,6 +699,181 @@ namespace data2.BLink0::unlink(); } + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_previous == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_bidirectional_link_get_set) { From 5d6771f6077d0f88125345ddded1427827167b15 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:39:51 +0000 Subject: [PATCH 027/216] Added variadic constructors --- include/etl/intrusive_forward_list.h | 49 +++++++++++++++++++++++++ include/etl/intrusive_list.h | 54 ++++++++++++++++++++++++++++ test/test_intrusive_forward_list.cpp | 23 ++++++++++++ test/test_intrusive_list.cpp | 23 ++++++++++++ 4 files changed, 149 insertions(+) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index d1a024fcf..79d156b37 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -629,6 +629,20 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_forward_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->start.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + last->etl_next = &this->terminator; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_forward_list. //************************************************************************* @@ -1192,6 +1206,41 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + return &first; + } + + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + return make_linked_list(count, next, static_cast(links)...); + } +#endif + //************************************************************************* /// Get the next value. //************************************************************************* diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f5..a8da751ee 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -685,6 +685,22 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->terminal_link.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + first.etl_previous = &this->terminal_link; + last->etl_next = &this->terminal_link; + this->terminal_link.etl_previous = last; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_list. //************************************************************************* @@ -1194,6 +1210,44 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + next.etl_previous = &first; + + return make_linked_list(count, next, static_cast(links)...); + } +#endif + // Disabled. intrusive_list(const intrusive_list& other); intrusive_list& operator = (const intrusive_list& rhs); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 8134f921c..b9e223672 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -183,6 +183,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 33aa44679..48081e355 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -196,6 +196,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { From 9ee97ec1b7d235c716c8277c25a94fe375de3580 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:40:49 +0000 Subject: [PATCH 028/216] Modified create_linked_list functions to not null terminal link pointers --- include/etl/intrusive_links.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 1ca2479e6..9c0e471c0 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -945,8 +945,7 @@ namespace etl { TLink* current = &first; ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); - current->etl_next = ETL_NULLPTR; - + return current; } @@ -959,12 +958,10 @@ namespace etl { TLink* current = first; ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); - current->etl_next = ETL_NULLPTR; return current; } #elif ETL_USING_CPP11 - //*************************************************************************** /// Create a linked list from a number of bidirectional_link nodes. //*************************************************************************** From 41a3b855e19dba0bf51e82effb5008db188f6438 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 18:57:27 +0100 Subject: [PATCH 029/216] Cleanup (#1039) --- include/etl/bit_stream.h | 6 +++--- include/etl/intrusive_forward_list.h | 6 +----- include/etl/private/delegate_cpp03.h | 10 +++++----- include/etl/vector.h | 1 - 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/etl/bit_stream.h b/include/etl/bit_stream.h index 7c5b557ef..b58c58820 100644 --- a/include/etl/bit_stream.h +++ b/include/etl/bit_stream.h @@ -236,8 +236,8 @@ namespace etl while (nbits != 0) { unsigned char mask_width = static_cast(etl::min(nbits, bits_available_in_char)); - - typedef typename etl::make_unsigned::type chunk_t; + + typedef typename etl::make_unsigned::type chunk_t; chunk_t chunk = get_chunk(mask_width); nbits -= mask_width; @@ -529,7 +529,7 @@ namespace etl typedef char value_type; typedef value_type* iterator; - typedef const value_type* const_iterator; + typedef const value_type* const_iterator; typedef etl::span callback_parameter_type; typedef etl::delegate callback_type; diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 79d156b37..1e530d87a 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -351,11 +351,7 @@ namespace etl } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 250fff6f6..382e6504f 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -66,11 +66,11 @@ namespace etl //*********************************** template struct call_if_impl - { + { etl::optional call_if(TParam param) { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + etl::optional result; if (d.is_valid()) @@ -88,8 +88,8 @@ namespace etl { bool call_if() { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + if (d.is_valid()) { d(); diff --git a/include/etl/vector.h b/include/etl/vector.h index 80994bd58..f2c1b6461 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -47,7 +47,6 @@ SOFTWARE. #include "functional.h" #include "static_assert.h" #include "placement_new.h" -#include "algorithm.h" #include "initializer_list.h" #include From 3849e349ec7e818d346ab3d52116935b922ac3a1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:30:54 +0000 Subject: [PATCH 030/216] Added variadic contruction Added erase from pointer to node --- include/etl/intrusive_forward_list.h | 30 ++++++---- test/test_intrusive_forward_list.cpp | 84 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 11 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 1e530d87a..45bdd7bfa 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -338,14 +338,14 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(link_type& search_link) + link_type* is_link_in_list(const link_type* search_link) { link_type* p_link = start.etl_next; link_type* p_previous = &start; while (p_link != ETL_NULLPTR) { - if (&search_link == p_link) + if (search_link == p_link) { return p_previous; } @@ -362,7 +362,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; @@ -370,7 +370,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link_after(*p_previous); @@ -632,9 +632,9 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { - current_size = 0; + this->current_size = 0; this->start.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); last->etl_next = &this->terminator; } #endif @@ -797,9 +797,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -1206,10 +1214,10 @@ namespace etl //*************************************************************************** /// Create a linked list from a number of forward_link nodes. //*************************************************************************** - template - TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) { - TLink* current = &first; + link_type* current = &first; ++count; ((current->etl_next = &links, current = &links, ++count), ...); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index b9e223672..a7d21da8a 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -722,6 +722,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_front(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_after_range) { From fc4c74721c1ca49a90d85ed205512bf6a6bf564a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:31:14 +0000 Subject: [PATCH 031/216] Added erase from pointer to node --- include/etl/intrusive_list.h | 20 ++++++--- test/test_intrusive_list.cpp | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index a8da751ee..30cf7d505 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -379,13 +379,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(link_type& search_link) const + bool is_link_in_list(const link_type* search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (&search_link == p_link) + if (search_link == p_link) { return true; } @@ -400,13 +400,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link(link); @@ -859,9 +859,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 48081e355..8006af29d 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -863,6 +863,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_back(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { From 24b241e10aaa50c362172148dc39921cc105a03d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 09:43:31 +0000 Subject: [PATCH 032/216] Improved implementation of etl::is_base_of_all --- .../etl/generators/type_traits_generator.h | 16 ++++++++-------- include/etl/type_traits.h | 19 ++++++++++--------- test/test_type_traits.cpp | 2 ++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index e55d12217..bc5edbeab 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1405,19 +1405,19 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; -#endif #if ETL_USING_CPP17 template diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 327f164be..b75118edc 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1398,23 +1398,24 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; + template + inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; #endif #if ETL_USING_CPP11 diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 4316a697f..37d620cdd 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1320,9 +1320,11 @@ namespace struct D4 {}; #if ETL_USING_CPP17 + CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_FALSE(bool(etl::is_base_of_all_v)); #else + CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_FALSE(bool(etl::is_base_of_all::value)); #endif From ec08fe48dfe5656c85d756d2854fa98c99cf5f4e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 10:20:44 +0000 Subject: [PATCH 033/216] Added static assert for variadic constructor Fixed missing this-> prefix for current_size --- include/etl/intrusive_forward_list.h | 2 ++ include/etl/intrusive_list.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 45bdd7bfa..307f110b8 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -632,6 +632,8 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + this->current_size = 0; this->start.etl_next = &first; link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 30cf7d505..49bfea05e 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -692,9 +692,11 @@ namespace etl template intrusive_list(link_type& first, TLinks&... links) { - current_size = 0; + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; this->terminal_link.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); first.etl_previous = &this->terminal_link; last->etl_next = &this->terminal_link; this->terminal_link.etl_previous = last; From 6124367f2872be5597c08e6cfebc9122e8189abe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 12:51:17 +0000 Subject: [PATCH 034/216] Integration of contains and contains_node --- include/etl/intrusive_forward_list.h | 25 +++++++++++-------------- include/etl/intrusive_list.h | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 238aca102..6cb442806 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -259,19 +259,16 @@ namespace etl //************************************************************************* bool contains_node(const link_type& search_link) const { - const link_type* p_link = start.etl_next; - - while (p_link != ETL_NULLPTR) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } + return is_link_in_list(&search_link); + } - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link); } protected: @@ -359,10 +356,10 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(const link_type* search_link) + link_type* is_link_in_list(const link_type* search_link) const { link_type* p_link = start.etl_next; - link_type* p_previous = &start; + link_type* p_previous = const_cast(&start); while (p_link != ETL_NULLPTR) { diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 673852c12..563fadfa8 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -259,21 +259,18 @@ namespace etl /// Detects existence of specified node in list. ///\param search_link The node to find in list //************************************************************************* - bool contains_node(link_type& search_link) const + bool contains_node(const link_type& search_link) const { - link_type* p_link = terminal_link.link_type::etl_next; - - while (p_link != &terminal_link) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } + return is_link_in_list(&search_link);; + } - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link);; } protected: @@ -425,7 +422,7 @@ namespace etl { link_type* result = ETL_NULLPTR; - if (contains_node(link)) + if (is_link_in_list(link)) { link_type* p_next = link->etl_next; From d5bea3a1f114c5babf3198cda9c84329d76a6a7c Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Mon, 3 Mar 2025 09:52:12 +0100 Subject: [PATCH 035/216] etl::span: Add advance(), copy(), reinterpret_as() (#1024) * etl::span: Add advance(), copy(), reinterpret_as() * Added further tests for span::reinterpret_as * Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef. --- include/etl/file_error_numbers.h | 2 + include/etl/span.h | 93 ++++++++++++++++++++++ include/etl/unaligned_type.h | 36 +++++---- test/test_span_dynamic_extent.cpp | 126 ++++++++++++++++++++++++++++++ test/test_span_fixed_extent.cpp | 70 +++++++++++++++++ test/test_unaligned_type.cpp | 20 +++++ 6 files changed, 330 insertions(+), 17 deletions(-) diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 64d94d573..2369f68cf 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -105,4 +105,6 @@ SOFTWARE. #define ETL_BASE64_FILE_ID "72" #define ETL_SINGLETON_BASE_FILE_ID "73" #define ETL_UNALIGNED_TYPE_FILE_ID "74" +#define ETL_SPAN_FILE_ID "75" + #endif diff --git a/include/etl/span.h b/include/etl/span.h index 8d03e5fba..7e4ad35ad 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -32,6 +32,10 @@ SOFTWARE. #define ETL_SPAN_INCLUDED #include "platform.h" + +#include "error_handler.h" +#include "exception.h" +#include "alignment.h" #include "iterator.h" #include "algorithm.h" #include "circular_iterator.h" @@ -55,6 +59,34 @@ SOFTWARE. namespace etl { + //*************************************************************************** + ///\ingroup span + /// Exception base for span + //*************************************************************************** + class span_exception : public exception + { + public: + + span_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup span + /// Bad alignment exception. + //*************************************************************************** + class span_alignment_exception : public span_exception + { + public: + + span_alignment_exception(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:alignment", ETL_SPAN_FILE_ID"A"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** @@ -426,6 +458,18 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + Extent * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -812,6 +856,28 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -884,6 +950,33 @@ namespace etl etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } + //************************************************************************* + /// Copy complete element data from one span to another. If the destination + /// span is bigger than the source span, only the initial part of + /// destination span is overwritten. + ///\param src Source + ///\param dst Destination + ///\return true, if copy was successful (including empty source span, or + /// spans pointing to the same address) + ///\return false, if the destination span is shorter than the source span. + //************************************************************************* + template + typename etl::enable_if::type, typename etl::remove_cv::type>::value && + !etl::is_const::value, bool>::type + copy(const etl::span& src, const etl::span& dst) + { + if (src.empty() || (src.begin() == dst.begin())) + { + return true; + } + if (src.size() > dst.size()) + { + return false; + } + (void) etl::copy(src.begin(), src.end(), dst.begin()); + return true; + } + //************************************************************************* /// Template deduction guides. //************************************************************************* diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 8910f864d..87519dbff 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -449,7 +449,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -457,6 +456,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; @@ -480,7 +481,7 @@ namespace etl //************************************************************************* unaligned_type(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -506,7 +507,7 @@ namespace etl //************************************************************************* unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); } //************************************************************************* @@ -515,7 +516,7 @@ namespace etl template unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } //************************************************************************* @@ -523,7 +524,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -533,7 +534,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage); return *this; } @@ -544,7 +545,7 @@ namespace etl template unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -556,7 +557,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -568,7 +569,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -589,7 +590,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -600,6 +600,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage_ext::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage_ext::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage_ext::const_pointer const_pointer; @@ -625,7 +627,7 @@ namespace etl unaligned_type_ext(T value, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -635,7 +637,7 @@ namespace etl unaligned_type_ext(const unaligned_type_ext& other, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } #if ETL_USING_CPP11 @@ -670,7 +672,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -680,7 +682,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); return *this; } @@ -691,7 +693,7 @@ namespace etl template unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -735,7 +737,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -747,7 +749,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index dd71bae22..ee85f843b 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1244,6 +1245,131 @@ namespace } } + //************************************************************************* + TEST(test_advance) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + } + { + const uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(100); + CHECK_EQUAL(data0.size(), 0); + } + } + + //************************************************************************* + TEST(test_reinterpret_as) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + { + uint32_t data[] = { 0x01020304 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(3); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 0); + } + { + uint32_t data[] = { 0x01020304, 0x06070809 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(6); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 1); + + auto it = data2.begin(); + CHECK_NOT_EQUAL(it, data2.end()); + ++it; + CHECK_EQUAL(it, data2.end()); + } + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), false); + + data0 = data0.subspan(0, 0); + + CHECK_EQUAL(etl::copy(data0, data1), true); + + data0 = src; + data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 640126eea..1440fde70 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1166,6 +1167,75 @@ namespace } } + //************************************************************************* + TEST(test_reinterpret_as) + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + { + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + { + etl::span data0 = src; + etl::span data1(&dst[1], 5); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + + { + etl::span data0 = src; + etl::span data1(&dst[2], 4); + + CHECK_EQUAL(etl::copy(data0, data1), false); + } + { + etl::span data0(&src[0], 0); + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + { + etl::span data0 = src; + etl::span data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_unaligned_type.cpp b/test/test_unaligned_type.cpp index be9ea1ec8..e80eeaebe 100644 --- a/test/test_unaligned_type.cpp +++ b/test/test_unaligned_type.cpp @@ -208,6 +208,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::le_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::le_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::le_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::le_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::le_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::le_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::le_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::le_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::le_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::le_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::le_uint64_t)); } //************************************************************************* @@ -236,6 +246,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::be_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::be_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::be_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::be_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::be_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::be_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::be_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::be_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::be_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::be_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::be_uint64_t)); } //************************************************************************* From 071a983cba660e12d6fe62e4f9f08966d60ed08f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Mar 2025 10:03:42 +0000 Subject: [PATCH 036/216] Added ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE macro and has_atomic_always_lock_free trait Fixed coditional unit tests in test_atomic --- include/etl/platform.h | 10 ++++++++++ test/test_atomic.cpp | 42 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index 5f92528eb..6738b4991 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -434,6 +434,15 @@ SOFTWARE. #else #define ETL_HAS_ATOMIC 0 #endif + #if ((ETL_USING_CPP17 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) || \ + defined(ETL_COMPILER_ARM5) || \ + defined(ETL_COMPILER_ARM6) || \ + defined(ETL_COMPILER_GCC) || \ + defined(ETL_COMPILER_CLANG)) + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 1 + #else + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0 + #endif #endif //************************************* @@ -524,6 +533,7 @@ namespace etl static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1); static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1); static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1); + static ETL_CONSTANT bool has_atomic_always_lock_free = (ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE == 1); static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1); static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1); static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1); diff --git a/test/test_atomic.cpp b/test/test_atomic.cpp index 572a9b47d..281b76508 100644 --- a/test/test_atomic.cpp +++ b/test/test_atomic.cpp @@ -76,10 +76,10 @@ namespace CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); -//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_TRUE(test.is_always_lock_free); -//#endif +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(test.is_always_lock_free); +#endif } //************************************************************************* @@ -90,28 +90,28 @@ namespace CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); -#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE CHECK_TRUE(etl::atomic::is_always_lock_free); CHECK_TRUE(test.is_always_lock_free); #endif } -//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC -// //************************************************************************* -// TEST(test_atomic_is_always_lock_free) -// { -// struct S -// { -// int a; -// int b; -// int c; -// }; -// -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_FALSE(etl::atomic::is_always_lock_free); -// } -//#endif +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + //************************************************************************* + TEST(test_atomic_is_always_lock_free) + { + struct S + { + int a; + int b; + int c; + }; + + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_FALSE(etl::atomic::is_always_lock_free); + } +#endif //************************************************************************* TEST(test_atomic_integer_load) From fc638a92a69abe34303c5715d6b865f06e5ddc7b Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Mon, 3 Mar 2025 09:52:12 +0100 Subject: [PATCH 037/216] etl::span: Add advance(), copy(), reinterpret_as() (#1024) * etl::span: Add advance(), copy(), reinterpret_as() * Added further tests for span::reinterpret_as * Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef. --- include/etl/file_error_numbers.h | 2 + include/etl/span.h | 93 ++++++++++++++++++++++ include/etl/unaligned_type.h | 36 +++++---- test/test_span_dynamic_extent.cpp | 126 ++++++++++++++++++++++++++++++ test/test_span_fixed_extent.cpp | 70 +++++++++++++++++ test/test_unaligned_type.cpp | 20 +++++ 6 files changed, 330 insertions(+), 17 deletions(-) diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 64d94d573..2369f68cf 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -105,4 +105,6 @@ SOFTWARE. #define ETL_BASE64_FILE_ID "72" #define ETL_SINGLETON_BASE_FILE_ID "73" #define ETL_UNALIGNED_TYPE_FILE_ID "74" +#define ETL_SPAN_FILE_ID "75" + #endif diff --git a/include/etl/span.h b/include/etl/span.h index 8d03e5fba..7e4ad35ad 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -32,6 +32,10 @@ SOFTWARE. #define ETL_SPAN_INCLUDED #include "platform.h" + +#include "error_handler.h" +#include "exception.h" +#include "alignment.h" #include "iterator.h" #include "algorithm.h" #include "circular_iterator.h" @@ -55,6 +59,34 @@ SOFTWARE. namespace etl { + //*************************************************************************** + ///\ingroup span + /// Exception base for span + //*************************************************************************** + class span_exception : public exception + { + public: + + span_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup span + /// Bad alignment exception. + //*************************************************************************** + class span_alignment_exception : public span_exception + { + public: + + span_alignment_exception(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:alignment", ETL_SPAN_FILE_ID"A"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** @@ -426,6 +458,18 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + Extent * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -812,6 +856,28 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -884,6 +950,33 @@ namespace etl etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } + //************************************************************************* + /// Copy complete element data from one span to another. If the destination + /// span is bigger than the source span, only the initial part of + /// destination span is overwritten. + ///\param src Source + ///\param dst Destination + ///\return true, if copy was successful (including empty source span, or + /// spans pointing to the same address) + ///\return false, if the destination span is shorter than the source span. + //************************************************************************* + template + typename etl::enable_if::type, typename etl::remove_cv::type>::value && + !etl::is_const::value, bool>::type + copy(const etl::span& src, const etl::span& dst) + { + if (src.empty() || (src.begin() == dst.begin())) + { + return true; + } + if (src.size() > dst.size()) + { + return false; + } + (void) etl::copy(src.begin(), src.end(), dst.begin()); + return true; + } + //************************************************************************* /// Template deduction guides. //************************************************************************* diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 8910f864d..87519dbff 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -449,7 +449,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -457,6 +456,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; @@ -480,7 +481,7 @@ namespace etl //************************************************************************* unaligned_type(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -506,7 +507,7 @@ namespace etl //************************************************************************* unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); } //************************************************************************* @@ -515,7 +516,7 @@ namespace etl template unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } //************************************************************************* @@ -523,7 +524,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -533,7 +534,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage); return *this; } @@ -544,7 +545,7 @@ namespace etl template unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -556,7 +557,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -568,7 +569,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -589,7 +590,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -600,6 +600,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage_ext::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage_ext::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage_ext::const_pointer const_pointer; @@ -625,7 +627,7 @@ namespace etl unaligned_type_ext(T value, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -635,7 +637,7 @@ namespace etl unaligned_type_ext(const unaligned_type_ext& other, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } #if ETL_USING_CPP11 @@ -670,7 +672,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -680,7 +682,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); return *this; } @@ -691,7 +693,7 @@ namespace etl template unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -735,7 +737,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -747,7 +749,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index dd71bae22..ee85f843b 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1244,6 +1245,131 @@ namespace } } + //************************************************************************* + TEST(test_advance) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + } + { + const uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(100); + CHECK_EQUAL(data0.size(), 0); + } + } + + //************************************************************************* + TEST(test_reinterpret_as) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + { + uint32_t data[] = { 0x01020304 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(3); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 0); + } + { + uint32_t data[] = { 0x01020304, 0x06070809 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(6); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 1); + + auto it = data2.begin(); + CHECK_NOT_EQUAL(it, data2.end()); + ++it; + CHECK_EQUAL(it, data2.end()); + } + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), false); + + data0 = data0.subspan(0, 0); + + CHECK_EQUAL(etl::copy(data0, data1), true); + + data0 = src; + data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 640126eea..1440fde70 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1166,6 +1167,75 @@ namespace } } + //************************************************************************* + TEST(test_reinterpret_as) + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + { + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + { + etl::span data0 = src; + etl::span data1(&dst[1], 5); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + + { + etl::span data0 = src; + etl::span data1(&dst[2], 4); + + CHECK_EQUAL(etl::copy(data0, data1), false); + } + { + etl::span data0(&src[0], 0); + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + { + etl::span data0 = src; + etl::span data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_unaligned_type.cpp b/test/test_unaligned_type.cpp index be9ea1ec8..e80eeaebe 100644 --- a/test/test_unaligned_type.cpp +++ b/test/test_unaligned_type.cpp @@ -208,6 +208,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::le_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::le_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::le_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::le_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::le_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::le_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::le_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::le_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::le_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::le_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::le_uint64_t)); } //************************************************************************* @@ -236,6 +246,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::be_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::be_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::be_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::be_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::be_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::be_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::be_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::be_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::be_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::be_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::be_uint64_t)); } //************************************************************************* From 987cb4f78b905d3a3053ecb10a3fde413447389c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Mar 2025 10:57:26 +0000 Subject: [PATCH 038/216] Minor format change --- include/etl/span.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 7e4ad35ad..db88f3601 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -458,6 +458,16 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + //************************************************************************* /// Reinterpret the span as a span with different element type. //************************************************************************* @@ -467,7 +477,7 @@ namespace etl ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); return etl::span(reinterpret_cast(pbegin), - Extent * sizeof(element_type) / sizeof(TNew)); + Extent * sizeof(element_type) / sizeof(TNew)); } private: @@ -875,7 +885,7 @@ namespace etl ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); return etl::span(reinterpret_cast(pbegin), - (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); } private: From c43d9eaea1b756e7df7ae5dddf44c4b82dad913c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:26:39 +0000 Subject: [PATCH 039/216] Removed duplicated header includes --- include/etl/basic_string.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1a9f0c9b6..d7f139d56 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -38,13 +38,11 @@ SOFTWARE. #include "char_traits.h" #include "alignment.h" #include "array.h" -#include "algorithm.h" #include "type_traits.h" #include "error_handler.h" #include "integral_limits.h" #include "exception.h" #include "memory.h" -#include "exception.h" #include "binary.h" #include "flags.h" From ceeb2e706ebdd0f53d98457f03df6a44403e3c17 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:27:07 +0000 Subject: [PATCH 040/216] Updated bash test script help --- test/run-tests.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index 34af8d07f..fbd015195 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -54,14 +54,14 @@ PrintHeader() PrintHelp() { echo "$HelpColour" - echo "-------------------------------------------------------------------------------------" - echo " Syntax : ./runtests.sh " - echo " C++ Standard : 11, 14, 17 or 20 " - echo " Optimisation : 0, 1, 2 or 3. Default = 0 " - echo " Threads : Number of threads to use. Default = 4 " - echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " - echo " Compiler select : gcc or clang. Default All compilers " - echo "-------------------------------------------------------------------------------------" + echo "--------------------------------------------------------------------------------------------" + echo " Syntax : ./runtests.sh " + echo " C++ Standard : 11, 14, 17 or 20 " + echo " Optimisation : 0, 1, 2 or 3. Default = 0 " + echo " Threads : Number of threads to use. Default = 4 " + echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " + echo " Compiler : gcc or clang. Default All compilers " + echo "--------------------------------------------------------------------------------------------" echo "$NoColour" } From c19a3fe085d26275c6c2f0caad776a2ea2e66807 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:27:39 +0000 Subject: [PATCH 041/216] Added unit tests for initializer_list construction --- test/test_intrusive_forward_list.cpp | 13 +++++++++++++ test/test_intrusive_list.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index d39ca7dc5..9e8544861 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -206,6 +206,19 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 9d5a08db4..45de60034 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -219,6 +219,19 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { From 2b27c28861a9e08261dfc3660e7ea5933f7c7a5e Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Tue, 4 Mar 2025 04:44:13 -0500 Subject: [PATCH 042/216] Implement << operator for std basic_ostream and etl string_view (#1040) * Implement << operator for std basic_ostream and etl string_view * Implement << operator for std basic_ostream and etl ibasic_string. Still working through tests * Should be all tests * Fix comment --- include/etl/basic_string.h | 21 ++++++++++++ include/etl/string_view.h | 17 ++++++++++ test/test_string_char.cpp | 18 ++++++++++ test/test_string_char_external_buffer.cpp | 19 +++++++++++ test/test_string_u16.cpp | 18 ++++++++++ test/test_string_u16_external_buffer.cpp | 19 +++++++++++ test/test_string_u32.cpp | 18 ++++++++++ test/test_string_u32_external_buffer.cpp | 19 +++++++++++ test/test_string_u8.cpp | 18 ++++++++++ test/test_string_u8_external_buffer.cpp | 19 +++++++++++ test/test_string_view.cpp | 35 ++++++++++++++++++++ test/test_string_wchar_t.cpp | 18 ++++++++++ test/test_string_wchar_t_external_buffer.cpp | 19 +++++++++++ 13 files changed, 258 insertions(+) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1a9f0c9b6..b9cf24f78 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -56,6 +56,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include "private/minmax_push.h" //***************************************************************************** @@ -2964,6 +2968,23 @@ namespace etl { return !(lhs < rhs); } + + //*************************************************************************** + /// Operator overload to write to std basic_ostream + ///\param os Reference to the output stream. + ///\param str Reference to the string to write. + ///\return Reference to the output stream, for chaining write operations. + ///\ingroup string + //*************************************************************************** +#if ETL_USING_STL + template + std::basic_ostream > &operator<<(std::basic_ostream > &os, + const etl::ibasic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif } #include "private/minmax_pop.h" diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 82bd4502b..69cbe8366 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -47,6 +47,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include namespace etl @@ -972,6 +976,19 @@ void swap(etl::basic_string_view >& lhs, etl::basic_strin lhs.swap(rhs); } +//************************************************************************* +/// Operator overload to write to std basic_ostream +//************************************************************************* +#if ETL_USING_STL +template +std::basic_ostream > &operator<<(std::basic_ostream > &os, + etl::basic_string_view > text) +{ + os.write(text.data(), text.size()); + return os; +} +#endif + #include "private/minmax_pop.h" #endif diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 9a4f463ca..55e1bdb37 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -5310,5 +5310,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 1234e1703..a2593660b 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -5689,5 +5689,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index d2cb002b8..01ee5cf88 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index b7a2bfec1..ab7223e74 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 4c19a57d6..4f4c6cb0d 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 5e8087267..1187091fe 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 4f792225a..e105ed197 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -5327,6 +5327,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index df2724e56..1494e7084 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -5706,6 +5706,25 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index afa1e6d33..598f63325 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -1120,5 +1120,40 @@ namespace CHECK_TRUE((u16view == U16View{ u"Hello World", etl::strlen(u"Hello World") })); CHECK_TRUE((u32view == U32View{ U"Hello World", etl::strlen(U"Hello World") })); } + + //************************************************************************* +#if ETL_USING_STL + TEST(write_to_std_stream) + { + View view{ "Hello World" }; + WView wview{ L"Hello World" }; + U16View u16view{ u"Hello World" }; + U32View u32view{ U"Hello World" }; + + std::stringstream sstream; + std::wstringstream wsstream; + std::basic_stringstream u16sstream; + std::basic_stringstream u32sstream; + + sstream << view; + std::string sstream_string = sstream.str(); + wsstream << wview; + std::wstring wsstream_string = wsstream.str(); + u16sstream << u16view; + std::u16string u16sstream_string = u16sstream.str(); + u32sstream << u32view; + std::u32string u32sstream_string = u32sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + WView wsstream_view(wsstream_string.data(), wsstream_string.size()); + U16View u16sstream_view(u16sstream_string.data(), u16sstream_string.size()); + U32View u32sstream_view(u32sstream_string.data(), u32sstream_string.size()); + + CHECK_TRUE(view == sstream_view); + CHECK_TRUE(wview == wsstream_view); + CHECK_TRUE(u16view == u16sstream_view); + CHECK_TRUE(u32view == u32sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 4eb16f41a..d28ba6d64 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -5325,5 +5325,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 8bbbe4963..16cc52a8d 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -5680,5 +5680,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } From d4813dff86c725072385dda9bc98cd8e4fea5151 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 9 Mar 2025 10:41:15 +0100 Subject: [PATCH 043/216] Add traits to type_list (#1044) --- include/etl/type_list.h | 91 +++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_type_list.cpp | 172 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 test/test_type_list.cpp diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 533ae7618..556787abe 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -30,7 +30,10 @@ SOFTWARE. #define ETL_TYPE_LIST_INCLUDED #include "platform.h" + +#include "algorithm.h" #include "nth_type.h" +#include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" @@ -38,6 +41,9 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { + + static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** /// Type list forward declaration. //*************************************************************************** @@ -61,6 +67,18 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; + namespace private_type_list + { + + // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition + template + struct recursion_helper + { + using type = type_list; + }; + + } + //*************************************************************************** /// Recursive type list implementation for multiple types. //*************************************************************************** @@ -68,6 +86,7 @@ namespace etl struct type_list : type_list { using type = THead; + using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -87,6 +106,7 @@ namespace etl struct type_list : type_list<> { using type = THead; + using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -180,6 +200,77 @@ namespace etl { using type = typename type_list_cat, TTail...>::type; }; + + template + struct type_list_contains + : public etl::integral_constant::value ? true : type_list_contains::value> + { + }; + + template + struct type_list_contains, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif + + template + struct type_list_index_of + : public etl::integral_constant::value ? 0 : + (type_list_index_of::value == type_list_npos ? + type_list_npos : type_list_index_of::value + 1)> + { + }; + + template + struct type_list_index_of, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; +#endif + + template + struct type_list_max_sizeof_type + : public etl::integral_constant::value)> + { + }; + + template<> + struct type_list_max_sizeof_type> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; +#endif + + template + struct type_list_max_alignment + : public etl::integral_constant::value, + type_list_max_alignment::value)> + { + }; + + template<> + struct type_list_max_alignment> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; +#endif } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bcc8a0da7..d2641ab5f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -286,6 +286,7 @@ add_executable(etl_tests test_to_u8string.cpp test_to_wstring.cpp test_type_def.cpp + test_type_list.cpp test_type_lookup.cpp test_type_select.cpp test_type_traits.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp new file mode 100644 index 000000000..44f197f8f --- /dev/null +++ b/test/test_type_list.cpp @@ -0,0 +1,172 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 BMW AG + +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 "unit_test_framework.h" + +#include "etl/type_list.h" + +#include + +namespace +{ +#if ETL_USING_CPP11 + SUITE(test_type_list) + { + //************************************************************************* + TEST(test_nth_type) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type, char>::value)); + CHECK_TRUE((std::is_same::type, int>::value)); + CHECK_TRUE((std::is_same::type, uint32_t>::value)); + } + + //************************************************************************* + TEST(test_type_list_select) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_TRUE((std::is_same::type, t2>::value)); + } + + //************************************************************************* + TEST(test_type_list_size) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_EQUAL(etl::type_list_size::value, 3); + CHECK_EQUAL(etl::type_list_size::value, 2); + } + + //************************************************************************* + TEST(test_type_list_cat) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + typedef etl::type_list t_cat1; + typedef etl::type_list t_cat2; + + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + } + + //************************************************************************* + TEST(test_type_list_contains) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_index_of) + { + typedef etl::type_list t1; + typedef etl::type_list<> t2; + + CHECK_EQUAL((etl::type_list_index_of::value), 0); + CHECK_EQUAL((etl::type_list_index_of::value), 1); + CHECK_EQUAL((etl::type_list_index_of::value), 2); + CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_index_of_v), 0); + CHECK_EQUAL((etl::type_list_index_of_v), 1); + CHECK_EQUAL((etl::type_list_index_of_v), 2); + CHECK_EQUAL((etl::type_list_index_of_v), etl::type_list_npos); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_sizeof_type) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_alignment) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, 1); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), 1); +#endif + } + + }; +#endif +} From f1d5b16d38603c9709d8541c3418ceb825d46bca Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 9 Mar 2025 10:47:24 +0000 Subject: [PATCH 044/216] Added etl::type_list_type_at_index --- include/etl/type_list.h | 46 +++++++++++++++++++++++++++------ test/test_type_list.cpp | 14 ++++++++++ test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 5 +++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 556787abe..f4607dc95 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -41,8 +41,10 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { - - static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t type_list_npos = etl::integral_limits::max; //*************************************************************************** /// Type list forward declaration. @@ -69,14 +71,12 @@ namespace etl namespace private_type_list { - // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition template struct recursion_helper { using type = type_list; }; - } //*************************************************************************** @@ -201,6 +201,9 @@ namespace etl using type = typename type_list_cat, TTail...>::type; }; + //*************************************************************************** + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. + //*************************************************************************** template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> @@ -218,17 +221,21 @@ namespace etl inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif + //*************************************************************************** + /// Defines an integral constant that is the index of the specified type in the type_list. + /// If the type is not in the type_list, then defined as etl::type_list_npos. + //*************************************************************************** template struct type_list_index_of : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == type_list_npos ? - type_list_npos : type_list_index_of::value + 1)> + (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of::value + 1)> { }; template struct type_list_index_of, T> - : public etl::integral_constant + : public etl::integral_constant { }; @@ -237,6 +244,25 @@ namespace etl inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; #endif + //*************************************************************************** + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. + //*************************************************************************** + template + struct type_list_type_at_index + { + ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); + + using type = nth_type_t; + }; + + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; + + //*************************************************************************** + /// Defines an integral constant that is maximum sizeof all types in the type_list. + /// If the type_list is empty, then defined as 0. + //*************************************************************************** template struct type_list_max_sizeof_type : public etl::integral_constant::value)> @@ -254,10 +280,14 @@ namespace etl inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif + //*************************************************************************** + /// Defines an integral constant that is maximum alignment all types in the type_list. + /// If the type_list is empty, then defined as 1. + //*************************************************************************** template struct type_list_max_alignment : public etl::integral_constant::value, - type_list_max_alignment::value)> + type_list_max_alignment::value)> { }; diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 44f197f8f..49641e6f7 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -125,6 +125,20 @@ namespace #endif } + //************************************************************************* + TEST(test_type_list_type_at_index) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + //************************************************************************* TEST(test_type_list_max_sizeof_type) { diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index dfa03400a..b796f072d 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9453,6 +9453,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 5251ef8b5..d5ff0eef6 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1429,7 +1429,7 @@ UnitTest++\Header Files - UnitTest++\Header Files + ETL\Utilities @@ -3431,6 +3431,9 @@ Tests\Syntax Checks\Source + + Tests\Types + From 53887fa105c5d9e1bb73e4c46ff1e262741dd19d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 14 Mar 2025 15:46:25 +0000 Subject: [PATCH 045/216] Renamed type_list_index_of to type_list_index_of_type --- include/etl/type_list.h | 38 +++++++++++++++++++------------------- test/test_type_list.cpp | 10 +++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index f4607dc95..21ee103c0 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -204,20 +204,20 @@ namespace etl //*************************************************************************** /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template + template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> { }; - template + template struct type_list_contains, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif @@ -225,30 +225,30 @@ namespace etl /// Defines an integral constant that is the index of the specified type in the type_list. /// If the type is not in the type_list, then defined as etl::type_list_npos. //*************************************************************************** - template - struct type_list_index_of + template + struct type_list_index_of_type : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of::value + 1)> + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> { }; - template - struct type_list_index_of, T> + template + struct type_list_index_of_type, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; #endif //*************************************************************************** /// Defines type as the type found at Index in the type_list. /// Static asserts if Index is out of range. //*************************************************************************** - template + template struct type_list_type_at_index { ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); @@ -256,27 +256,27 @@ namespace etl using type = nth_type_t; }; - template + template using type_list_type_at_index_t = typename type_list_type_at_index::type; //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template + template struct type_list_max_sizeof_type : public etl::integral_constant::value)> { }; - template<> + template <> struct type_list_max_sizeof_type> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif @@ -284,21 +284,21 @@ namespace etl /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template + template struct type_list_max_alignment : public etl::integral_constant::value, type_list_max_alignment::value)> { }; - template<> + template <> struct type_list_max_alignment> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif } diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 49641e6f7..75c8f3226 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -107,15 +107,15 @@ namespace } //************************************************************************* - TEST(test_type_list_index_of) + TEST(test_type_list_index_of_type) { typedef etl::type_list t1; typedef etl::type_list<> t2; - CHECK_EQUAL((etl::type_list_index_of::value), 0); - CHECK_EQUAL((etl::type_list_index_of::value), 1); - CHECK_EQUAL((etl::type_list_index_of::value), 2); - CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + CHECK_EQUAL((etl::type_list_index_of_type::value), 0); + CHECK_EQUAL((etl::type_list_index_of_type::value), 1); + CHECK_EQUAL((etl::type_list_index_of_type::value), 2); + CHECK_EQUAL((etl::type_list_index_of_type::value), etl::type_list_npos); #if ETL_USING_CPP17 CHECK_EQUAL((etl::type_list_index_of_v), 0); From 36b4d51bafc13dcdfbeeb23be7e12bb03a9e98d0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:06:34 +0000 Subject: [PATCH 046/216] Added etl::index_of_type as a complement to etl::nth_type --- include/etl/index_of_type.h | 80 +++++++++++++++++++++++++++++++++++++ test/test_index_of_type.cpp | 58 +++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 include/etl/index_of_type.h create mode 100644 test/test_index_of_type.cpp diff --git a/include/etl/index_of_type.h b/include/etl/index_of_type.h new file mode 100644 index 000000000..5546ad533 --- /dev/null +++ b/include/etl/index_of_type.h @@ -0,0 +1,80 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_INDEX_OF_TYPE_INCLUDED +#define ETL_INDEX_OF_TYPE_INCLUDED + +#include "platform.h" +#include "static_assert.h" +#include "integral_limits.h" + +namespace etl +{ +#if ETL_USING_CPP11 + + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t index_of_type_npos = etl::integral_limits::max; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant::value ? 0 : + (etl::index_of_type::value == etl::index_of_type_npos ? etl::index_of_type_npos : + etl::index_of_type::value + 1)> + { + }; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + /// No types left. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + inline constexpr size_t index_of_type_v = etl::index_of_type::value; +#endif +#endif +} + +#endif diff --git a/test/test_index_of_type.cpp b/test/test_index_of_type.cpp new file mode 100644 index 000000000..60d211e8a --- /dev/null +++ b/test/test_index_of_type.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include "etl/index_of_type.h" +#include + +namespace +{ + SUITE(test_index_of_type) + { + //************************************************************************* + TEST(test_index_of_type) + { + CHECK_EQUAL(0, (etl::index_of_type::value)); + CHECK_EQUAL(1, (etl::index_of_type::value)); + CHECK_EQUAL(2, (etl::index_of_type::value)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type::value)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_index_of_type_v) + { + CHECK_EQUAL(0, (etl::index_of_type_v)); + CHECK_EQUAL(1, (etl::index_of_type_v)); + CHECK_EQUAL(2, (etl::index_of_type_v)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type_v)); + } +#endif + } +} From 495ea2b9433bb24a0ed9d0d6ba74a4d1841b9e84 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:07:25 +0000 Subject: [PATCH 047/216] Attempt to fix some sanitizer issues for tests --- include/etl/intrusive_forward_list.h | 5 ++++- test/test_map.cpp | 7 ++++--- test/test_multi_span.cpp | 14 ++------------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index d1a024fcf..5ba16248e 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -304,7 +304,10 @@ namespace etl if (p_next != &this->terminator) { link_type* p_unlinked = etl::unlink_after(link); - p_unlinked->clear(); + if (p_unlinked != ETL_NULLPTR) + { + p_unlinked->clear(); + } --current_size; } } diff --git a/test/test_map.cpp b/test/test_map.cpp index bd8817ce6..2c19e4e4e 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include #include "etl/map.h" +#include "etl/string.h" #include "data.h" @@ -1575,7 +1576,7 @@ namespace #if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST_FIXTURE(SetupFixture, test_map_template_deduction) { - using Pair = std::pair; + using Pair = std::pair, int>; etl::map data { Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5} }; @@ -1596,9 +1597,9 @@ namespace #if ETL_HAS_INITIALIZER_LIST TEST_FIXTURE(SetupFixture, test_make_map) { - using Pair = ETL_OR_STD::pair; + using Pair = ETL_OR_STD::pair, int>; - auto data = etl::make_map>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); + auto data = etl::make_map, int, std::less>>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); auto v = *data.begin(); using Type = decltype(v); diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 11c77196f..c3e20a6ee 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -341,14 +341,7 @@ namespace etl::multi_span::iterator ms_itr = ms_int.begin(); etl::multi_span::iterator ms_end_itr = ms_int.end(); - while (ms_itr != ms_end_itr) - { - // Fill the multi span - *ms_itr++ = *exp_itr++; - } - - ms_itr = ms_int.begin(); - exp_itr = expected.begin(); + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { @@ -554,10 +547,7 @@ namespace multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); - while (ms_itr != ms_end_itr) - { - *ms_itr++ = *exp_itr++; - } + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { From 03ca499e5ec7cb53c525f70e77c1fe5051d848f5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:08:55 +0000 Subject: [PATCH 048/216] Refactored and simplified some features of etl::type_list Removed nth_type specialisation for etl::type_list --- include/etl/type_list.h | 198 +++++++++++++++----------------- test/CMakeLists.txt | 1 + test/test_type_list.cpp | 57 +++++---- test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 5 files changed, 129 insertions(+), 135 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 21ee103c0..4dbc66ec1 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -32,11 +32,12 @@ SOFTWARE. #include "platform.h" #include "algorithm.h" -#include "nth_type.h" +#include "index_of_type.h" #include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" +#include "largest.h" #if ETL_USING_CPP11 namespace etl @@ -85,7 +86,7 @@ namespace etl template struct type_list : type_list { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -105,7 +106,7 @@ namespace etl template struct type_list : type_list<> { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -119,50 +120,10 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list - //*************************************************************************** - template - struct nth_type> - { - ETL_STATIC_ASSERT(N <= sizeof...(TTail), "etl::nth_type out of range for etl::type_list"); - - using type = typename nth_type>::type; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list with index of 0 - //*************************************************************************** - template - struct nth_type<0, type_list> - { - using type = THead; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for empty etl::type_list - //*************************************************************************** - template - struct nth_type> - { - }; - - //*************************************************************************** - /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. - //*************************************************************************** - template - struct type_list_select - { - using type = type_list...>; - }; - - template - using type_list_select_t = typename type_list_select::type; - //*************************************************************************** /// Type list size. //*************************************************************************** - template + template struct type_list_size; template @@ -176,61 +137,38 @@ namespace etl #endif //*************************************************************************** - /// Concatenates two or more type_lists. - //*************************************************************************** - template - struct type_list_cat; - - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for a single type_list (base case) - //*************************************************************************** - template - struct type_list_cat - { - using type = TypeList; - }; - - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for two or more type_lists + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. //*************************************************************************** - template - struct type_list_cat, etl::type_list, TTail...> + template + struct type_list_type_at_index { - using type = typename type_list_cat, TTail...>::type; - }; + ETL_STATIC_ASSERT(Index < type_list_size::value, "etl::type_list_type_at_index out of range"); + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); - //*************************************************************************** - /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. - //*************************************************************************** - template - struct type_list_contains - : public etl::integral_constant::value ? true : type_list_contains::value> - { + using type = typename type_list_type_at_index::type; }; - template - struct type_list_contains, T> - : public etl::integral_constant + template + struct type_list_type_at_index { + using type = typename TTypeList::head; }; -#if ETL_USING_CPP17 - template - inline constexpr bool type_list_contains_v = etl::type_list_contains::value; -#endif + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; //*************************************************************************** /// Defines an integral constant that is the index of the specified type in the type_list. /// If the type is not in the type_list, then defined as etl::type_list_npos. //*************************************************************************** - template + template struct type_list_index_of_type - : public etl::integral_constant::value ? 0 : - (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of_type::value + 1)> + : public etl::integral_constant::value ? 0 : + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); }; template @@ -240,54 +178,67 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; #endif //*************************************************************************** - /// Defines type as the type found at Index in the type_list. - /// Static asserts if Index is out of range. + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template - struct type_list_type_at_index + template + struct type_list_contains; + + template + struct type_list_contains, T> + : public etl::integral_constant::value> { - ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); + }; - using type = nth_type_t; + template + struct type_list_contains, T> + : public etl::integral_constant + { }; - template - using type_list_type_at_index_t = typename type_list_type_at_index::type; +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template - struct type_list_max_sizeof_type - : public etl::integral_constant::value)> + template + struct type_list_max_size; + + template + struct type_list_max_size> + : public etl::integral_constant::size> { }; template <> - struct type_list_max_sizeof_type> + struct type_list_max_size> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; + template + inline constexpr size_t type_list_max_size_v = etl::type_list_max_size::value; #endif //*************************************************************************** /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template - struct type_list_max_alignment - : public etl::integral_constant::value, - type_list_max_alignment::value)> + template + struct type_list_max_alignment; + + template + struct type_list_max_alignment> + : public etl::integral_constant::alignment> { }; @@ -298,9 +249,44 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif + + //*************************************************************************** + /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. + //*************************************************************************** + template + struct type_list_select + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = type_list...>; + }; + + template + using type_list_select_t = typename type_list_select::type; + + //*************************************************************************** + /// Concatenates two or more type_lists. + //*************************************************************************** + template + struct type_list_cat; + + template + struct type_list_cat, etl::type_list, TTail...> + { + using type = typename type_list_cat, TTail...>::type; + }; + + template + struct type_list_cat + { + using type = T; + }; + + template + using type_list_cat_t = typename type_list_cat::type; } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2641ab5f..498fa7db2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,6 +149,7 @@ add_executable(etl_tests test_hfsm.cpp test_hfsm_recurse_to_inner_state_on_start.cpp test_histogram.cpp + test_index_of_type.cpp test_indirect_vector.cpp test_indirect_vector_external_buffer.cpp test_instance_count.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 75c8f3226..de9be9fc5 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -37,16 +37,6 @@ namespace #if ETL_USING_CPP11 SUITE(test_type_list) { - //************************************************************************* - TEST(test_nth_type) - { - typedef etl::type_list t1; - - CHECK_TRUE((std::is_same::type, char>::value)); - CHECK_TRUE((std::is_same::type, int>::value)); - CHECK_TRUE((std::is_same::type, uint32_t>::value)); - } - //************************************************************************* TEST(test_type_list_select) { @@ -54,6 +44,7 @@ namespace typedef etl::type_list t2; CHECK_TRUE((std::is_same::type, t2>::value)); + CHECK_TRUE((std::is_same, t2>::value)); } //************************************************************************* @@ -61,46 +52,54 @@ namespace { typedef etl::type_list t1; typedef etl::type_list t2; + typedef etl::type_list<> t3; CHECK_EQUAL(etl::type_list_size::value, 3); CHECK_EQUAL(etl::type_list_size::value, 2); + CHECK_EQUAL(etl::type_list_size::value, 0); } //************************************************************************* TEST(test_type_list_cat) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; + typedef etl::type_list<> t3; typedef etl::type_list t_cat1; - typedef etl::type_list t_cat2; + typedef etl::type_list t_cat2; - CHECK_TRUE((std::is_same::type, t_cat1>::value)); - CHECK_FALSE((std::is_same::type, t_cat2>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_FALSE((std::is_same, t_cat2>::value)); } //************************************************************************* TEST(test_type_list_contains) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); #if ETL_USING_CPP17 - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); #endif @@ -147,16 +146,16 @@ namespace typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 2); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 0); #if ETL_USING_CPP17 - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 2); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 0); #endif } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index b796f072d..808b085ac 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3169,6 +3169,7 @@ + @@ -8477,6 +8478,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index d5ff0eef6..f778794a4 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1431,6 +1431,9 @@ ETL\Utilities + + ETL\Utilities + @@ -3434,6 +3437,9 @@ Tests\Types + + Tests\Types + From 3360eae62d8a9a352c9e704453d11a6a9d56f876 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:09:41 +0000 Subject: [PATCH 049/216] Modified etl::variant_variadic to use etl::type_list in place of etl::parameter_pack --- include/etl/private/variant_variadic.h | 121 +++++-------------------- 1 file changed, 23 insertions(+), 98 deletions(-) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 443346694..6874f7f94 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -31,13 +31,14 @@ SOFTWARE. #include "../platform.h" #include "../utility.h" #include "../largest.h" +#include "../nth_type.h" #include "../exception.h" #include "../type_traits.h" #include "../integral_limits.h" #include "../static_assert.h" #include "../alignment.h" #include "../error_handler.h" -#include "../parameter_pack.h" +#include "../type_list.h" #include "../placement_new.h" #include "../visitor.h" #include "../memory.h" @@ -66,82 +67,6 @@ namespace etl { namespace private_variant { - //*************************************************************************** - // This is a copy of the normal etl::parameter_pack, but without the static_assert - // so that the C++11 versions of do_visitor() & do_operator() do not throw a compile time error. - //*************************************************************************** - template - class parameter_pack - { - public: - - static constexpr size_t size = sizeof...(TTypes); - - //*************************************************************************** - /// index_of_type - //*************************************************************************** - template - class index_of_type - { - private: - - using type = etl::remove_cvref_t; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_type_helper::value; - }; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = 1UL; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in parameter pack"); - - /// The index value. - static constexpr size_t value = index_of_type_helper::value - 1; - }; - - //*************************************************************************** - /// type_from_index - //*************************************************************************** - template - class type_from_index - { - private: - - //*********************************** - template - struct type_from_index_helper - { - using type = typename etl::conditional::type>::type; - }; - - //*********************************** - template - struct type_from_index_helper - { - using type = T1; - }; - - public: - - /// Template alias - using type = typename type_from_index_helper::type; - }; - - //*********************************** - template - using type_from_index_t = typename type_from_index::type; - }; - //******************************************* // The traits an object may have. //******************************************* @@ -327,7 +252,7 @@ namespace etl template struct variant_alternative> { - using type = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type = nth_type_t; }; template @@ -529,13 +454,13 @@ namespace etl // Get the index of a type. //******************************************* template - using index_of_type = typename etl::private_variant::parameter_pack::template index_of_type>; + using index_of_type = etl::type_list_index_of_type, etl::remove_cvref_t>; //******************************************* // Get the type from the index. //******************************************* template - using type_from_index = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type_from_index = typename etl::type_list_type_at_index, Index>::type; public: @@ -546,7 +471,7 @@ namespace etl #include "diagnostic_uninitialized_push.h" ETL_CONSTEXPR14 variant() { - using type = typename etl::private_variant::parameter_pack::template type_from_index<0U>::type; + using type = type_from_index<0U>; default_construct_in_place(data); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; @@ -592,7 +517,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, etl::forward(args)...); @@ -625,7 +550,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, std::initializer_list init, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, init, etl::forward(args)...); @@ -715,7 +640,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -737,7 +662,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -747,9 +672,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative>::type& emplace(TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -769,9 +694,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -803,7 +728,7 @@ namespace etl construct_in_place(data, etl::forward(value)); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *this; } @@ -896,7 +821,7 @@ namespace etl template (), int> = 0> constexpr bool is_type() const noexcept { - return (type_id == etl::private_variant::parameter_pack::template index_of_type::value); + return (type_id == index_of_type::value); } //*************************************************************************** @@ -1469,7 +1394,7 @@ namespace etl template ETL_CONSTEXPR14 bool holds_alternative(const etl::variant& v) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return (Index == variant_npos) ? false : (v.index() == Index); } @@ -1560,7 +1485,7 @@ namespace etl template ETL_CONSTEXPR14 T& get(etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1569,7 +1494,7 @@ namespace etl template ETL_CONSTEXPR14 T&& get(etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1578,7 +1503,7 @@ namespace etl template ETL_CONSTEXPR14 const T& get(const etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1587,7 +1512,7 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1628,7 +1553,7 @@ namespace etl template< class T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { @@ -1644,7 +1569,7 @@ namespace etl template< typename T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(const etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { From b0212765197b5bbbe3f94592250e5bf5a6d533f4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 17 Mar 2025 08:53:18 +0000 Subject: [PATCH 050/216] Reversed loop change --- test/test_multi_span.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index c3e20a6ee..19fbee95a 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -341,7 +341,14 @@ namespace etl::multi_span::iterator ms_itr = ms_int.begin(); etl::multi_span::iterator ms_end_itr = ms_int.end(); - std::copy(ms_itr, ms_end_itr, exp_itr); + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } + + ms_itr = ms_int.begin(); + exp_itr = expected.begin(); while (ms_itr != ms_end_itr) { @@ -547,7 +554,11 @@ namespace multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); - std::copy(ms_itr, ms_end_itr, exp_itr); + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } while (ms_itr != ms_end_itr) { From ecf5d9bca39dfd47696297afe016f4c924894833 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Tue, 4 Mar 2025 04:44:13 -0500 Subject: [PATCH 051/216] Implement << operator for std basic_ostream and etl string_view (#1040) * Implement << operator for std basic_ostream and etl string_view * Implement << operator for std basic_ostream and etl ibasic_string. Still working through tests * Should be all tests * Fix comment --- include/etl/basic_string.h | 21 ++++++++++++ include/etl/string_view.h | 17 ++++++++++ test/test_string_char.cpp | 18 ++++++++++ test/test_string_char_external_buffer.cpp | 19 +++++++++++ test/test_string_u16.cpp | 18 ++++++++++ test/test_string_u16_external_buffer.cpp | 19 +++++++++++ test/test_string_u32.cpp | 18 ++++++++++ test/test_string_u32_external_buffer.cpp | 19 +++++++++++ test/test_string_u8.cpp | 18 ++++++++++ test/test_string_u8_external_buffer.cpp | 19 +++++++++++ test/test_string_view.cpp | 35 ++++++++++++++++++++ test/test_string_wchar_t.cpp | 18 ++++++++++ test/test_string_wchar_t_external_buffer.cpp | 19 +++++++++++ 13 files changed, 258 insertions(+) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index d7f139d56..40a8d0db7 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -54,6 +54,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include "private/minmax_push.h" //***************************************************************************** @@ -2962,6 +2966,23 @@ namespace etl { return !(lhs < rhs); } + + //*************************************************************************** + /// Operator overload to write to std basic_ostream + ///\param os Reference to the output stream. + ///\param str Reference to the string to write. + ///\return Reference to the output stream, for chaining write operations. + ///\ingroup string + //*************************************************************************** +#if ETL_USING_STL + template + std::basic_ostream > &operator<<(std::basic_ostream > &os, + const etl::ibasic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif } #include "private/minmax_pop.h" diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 82bd4502b..69cbe8366 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -47,6 +47,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include namespace etl @@ -972,6 +976,19 @@ void swap(etl::basic_string_view >& lhs, etl::basic_strin lhs.swap(rhs); } +//************************************************************************* +/// Operator overload to write to std basic_ostream +//************************************************************************* +#if ETL_USING_STL +template +std::basic_ostream > &operator<<(std::basic_ostream > &os, + etl::basic_string_view > text) +{ + os.write(text.data(), text.size()); + return os; +} +#endif + #include "private/minmax_pop.h" #endif diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 9a4f463ca..55e1bdb37 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -5310,5 +5310,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 1234e1703..a2593660b 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -5689,5 +5689,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index d2cb002b8..01ee5cf88 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index b7a2bfec1..ab7223e74 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 4c19a57d6..4f4c6cb0d 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 5e8087267..1187091fe 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 4f792225a..e105ed197 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -5327,6 +5327,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index df2724e56..1494e7084 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -5706,6 +5706,25 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index afa1e6d33..598f63325 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -1120,5 +1120,40 @@ namespace CHECK_TRUE((u16view == U16View{ u"Hello World", etl::strlen(u"Hello World") })); CHECK_TRUE((u32view == U32View{ U"Hello World", etl::strlen(U"Hello World") })); } + + //************************************************************************* +#if ETL_USING_STL + TEST(write_to_std_stream) + { + View view{ "Hello World" }; + WView wview{ L"Hello World" }; + U16View u16view{ u"Hello World" }; + U32View u32view{ U"Hello World" }; + + std::stringstream sstream; + std::wstringstream wsstream; + std::basic_stringstream u16sstream; + std::basic_stringstream u32sstream; + + sstream << view; + std::string sstream_string = sstream.str(); + wsstream << wview; + std::wstring wsstream_string = wsstream.str(); + u16sstream << u16view; + std::u16string u16sstream_string = u16sstream.str(); + u32sstream << u32view; + std::u32string u32sstream_string = u32sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + WView wsstream_view(wsstream_string.data(), wsstream_string.size()); + U16View u16sstream_view(u16sstream_string.data(), u16sstream_string.size()); + U32View u32sstream_view(u32sstream_string.data(), u32sstream_string.size()); + + CHECK_TRUE(view == sstream_view); + CHECK_TRUE(wview == wsstream_view); + CHECK_TRUE(u16view == u16sstream_view); + CHECK_TRUE(u32view == u32sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 4eb16f41a..d28ba6d64 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -5325,5 +5325,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 8bbbe4963..16cc52a8d 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -5680,5 +5680,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } From 32f567f0bcc02cb5033bd304ef08671f33b489cf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 17 Mar 2025 17:59:50 +0000 Subject: [PATCH 052/216] Comments for nth_type --- include/etl/nth_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index ca3534582..ac8091669 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -63,7 +63,7 @@ namespace etl }; //*************************************************************************** - /// Finds the 0th type in a variadic type parameter. + /// Handles a zero length type list. //*************************************************************************** template struct nth_type From d6e6816ffc1002f8f42ad892f13d593194772499 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 18 Mar 2025 14:45:38 +0000 Subject: [PATCH 053/216] Refactored variant_variadic to use etl::nth_type for etl::variant_alternative implementation Refactored C++11 & C++14 support. --- .../etl/private/variant_select_do_operator.h | 1020 +++++++++++++++++ .../etl/private/variant_select_do_visitor.h | 1020 +++++++++++++++++ include/etl/private/variant_variadic.h | 239 +--- test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 5 files changed, 2088 insertions(+), 199 deletions(-) create mode 100644 include/etl/private/variant_select_do_operator.h create mode 100644 include/etl/private/variant_select_do_visitor.h diff --git a/include/etl/private/variant_select_do_operator.h b/include/etl/private/variant_select_do_operator.h new file mode 100644 index 000000000..c4b125d00 --- /dev/null +++ b/include/etl/private/variant_select_do_operator.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_operator inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_operator; + + //*************************************************************************** + template <> + struct select_do_operator<1> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<2> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<3> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<4> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<5> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<6> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<7> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<8> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<9> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<10> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<11> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<12> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<13> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<14> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<15> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<16> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<17> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<18> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<19> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<20> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<21> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<22> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<23> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<24> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<25> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<26> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<27> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<28> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<29> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<30> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<31> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<32> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + case 31: { visitor(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_select_do_visitor.h b/include/etl/private/variant_select_do_visitor.h new file mode 100644 index 000000000..b6e5bc500 --- /dev/null +++ b/include/etl/private/variant_select_do_visitor.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_visitor inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_visitor; + + //*************************************************************************** + template <> + struct select_do_visitor<1> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<2> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<3> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<4> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<5> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<6> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<7> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<8> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<9> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<10> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<11> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<12> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<13> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<14> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<15> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<16> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<17> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<18> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<19> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<20> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<21> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<22> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<23> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<24> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<25> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<26> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<27> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<28> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<29> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<30> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<31> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<32> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + case 31: { visitor.visit(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 6874f7f94..04b16f8d1 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -70,16 +70,16 @@ namespace etl //******************************************* // The traits an object may have. //******************************************* - static constexpr bool Copyable = true; + static constexpr bool Copyable = true; static constexpr bool Non_Copyable = false; - static constexpr bool Moveable = true; + static constexpr bool Moveable = true; static constexpr bool Non_Moveable = false; //******************************************* // The types of operations we can perform. //******************************************* - static constexpr int Copy = 0; - static constexpr int Move = 1; + static constexpr int Copy = 0; + static constexpr int Move = 1; static constexpr int Destroy = 2; //******************************************* @@ -93,7 +93,7 @@ namespace etl template <> struct operation_type { - static void do_operation(int , char* , const char* ) + static void do_operation(int, char*, const char*) { // This should never occur. #if defined(ETL_IN_UNIT_TEST) @@ -120,9 +120,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -153,9 +153,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -186,9 +186,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -245,14 +245,14 @@ namespace etl //*************************************************************************** /// variant_alternative - //*************************************************************************** + //*************************************************************************** template struct variant_alternative; template struct variant_alternative> { - using type = nth_type_t; + using type = etl::nth_type_t; }; template @@ -299,6 +299,11 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v); +#if ETL_NOT_USING_CPP17 + #include "variant_select_do_visitor.h" + #include "variant_select_do_operator.h" +#endif + //*************************************************************************** /// Monostate for variants. ///\ingroup variant @@ -672,7 +677,7 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative_t>& emplace(TArgs&&... args) { static_assert(Index < sizeof...(TTypes), "Index out of range"); @@ -694,7 +699,7 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative_t>& emplace(std::initializer_list il, TArgs&&... args) { static_assert(Index < sizeof...(TTypes), "Index out of range"); @@ -862,7 +867,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -876,7 +881,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -890,7 +895,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -904,7 +909,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -921,7 +926,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -938,7 +943,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -955,7 +960,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -972,7 +977,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -1045,103 +1050,21 @@ namespace etl } #else //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) const { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } #endif @@ -1207,9 +1130,9 @@ namespace etl } #else //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1226,54 +1149,13 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) const { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1290,48 +1172,7 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } #endif diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 808b085ac..306e5ea6b 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3185,6 +3185,8 @@ + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index f778794a4..a047f4305 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1434,6 +1434,12 @@ ETL\Utilities + + ETL\Private + + + ETL\Private + From 258e87569ae15c9c37db3fd9c5f0f99d1b7cce7d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 18 Mar 2025 15:47:38 +0000 Subject: [PATCH 054/216] Added instructions --- CONTRIBUTING.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56ce976d6..aa9253af5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,3 +8,6 @@ If your are considering creating a pull request, please observe the following: - Branches should be based on the branch `master`. There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang. + +If you are thinking of adding a new feature then raise this on the GitHub Issues page for disccussion as the maintainers and user of the ETL may have questions or suggestions. +It is possible that the maintainer of the ETL or another contributor is already working on the same or a related feature. From 0ca3043e242e656928c1650a6cb5a9d4d3f53324 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 18 Mar 2025 15:53:51 +0000 Subject: [PATCH 055/216] Added instructions --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa9253af5..3c1aa1c9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,4 +10,4 @@ If your are considering creating a pull request, please observe the following: There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang. If you are thinking of adding a new feature then raise this on the GitHub Issues page for disccussion as the maintainers and user of the ETL may have questions or suggestions. -It is possible that the maintainer of the ETL or another contributor is already working on the same or a related feature. +It is possible that the maintainer of the ETL or another contributor is already working on the same or related feature. From d794e84c547f2486289d9900f6db04c7beddd673 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Tue, 25 Mar 2025 14:16:44 -0400 Subject: [PATCH 056/216] Potential fix for span construct (#1051) * Try fix for span constructors * Make base class public --- include/etl/span.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 8d03e5fba..a313b54b7 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -55,11 +55,13 @@ SOFTWARE. namespace etl { + //empty base optimization means this has zero size + class span_base {}; //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** template - class span + class span : public span_base { public: @@ -113,7 +115,8 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value&& etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT @@ -158,7 +161,7 @@ namespace etl /// Copy constructor //************************************************************************* template - ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type* = 0) ETL_NOEXCEPT : pbegin(other.data()) { } @@ -511,7 +514,8 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value && etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT From e9adc288c68606c2adb820cb0088dbabffa3f499 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 25 Mar 2025 19:47:32 +0000 Subject: [PATCH 057/216] Changed span_base to span_tag Removed #include of --- include/etl/span.h | 41 ++++++++++++++++++--------------- test/test_span_fixed_extent.cpp | 9 ++++++++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index a313b54b7..4e7dac84f 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -46,22 +46,23 @@ SOFTWARE. #include "private/dynamic_extent.h" -#if ETL_USING_CPP20 && ETL_USING_STL - #include -#endif - ///\defgroup span span ///\ingroup containers namespace etl { + //*************************************************************************** + // Tag to indicate a class is a span. + //*************************************************************************** + class span_tag {}; + //empty base optimization means this has zero size class span_base {}; //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** template - class span : public span_base + class span : public span_tag { public: @@ -115,11 +116,11 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && !etl::is_pointer>::value && !etl::is_array>::value&& etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -129,7 +130,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - span(TContainer& a, typename etl::enable_if::type>::value && + span(TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -141,9 +143,10 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && - !etl::is_array::value&& - etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT + span(const TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && + !etl::is_array::value&& + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -385,14 +388,14 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { // If Extent is static, check that OFFSET is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? OFFSET <= Extent : true, "OFFSET is not within the original span"); // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, (pbegin + Extent)) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); } @@ -408,7 +411,7 @@ namespace etl // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + if (COUNT == etl::dynamic_extent) { return etl::span(pbegin + OFFSET, (pbegin + Extent)); @@ -459,7 +462,7 @@ namespace etl typedef const T& const_reference; typedef T* pointer; typedef const T* const_pointer; - + typedef T* iterator; typedef const T* const_iterator; typedef ETL_OR_STD::reverse_iterator reverse_iterator; @@ -514,11 +517,11 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && !etl::is_pointer>::value && !etl::is_array>::value && etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -784,7 +787,7 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, pend) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); @@ -960,4 +963,4 @@ namespace etl } } -#endif +#endif \ No newline at end of file diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 640126eea..cf50d52c5 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -1166,6 +1166,15 @@ namespace } } + //************************************************************************* + TEST(test_span_issue_1050_questions_on_span_constructors) + { + int arr[5]{}; + etl::span span1(arr); + etl::span span2(span1); + //etl::span span3(span1); // This line should fail to compile. + } + #include "etl/private/diagnostic_pop.h" }; } From af725afc79faaee34ddb82783af1b9855318076d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 26 Mar 2025 08:34:13 +0000 Subject: [PATCH 058/216] Added etl::monostate as a separate header monostate.h so that it can be used without have to include variant.h --- include/etl/monostate.h | 46 ++++++++++++++++++++++++++ include/etl/private/variant_legacy.h | 5 ++- include/etl/private/variant_variadic.h | 9 +---- test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 3 ++ 5 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 include/etl/monostate.h diff --git a/include/etl/monostate.h b/include/etl/monostate.h new file mode 100644 index 000000000..eb7877bf5 --- /dev/null +++ b/include/etl/monostate.h @@ -0,0 +1,46 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 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_MONOSTATE_INCLUDED +#define ETL_MONOSTATE_INCLUDED + +#include "platform.h" + +namespace etl +{ + //*************************************************************************** + /// A 'no-value' placeholder. + //*************************************************************************** + struct monostate + { + }; +} + +#endif diff --git a/include/etl/private/variant_legacy.h b/include/etl/private/variant_legacy.h index 3c0e788e6..d6eb539ae 100644 --- a/include/etl/private/variant_legacy.h +++ b/include/etl/private/variant_legacy.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../error_handler.h" #include "../null_type.h" #include "../placement_new.h" +#include "../monostate.h" #include @@ -75,9 +76,7 @@ namespace etl /// Monostate for variants. ///\ingroup variant //*************************************************************************** - struct monostate - { - }; + typedef etl::monostate monostate; //*************************************************************************** /// Base exception for the variant class. diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 04b16f8d1..8e6874601 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -44,6 +44,7 @@ SOFTWARE. #include "../memory.h" #include "../compare.h" #include "../initializer_list.h" +#include "../monostate.h" #include @@ -304,14 +305,6 @@ namespace etl #include "variant_select_do_operator.h" #endif - //*************************************************************************** - /// Monostate for variants. - ///\ingroup variant - //*************************************************************************** - struct monostate - { - }; - constexpr bool operator >(etl::monostate, etl::monostate) noexcept { return false; } constexpr bool operator <(etl::monostate, etl::monostate) noexcept { return false; } constexpr bool operator !=(etl::monostate, etl::monostate) noexcept { return false; } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 306e5ea6b..fde32d913 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3173,6 +3173,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index a047f4305..322cefa3f 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1440,6 +1440,9 @@ ETL\Private + + ETL\Utilities + From c547b7804fb86be2edabd0e55f0b0e3fb8d51149 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 26 Mar 2025 13:17:23 +0100 Subject: [PATCH 059/216] Returning const ref of member from const member function (#1052) The `const` marked function needs to return a `const` reference to a member variable Co-authored-by: Andreas Pelczer --- include/etl/expected.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/etl/expected.h b/include/etl/expected.h index 3f1abd999..fd68ac858 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -188,7 +188,7 @@ namespace etl //******************************************* /// Get the error. - //******************************************* + //******************************************* ETL_CONSTEXPR14 TError&& error() const&& ETL_NOEXCEPT { return etl::move(error_value); @@ -500,7 +500,7 @@ namespace etl //******************************************* /// Get the value. //******************************************* - value_type& value() const + const value_type& value() const { return etl::get(storage); } @@ -660,7 +660,7 @@ namespace etl //******************************************* /// //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -932,7 +932,7 @@ namespace etl /// Returns the error /// Undefined behaviour if an error has not been set. //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -1107,4 +1107,3 @@ void swap(etl::unexpected& lhs, etl::unexpected& rhs) } #endif - From a75d1d2a30e831931e9f5a25abe66d2e9be344c5 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Thu, 27 Mar 2025 11:15:31 -0400 Subject: [PATCH 060/216] Add enable_if restriction for span constructor from c array (#1055) * Add enable_if restriction for span constructor from c array * Try to simplify enable if * Revert "Try to simplify enable if" This reverts commit b133835f8cfe43e75478f2a8df06ad5265b7f163. --- include/etl/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/span.h b/include/etl/span.h index 8d03e5fba..a02fa0991 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -102,7 +102,7 @@ namespace etl //************************************************************************* /// Construct from C array //************************************************************************* - template + template::type> ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT : pbegin(begin_) { From 44a0d7c3c521875756d187e17d25d8294f84be1b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Feb 2025 10:02:56 +0000 Subject: [PATCH 061/216] Added etl::create_linked_list and etl::detach_linked_list to the intrusive link utilities --- include/etl/intrusive_links.h | 196 ++++++++++++++++++++ test/test_intrusive_links.cpp | 337 ++++++++++++++++++++++++++++++++++ 2 files changed, 533 insertions(+) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 577f50108..1ca2479e6 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -404,6 +404,112 @@ namespace etl } } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, current = &links), ...); + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, (*links)...); + } + else + { + return nullptr; + } + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first); + } + else + { + return ETL_NULLPTR; + } + } + + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A bidirectional link. //*************************************************************************** @@ -829,6 +935,96 @@ namespace etl etl::link_clear_range(*start); } +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLinks&... links) + { + TLink* current = &first; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLinks*... links) + { + TLink* current = first; + ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); + current->etl_next = ETL_NULLPTR; + + return current; + } +#elif ETL_USING_CPP11 + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first) + { + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink& first, TLink& next, TLinks&... links) + { + first.etl_next = &next; + next.etl_previous = &first; + + return create_linked_list(next, static_cast(links)...); + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + typename etl::enable_if::value, TLink*>::type + create_linked_list(TLink* first, TLink* next, TLinks*... links) + { + if (first != ETL_NULLPTR) + { + return create_linked_list(*first, *next, static_cast(*links)...); + } + else + { + return ETL_NULLPTR; + } + } +#endif + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink& first) + { + link_clear_range(first); + } + + //*************************************************************************** + template + typename etl::enable_if::value, void>::type + detach_linked_list(TLink* first) + { + if (first != ETL_NULLPTR) + { + detach_linked_list(*first); + } + } + //*************************************************************************** /// A binary tree link. //*************************************************************************** diff --git a/test/test_intrusive_links.cpp b/test/test_intrusive_links.cpp index 13a09c5b7..cdfa1d8c4 100644 --- a/test/test_intrusive_links.cpp +++ b/test/test_intrusive_links.cpp @@ -32,6 +32,8 @@ SOFTWARE. #include "etl/intrusive_links.h" +#include + namespace { //******************************************************* @@ -157,6 +159,166 @@ namespace CHECK_EQUAL(0, pdata->value); } + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + FLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + FLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.FLink1::etl_next == &data2); + CHECK(data2.FLink1::etl_next == &data1); + CHECK(data1.FLink1::etl_next == &data0); + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + + FData* pdata; + + pdata = static_cast(data0.FLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.FLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->FLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + FData data4(4); + FData data5(5); + FData data6(6); + FData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.FLink0::etl_next == &data1); + CHECK(data1.FLink0::etl_next == &data2); + CHECK(data2.FLink0::etl_next == &data3); + CHECK(data3.FLink0::etl_next == &data4); + CHECK(data4.FLink0::etl_next == &data5); + CHECK(data5.FLink0::etl_next == &data6); + CHECK(data6.FLink0::etl_next == &data7); + CHECK(data7.FLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_references) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_forward_links_as_pointers) + { + FData data0(0); + FData data1(1); + FData data2(2); + FData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.FLink0::etl_next == ETL_NULLPTR); + CHECK(data1.FLink0::etl_next == ETL_NULLPTR); + CHECK(data2.FLink0::etl_next == ETL_NULLPTR); + CHECK(data3.FLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.FLink1::etl_next == ETL_NULLPTR); + CHECK(data1.FLink1::etl_next == ETL_NULLPTR); + CHECK(data2.FLink1::etl_next == ETL_NULLPTR); + CHECK(data3.FLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_forward_link_get_set) { @@ -537,6 +699,181 @@ namespace data2.BLink0::unlink(); } + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(data0, data1, data2, data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(data3, data2, data1, data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_previous == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_previous == &data3); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_previous == &data2); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_previous == &data1); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(*last0, data4, data5, data6, data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_previous == ETL_NULLPTR); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_previous == &data0); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_previous == &data1); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_previous == &data2); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_previous == &data3); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_previous == &data4); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_previous == &data5); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_create_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + BLink0* last0 = etl::create_linked_list(&data0, &data1, &data2, &data3); + CHECK(last0 == &data3); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + BLink1* last1 = etl::create_linked_list(&data3, &data2, &data1, &data0); + CHECK(last1 == &data0); + CHECK(data3.BLink1::etl_next == &data2); + CHECK(data2.BLink1::etl_next == &data1); + CHECK(data1.BLink1::etl_next == &data0); + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + + BData* pdata; + + pdata = static_cast(data0.BLink0::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink0::etl_next); + CHECK_EQUAL(3, pdata->value); + + pdata = static_cast(data3.BLink1::etl_next); + CHECK_EQUAL(2, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(1, pdata->value); + pdata = static_cast(pdata->BLink1::etl_next); + CHECK_EQUAL(0, pdata->value); + + BData data4(4); + BData data5(5); + BData data6(6); + BData data7(7); + + auto last2 = etl::create_linked_list(last0, &data4, &data5, &data6, &data7); + CHECK(last2 == &data7); + CHECK(data0.BLink0::etl_next == &data1); + CHECK(data1.BLink0::etl_next == &data2); + CHECK(data2.BLink0::etl_next == &data3); + CHECK(data3.BLink0::etl_next == &data4); + CHECK(data4.BLink0::etl_next == &data5); + CHECK(data5.BLink0::etl_next == &data6); + CHECK(data6.BLink0::etl_next == &data7); + CHECK(data7.BLink0::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_references) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(data0); + etl::detach_linked_list(data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + + //************************************************************************* + TEST(test_detach_linked_list_multiple_bidirectional_links_as_pointers) + { + BData data0(0); + BData data1(1); + BData data2(2); + BData data3(3); + + etl::create_linked_list(data0, data1, data2, data3); + etl::create_linked_list(data3, data2, data1, data0); + + etl::detach_linked_list(&data0); + etl::detach_linked_list(&data3); + + CHECK(data0.BLink0::etl_next == ETL_NULLPTR); + CHECK(data1.BLink0::etl_next == ETL_NULLPTR); + CHECK(data2.BLink0::etl_next == ETL_NULLPTR); + CHECK(data3.BLink0::etl_next == ETL_NULLPTR); + + CHECK(data0.BLink1::etl_next == ETL_NULLPTR); + CHECK(data1.BLink1::etl_next == ETL_NULLPTR); + CHECK(data2.BLink1::etl_next == ETL_NULLPTR); + CHECK(data3.BLink1::etl_next == ETL_NULLPTR); + } + //************************************************************************* TEST(test_link_bidirectional_link_get_set) { From 13ee4bb41135a292c5c08fa946f30c653c4e1fa8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:39:51 +0000 Subject: [PATCH 062/216] Added variadic constructors --- include/etl/intrusive_forward_list.h | 49 +++++++++++++++++++++++++ include/etl/intrusive_list.h | 54 ++++++++++++++++++++++++++++ test/test_intrusive_forward_list.cpp | 23 ++++++++++++ test/test_intrusive_list.cpp | 23 ++++++++++++ 4 files changed, 149 insertions(+) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index d1a024fcf..79d156b37 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -629,6 +629,20 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_forward_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->start.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + last->etl_next = &this->terminator; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_forward_list. //************************************************************************* @@ -1192,6 +1206,41 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of forward_link nodes. + //*************************************************************************** + template + TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + return &first; + } + + //*************************************************************************** + /// Create a counted linked list from a number of forward_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + return make_linked_list(count, next, static_cast(links)...); + } +#endif + //************************************************************************* /// Get the next value. //************************************************************************* diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f5..a8da751ee 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -685,6 +685,22 @@ namespace etl this->assign(first, last); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Constructor from variadic list of nodes. + //************************************************************************* + template + intrusive_list(link_type& first, TLinks&... links) + { + current_size = 0; + this->terminal_link.etl_next = &first; + link_type* last = make_linked_list(current_size, first, static_cast(links)...); + first.etl_previous = &this->terminal_link; + last->etl_next = &this->terminal_link; + this->terminal_link.etl_previous = last; + } +#endif + //************************************************************************* /// Gets the beginning of the intrusive_list. //************************************************************************* @@ -1194,6 +1210,44 @@ namespace etl private: +#if ETL_USING_CPP17 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + { + TLink* current = &first; + ++count; + ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links, ++count), ...); + + return current; + } +#elif ETL_USING_CPP11 + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + link_type* make_linked_list(size_t& count, link_type& first) + { + ++count; + + return &first; + } + + //*************************************************************************** + /// Create a linked list from a number of bidirectional_link nodes. + //*************************************************************************** + template + link_type* make_linked_list(size_t& count, link_type& first, link_type& next, TLinks&... links) + { + ++count; + first.etl_next = &next; + next.etl_previous = &first; + + return make_linked_list(count, next, static_cast(links)...); + } +#endif + // Disabled. intrusive_list(const intrusive_list& other); intrusive_list& operator = (const intrusive_list& rhs); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 8134f921c..b9e223672 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -183,6 +183,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 33aa44679..48081e355 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -196,6 +196,29 @@ namespace CHECK_EQUAL(sorted_data.size(), data0.size()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_single) + { + DataNDC0 data0(sorted_data[0]); + + CHECK(!data0.empty()); + CHECK_EQUAL(1, data0.size()); + CHECK_EQUAL(sorted_data[0], data0.front()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_variadic_list_multiple) + { + DataNDC0 data0(sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9]); + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { From 222cf930569d591b709b5e6fb9fbe4ede9c0ab5a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:40:49 +0000 Subject: [PATCH 063/216] Modified create_linked_list functions to not null terminal link pointers --- include/etl/intrusive_links.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 1ca2479e6..9c0e471c0 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -945,8 +945,7 @@ namespace etl { TLink* current = &first; ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); - current->etl_next = ETL_NULLPTR; - + return current; } @@ -959,12 +958,10 @@ namespace etl { TLink* current = first; ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); - current->etl_next = ETL_NULLPTR; return current; } #elif ETL_USING_CPP11 - //*************************************************************************** /// Create a linked list from a number of bidirectional_link nodes. //*************************************************************************** From 2b437a60b2fc3732fc392d2a26af381fafc32290 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 18:57:27 +0100 Subject: [PATCH 064/216] Cleanup (#1039) --- include/etl/bit_stream.h | 6 +++--- include/etl/intrusive_forward_list.h | 6 +----- include/etl/private/delegate_cpp03.h | 10 +++++----- include/etl/vector.h | 1 - 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/include/etl/bit_stream.h b/include/etl/bit_stream.h index 7c5b557ef..b58c58820 100644 --- a/include/etl/bit_stream.h +++ b/include/etl/bit_stream.h @@ -236,8 +236,8 @@ namespace etl while (nbits != 0) { unsigned char mask_width = static_cast(etl::min(nbits, bits_available_in_char)); - - typedef typename etl::make_unsigned::type chunk_t; + + typedef typename etl::make_unsigned::type chunk_t; chunk_t chunk = get_chunk(mask_width); nbits -= mask_width; @@ -529,7 +529,7 @@ namespace etl typedef char value_type; typedef value_type* iterator; - typedef const value_type* const_iterator; + typedef const value_type* const_iterator; typedef etl::span callback_parameter_type; typedef etl::delegate callback_type; diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 79d156b37..1e530d87a 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -351,11 +351,7 @@ namespace etl } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 250fff6f6..382e6504f 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -66,11 +66,11 @@ namespace etl //*********************************** template struct call_if_impl - { + { etl::optional call_if(TParam param) { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + etl::optional result; if (d.is_valid()) @@ -88,8 +88,8 @@ namespace etl { bool call_if() { - TDelegate& d = static_cast(*this); - + TDelegate& d = static_cast(*this); + if (d.is_valid()) { d(); diff --git a/include/etl/vector.h b/include/etl/vector.h index 80994bd58..f2c1b6461 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -47,7 +47,6 @@ SOFTWARE. #include "functional.h" #include "static_assert.h" #include "placement_new.h" -#include "algorithm.h" #include "initializer_list.h" #include From 277cd68301d8f040518d573c783f5a632717f346 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:30:54 +0000 Subject: [PATCH 065/216] Added variadic contruction Added erase from pointer to node --- include/etl/intrusive_forward_list.h | 30 ++++++---- test/test_intrusive_forward_list.cpp | 84 ++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 11 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 1e530d87a..45bdd7bfa 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -338,14 +338,14 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(link_type& search_link) + link_type* is_link_in_list(const link_type* search_link) { link_type* p_link = start.etl_next; link_type* p_previous = &start; while (p_link != ETL_NULLPTR) { - if (&search_link == p_link) + if (search_link == p_link) { return p_previous; } @@ -362,7 +362,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; @@ -370,7 +370,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link_after(*p_previous); @@ -632,9 +632,9 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { - current_size = 0; + this->current_size = 0; this->start.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); last->etl_next = &this->terminator; } #endif @@ -797,9 +797,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -1206,10 +1214,10 @@ namespace etl //*************************************************************************** /// Create a linked list from a number of forward_link nodes. //*************************************************************************** - template - TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) { - TLink* current = &first; + link_type* current = &first; ++count; ((current->etl_next = &links, current = &links, ++count), ...); diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index b9e223672..a7d21da8a 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -722,6 +722,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_front(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_after_range) { From 13dfaaa74871101b2180f1fce2665f5c5142ce37 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:31:14 +0000 Subject: [PATCH 066/216] Added erase from pointer to node --- include/etl/intrusive_list.h | 20 ++++++--- test/test_intrusive_list.cpp | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index a8da751ee..30cf7d505 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -379,13 +379,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(link_type& search_link) const + bool is_link_in_list(const link_type* search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (&search_link == p_link) + if (search_link == p_link) { return true; } @@ -400,13 +400,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link(link); @@ -859,9 +859,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 48081e355..8006af29d 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -863,6 +863,90 @@ namespace CHECK(ETL_NULLPTR == p_next5); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_by_node_pointer) + { + bool are_equal; + + std::vector compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC0 data0(sorted_data.begin(), sorted_data.end()); + DataNDC1 data1(sorted_data.begin(), sorted_data.end()); + + // Move to the third value and erase. + std::vector::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 3); + + DataNDC0::iterator i_data = data0.begin(); + std::advance(i_data, 3); + + ItemNDCNode& node1 = *i_data; + ItemNDCNode* p_next1 = static_cast(node1.FirstLink::get_next()); + ItemNDCNode* p_node1 = data0.erase(&node1); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next1, p_node1); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the first value and erase. + i_compare_data = compare_data.begin(); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data0.begin(); + + ItemNDCNode& node2 = *i_data; + ItemNDCNode* p_next2 = static_cast(node2.FirstLink::get_next()); + ItemNDCNode* p_node2 = data0.erase(&node2); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_EQUAL(p_next2, p_node2); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + + i_data = data0.begin(); + std::advance(i_data, data0.size() - 1); + + ItemNDCNode& node3 = *i_data; + ItemNDCNode* p_next3 = static_cast(node3.FirstLink::get_next()); + ItemNDCNode* p_node3 = data0.erase(&node3); + i_compare_data = compare_data.erase(i_compare_data); + + are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK_NOT_EQUAL(p_next3, p_node3); + CHECK(ETL_NULLPTR == p_node3); + CHECK_EQUAL(compare_data.size(), data0.size()); + CHECK_EQUAL(compare_data.size(), size_t(std::distance(data0.begin(), data0.end()))); + + // Try removing a node that isn't in the list. + auto node_not_in_list = ItemNDCNode("9"); + + ItemNDCNode* p_node4 = data0.erase(&node_not_in_list); + CHECK(p_node4 == ETL_NULLPTR); + + // Try removing the only node in the list. + while (data0.size() > 1) + { + data0.pop_back(); + } + + ItemNDCNode* p_node5 = &data0.front(); + + ItemNDCNode* p_next5 = static_cast(p_node5->FirstLink::get_next()); + p_next5 = data0.erase(p_node5); + CHECK(ETL_NULLPTR == p_next5); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { From 9a07ef9cae019d4bac32583726760f396bdc984a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 09:43:31 +0000 Subject: [PATCH 067/216] Improved implementation of etl::is_base_of_all --- .../etl/generators/type_traits_generator.h | 16 ++++++++-------- include/etl/type_traits.h | 19 ++++++++++--------- test/test_type_traits.cpp | 2 ++ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index e55d12217..bc5edbeab 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1405,19 +1405,19 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; -#endif #if ETL_USING_CPP17 template diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 327f164be..b75118edc 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1398,23 +1398,24 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_base_of_all + template + struct is_base_of_all; + + template + struct is_base_of_all : etl::true_type { - static const bool value = etl::is_base_of::value && - etl::is_base_of_all::value; }; - template - struct is_base_of_all + template + struct is_base_of_all : etl::integral_constant::value && + etl::is_base_of_all::value> { - static const bool value = etl::is_base_of::value; }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; + template + inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; #endif #if ETL_USING_CPP11 diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 4316a697f..37d620cdd 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1320,9 +1320,11 @@ namespace struct D4 {}; #if ETL_USING_CPP17 + CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_FALSE(bool(etl::is_base_of_all_v)); #else + CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_FALSE(bool(etl::is_base_of_all::value)); #endif From 4197a1ee8ad140669140e025f5524d7e07300043 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 10:20:44 +0000 Subject: [PATCH 068/216] Added static assert for variadic constructor Fixed missing this-> prefix for current_size --- include/etl/intrusive_forward_list.h | 2 ++ include/etl/intrusive_list.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 45bdd7bfa..307f110b8 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -632,6 +632,8 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + this->current_size = 0; this->start.etl_next = &first; link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 30cf7d505..49bfea05e 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -692,9 +692,11 @@ namespace etl template intrusive_list(link_type& first, TLinks&... links) { - current_size = 0; + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; this->terminal_link.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); first.etl_previous = &this->terminal_link; last->etl_next = &this->terminal_link; this->terminal_link.etl_previous = last; From e103d0959f2a84af8b208825f870ab725ab97ba0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Feb 2025 10:02:56 +0000 Subject: [PATCH 069/216] Added etl::create_linked_list and etl::detach_linked_list to the intrusive link utilities # Conflicts: # include/etl/intrusive_links.h --- include/etl/intrusive_links.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 9c0e471c0..1ca2479e6 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -945,7 +945,8 @@ namespace etl { TLink* current = &first; ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); - + current->etl_next = ETL_NULLPTR; + return current; } @@ -958,10 +959,12 @@ namespace etl { TLink* current = first; ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); + current->etl_next = ETL_NULLPTR; return current; } #elif ETL_USING_CPP11 + //*************************************************************************** /// Create a linked list from a number of bidirectional_link nodes. //*************************************************************************** From 8890f4391835c1749705427701aa6f41a6c54451 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:39:51 +0000 Subject: [PATCH 070/216] Added variadic constructors --- include/etl/intrusive_forward_list.h | 61 ++++++++-------------------- include/etl/intrusive_list.h | 26 ++++-------- 2 files changed, 24 insertions(+), 63 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 307f110b8..a466337f1 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -338,20 +338,24 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(const link_type* search_link) + link_type* is_link_in_list(link_type& search_link) { link_type* p_link = start.etl_next; link_type* p_previous = &start; while (p_link != ETL_NULLPTR) { - if (search_link == p_link) + if (&search_link == p_link) { return p_previous; } p_previous = p_link; - p_link = p_link->link_type::etl_next; + + if (p_link != ETL_NULLPTR) + { + p_link = p_link->link_type::etl_next; + } } return ETL_NULLPTR; @@ -362,7 +366,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type* link) + link_type* remove_link(link_type& link) { link_type* result = ETL_NULLPTR; @@ -370,7 +374,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link->etl_next; + link_type* p_next = link.etl_next; disconnect_link_after(*p_previous); @@ -632,11 +636,9 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { - ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); - - this->current_size = 0; + current_size = 0; this->start.etl_next = &first; - link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); + link_type* last = make_linked_list(current_size, first, static_cast(links)...); last->etl_next = &this->terminator; } #endif @@ -799,17 +801,9 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(const node_type& node) + node_type* erase(node_type& node) { - return static_cast(this->remove_link(const_cast(&node))); - } - - //************************************************************************* - /// Erases the specified node. - //************************************************************************* - node_type* erase(const node_type* p_node) - { - return static_cast(this->remove_link(const_cast(p_node))); + return static_cast(this->remove_link(node)); } //************************************************************************* @@ -1011,29 +1005,6 @@ namespace etl } } - //************************************************************************* - // Removes the element specified by pointer. - //************************************************************************* - void remove(const_pointer element) - { - iterator i_item = begin(); - iterator i_last_item = before_begin(); - - while (i_item != end()) - { - if (&i_item == element) - { - i_item = erase_after(i_last_item); - return; - } - else - { - ++i_item; - ++i_last_item; - } - } - } - //************************************************************************* /// Removes according to a predicate. //************************************************************************* @@ -1216,10 +1187,10 @@ namespace etl //*************************************************************************** /// Create a linked list from a number of forward_link nodes. //*************************************************************************** - template - link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) + template + TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) { - link_type* current = &first; + TLink* current = &first; ++count; ((current->etl_next = &links, current = &links, ++count), ...); diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 49bfea05e..a8da751ee 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -379,13 +379,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(const link_type* search_link) const + bool is_link_in_list(link_type& search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (search_link == p_link) + if (&search_link == p_link) { return true; } @@ -400,13 +400,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type* link) + link_type* remove_link(link_type& link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link->etl_next; + link_type* p_next = link.etl_next; disconnect_link(link); @@ -692,11 +692,9 @@ namespace etl template intrusive_list(link_type& first, TLinks&... links) { - ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); - - this->current_size = 0; + current_size = 0; this->terminal_link.etl_next = &first; - link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); + link_type* last = make_linked_list(current_size, first, static_cast(links)...); first.etl_previous = &this->terminal_link; last->etl_next = &this->terminal_link; this->terminal_link.etl_previous = last; @@ -861,17 +859,9 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(const node_type& node) - { - return static_cast(this->remove_link(const_cast(&node))); - } - - //************************************************************************* - /// Erases the specified node. - //************************************************************************* - node_type* erase(const node_type* p_node) + node_type* erase(node_type& node) { - return static_cast(this->remove_link(const_cast(p_node))); + return static_cast(this->remove_link(node)); } //************************************************************************* From b5ee8fb2596f4a094ea2c21fae9eb44d385fb05a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 1 Mar 2025 13:40:49 +0000 Subject: [PATCH 071/216] Modified create_linked_list functions to not null terminal link pointers --- include/etl/intrusive_links.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 1ca2479e6..9c0e471c0 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -945,8 +945,7 @@ namespace etl { TLink* current = &first; ((current->etl_next = &links, static_cast(links).etl_previous = current, current = &links), ...); - current->etl_next = ETL_NULLPTR; - + return current; } @@ -959,12 +958,10 @@ namespace etl { TLink* current = first; ((current->etl_next = links, static_cast(links)->etl_previous = current, current = links), ...); - current->etl_next = ETL_NULLPTR; return current; } #elif ETL_USING_CPP11 - //*************************************************************************** /// Create a linked list from a number of bidirectional_link nodes. //*************************************************************************** From ef2337cfe5fbade957ababdba69ef92fc1567dee Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 18:57:27 +0100 Subject: [PATCH 072/216] Cleanup (#1039) --- include/etl/intrusive_forward_list.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index a466337f1..929a69d03 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -351,11 +351,7 @@ namespace etl } p_previous = p_link; - - if (p_link != ETL_NULLPTR) - { - p_link = p_link->link_type::etl_next; - } + p_link = p_link->link_type::etl_next; } return ETL_NULLPTR; From 74cb40c6e1909aee021fef204674c392078aa3df Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:30:54 +0000 Subject: [PATCH 073/216] Added variadic contruction Added erase from pointer to node --- include/etl/intrusive_forward_list.h | 30 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 929a69d03..566c0e41f 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -338,14 +338,14 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(link_type& search_link) + link_type* is_link_in_list(const link_type* search_link) { link_type* p_link = start.etl_next; link_type* p_previous = &start; while (p_link != ETL_NULLPTR) { - if (&search_link == p_link) + if (search_link == p_link) { return p_previous; } @@ -362,7 +362,7 @@ namespace etl /// Returns ETL_NULLPTR if the link was not in this list. /// Returns the next //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; @@ -370,7 +370,7 @@ namespace etl if (p_previous != ETL_NULLPTR) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link_after(*p_previous); @@ -632,9 +632,9 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { - current_size = 0; + this->current_size = 0; this->start.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); last->etl_next = &this->terminator; } #endif @@ -797,9 +797,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* @@ -1183,10 +1191,10 @@ namespace etl //*************************************************************************** /// Create a linked list from a number of forward_link nodes. //*************************************************************************** - template - TLink* make_linked_list(size_t& count, TLink& first, TLinks&... links) + template + link_type* make_linked_list(size_t& count, link_type& first, TLinks&... links) { - TLink* current = &first; + link_type* current = &first; ++count; ((current->etl_next = &links, current = &links, ++count), ...); From 6e7df8c581806d57946906f7ae5a9ee792b85979 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 08:31:14 +0000 Subject: [PATCH 074/216] Added erase from pointer to node --- include/etl/intrusive_list.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index a8da751ee..30cf7d505 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -379,13 +379,13 @@ namespace etl //************************************************************************* /// Tests if the link is in this list. //************************************************************************* - bool is_link_in_list(link_type& search_link) const + bool is_link_in_list(const link_type* search_link) const { link_type* p_link = terminal_link.link_type::etl_next; while (p_link != &terminal_link) { - if (&search_link == p_link) + if (search_link == p_link) { return true; } @@ -400,13 +400,13 @@ namespace etl /// Remove the specified node from the list. /// Returns ETL_NULLPTR if the link was not in this list or was the last in the list. //************************************************************************* - link_type* remove_link(link_type& link) + link_type* remove_link(link_type* link) { link_type* result = ETL_NULLPTR; if (is_link_in_list(link)) { - link_type* p_next = link.etl_next; + link_type* p_next = link->etl_next; disconnect_link(link); @@ -859,9 +859,17 @@ namespace etl //************************************************************************* /// Erases the specified node. //************************************************************************* - node_type* erase(node_type& node) + node_type* erase(const node_type& node) { - return static_cast(this->remove_link(node)); + return static_cast(this->remove_link(const_cast(&node))); + } + + //************************************************************************* + /// Erases the specified node. + //************************************************************************* + node_type* erase(const node_type* p_node) + { + return static_cast(this->remove_link(const_cast(p_node))); } //************************************************************************* From 9c22c6ce50b0e45d12e91f8caaf9baa86295cf13 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 10:20:44 +0000 Subject: [PATCH 075/216] Added static assert for variadic constructor Fixed missing this-> prefix for current_size --- include/etl/intrusive_forward_list.h | 2 ++ include/etl/intrusive_list.h | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 566c0e41f..12e3c3d3c 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -632,6 +632,8 @@ namespace etl template intrusive_forward_list(link_type& first, TLinks&... links) { + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + this->current_size = 0; this->start.etl_next = &first; link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 30cf7d505..49bfea05e 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -692,9 +692,11 @@ namespace etl template intrusive_list(link_type& first, TLinks&... links) { - current_size = 0; + ETL_STATIC_ASSERT((etl::is_base_of_all::value), "Mixed link types"); + + this->current_size = 0; this->terminal_link.etl_next = &first; - link_type* last = make_linked_list(current_size, first, static_cast(links)...); + link_type* last = make_linked_list(this->current_size, first, static_cast(links)...); first.etl_previous = &this->terminal_link; last->etl_next = &this->terminal_link; this->terminal_link.etl_previous = last; From a733502359f1e63732c9f75e423e0d8fb4a0c232 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 1 Mar 2025 19:24:30 +0100 Subject: [PATCH 076/216] Intrusive forward list add remove by pointer (#1026) * Add intrusive_forward_list::remove() element by pointer * Add test --- include/etl/intrusive_forward_list.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 12e3c3d3c..307f110b8 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -1011,6 +1011,29 @@ namespace etl } } + //************************************************************************* + // Removes the element specified by pointer. + //************************************************************************* + void remove(const_pointer element) + { + iterator i_item = begin(); + iterator i_last_item = before_begin(); + + while (i_item != end()) + { + if (&i_item == element) + { + i_item = erase_after(i_last_item); + return; + } + else + { + ++i_item; + ++i_last_item; + } + } + } + //************************************************************************* /// Removes according to a predicate. //************************************************************************* From a6e64af0850a04004d27bf66cea0ec7a7d32aeaf Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sun, 2 Mar 2025 12:09:32 +0100 Subject: [PATCH 077/216] Add contains() and contains_node() to etl::intrusive_forward_list and etl::intrusive_list (#1036) Co-authored-by: John Wellbelove --- include/etl/intrusive_forward_list.h | 42 ++++++++++++++++ include/etl/intrusive_list.h | 44 ++++++++++++++++- test/test_intrusive_forward_list.cpp | 72 ++++++++++++++++++++++++++++ test/test_intrusive_list.cpp | 72 ++++++++++++++++++++++++++++ 4 files changed, 229 insertions(+), 1 deletion(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 307f110b8..238aca102 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -253,6 +253,27 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type& search_link) const + { + const link_type* p_link = start.etl_next; + + while (p_link != ETL_NULLPTR) + { + if (&search_link == p_link) + { + return true; + } + + p_link = p_link->link_type::etl_next; + } + + return false; + } + protected: link_type start; ///< The link pointer that acts as the intrusive_forward_list start. @@ -1210,6 +1231,27 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: #if ETL_USING_CPP17 diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 49bfea05e..673852c12 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -255,6 +255,27 @@ namespace etl return current_size; } + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(link_type& search_link) const + { + link_type* p_link = terminal_link.link_type::etl_next; + + while (p_link != &terminal_link) + { + if (&search_link == p_link) + { + return true; + } + + p_link = p_link->link_type::etl_next; + } + + return false; + } + protected: /// The link that acts as the intrusive_list start & end. @@ -404,7 +425,7 @@ namespace etl { link_type* result = ETL_NULLPTR; - if (is_link_in_list(link)) + if (contains_node(link)) { link_type* p_next = link->etl_next; @@ -1218,6 +1239,27 @@ namespace etl } } + //************************************************************************* + /// Detects existence of specified value in list. + ///\param value The value to find in list + //************************************************************************* + bool contains(const_reference value) const + { + const_iterator i_item = begin(); + + while (i_item != end()) + { + if (*i_item == value) + { + return true; + } + + ++i_item; + } + + return false; + } + private: #if ETL_USING_CPP17 diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index a7d21da8a..d39ca7dc5 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -1302,5 +1302,77 @@ namespace CHECK_EQUAL(size_t(std::distance(compare0.begin(), compare0.end())), data0.size()); CHECK_EQUAL(size_t(std::distance(compare1.begin(), compare1.end())), data1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 8006af29d..9d5a08db4 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -1519,5 +1519,77 @@ namespace CHECK_EQUAL(data0.size(), compare0.size()); CHECK_EQUAL(data1.size(), compare1.size()); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_node) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains_node(node0)); + CHECK_TRUE(data0.contains_node(node1)); + CHECK_TRUE(data0.contains_node(node2)); + CHECK_TRUE(data0.contains_node(node3)); + CHECK_TRUE(data0.contains_node(node4)); + CHECK_TRUE(data0.contains_node(node5)); + + CHECK_FALSE(data0.contains_node(node6)); + CHECK_FALSE(data0.contains_node(node7)); + CHECK_FALSE(data0.contains_node(node8)); + CHECK_FALSE(data0.contains_node(node9)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains) + { + static ItemNDCNode node0("0"); + static ItemNDCNode node1("1"); + static ItemNDCNode node2("2"); + static ItemNDCNode node3("3"); + static ItemNDCNode node4("4"); + static ItemNDCNode node5("5"); + static ItemNDCNode node6("6"); + static ItemNDCNode node7("7"); + static ItemNDCNode node8("8"); + static ItemNDCNode node9("9"); + + DataNDC0 data0; + + data0.push_front(node0); + data0.push_front(node1); + data0.push_front(node2); + data0.push_front(node3); + data0.push_front(node4); + data0.push_front(node5); + + CHECK_TRUE(data0.contains(ItemNDCNode("0"))); + + ItemNDCNode compare_node1("1"); + + CHECK_TRUE(data0.contains(compare_node1)); + + CHECK_FALSE(data0.contains(ItemNDCNode("6"))); + + ItemNDCNode compare_node2("7"); + + CHECK_FALSE(data0.contains(compare_node2)); + } }; } From 1274ba263b6bd956a4d32f24595187fe7eb59b78 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 2 Mar 2025 12:51:17 +0000 Subject: [PATCH 078/216] Integration of contains and contains_node --- include/etl/intrusive_forward_list.h | 25 +++++++++++-------------- include/etl/intrusive_list.h | 25 +++++++++++-------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 238aca102..6cb442806 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -259,19 +259,16 @@ namespace etl //************************************************************************* bool contains_node(const link_type& search_link) const { - const link_type* p_link = start.etl_next; - - while (p_link != ETL_NULLPTR) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } + return is_link_in_list(&search_link); + } - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link); } protected: @@ -359,10 +356,10 @@ namespace etl /// Tests if the link is in this list. /// Returns the previous link to it, if found, otherwise ETL_NULLPTR. //************************************************************************* - link_type* is_link_in_list(const link_type* search_link) + link_type* is_link_in_list(const link_type* search_link) const { link_type* p_link = start.etl_next; - link_type* p_previous = &start; + link_type* p_previous = const_cast(&start); while (p_link != ETL_NULLPTR) { diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 673852c12..563fadfa8 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -259,21 +259,18 @@ namespace etl /// Detects existence of specified node in list. ///\param search_link The node to find in list //************************************************************************* - bool contains_node(link_type& search_link) const + bool contains_node(const link_type& search_link) const { - link_type* p_link = terminal_link.link_type::etl_next; - - while (p_link != &terminal_link) - { - if (&search_link == p_link) - { - return true; - } - - p_link = p_link->link_type::etl_next; - } + return is_link_in_list(&search_link);; + } - return false; + //************************************************************************* + /// Detects existence of specified node in list. + ///\param search_link The node to find in list + //************************************************************************* + bool contains_node(const link_type* search_link) const + { + return is_link_in_list(search_link);; } protected: @@ -425,7 +422,7 @@ namespace etl { link_type* result = ETL_NULLPTR; - if (contains_node(link)) + if (is_link_in_list(link)) { link_type* p_next = link->etl_next; From 90e432cd436e0298623e2ea06dcaf9889feb9868 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Mar 2025 10:03:42 +0000 Subject: [PATCH 079/216] Added ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE macro and has_atomic_always_lock_free trait Fixed coditional unit tests in test_atomic --- include/etl/platform.h | 10 ++++++++++ test/test_atomic.cpp | 42 +++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index 5f92528eb..6738b4991 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -434,6 +434,15 @@ SOFTWARE. #else #define ETL_HAS_ATOMIC 0 #endif + #if ((ETL_USING_CPP17 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) || \ + defined(ETL_COMPILER_ARM5) || \ + defined(ETL_COMPILER_ARM6) || \ + defined(ETL_COMPILER_GCC) || \ + defined(ETL_COMPILER_CLANG)) + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 1 + #else + #define ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE 0 + #endif #endif //************************************* @@ -524,6 +533,7 @@ namespace etl static ETL_CONSTANT bool has_8bit_types = (ETL_USING_8BIT_TYPES == 1); static ETL_CONSTANT bool has_64bit_types = (ETL_USING_64BIT_TYPES == 1); static ETL_CONSTANT bool has_atomic = (ETL_HAS_ATOMIC == 1); + static ETL_CONSTANT bool has_atomic_always_lock_free = (ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE == 1); static ETL_CONSTANT bool has_nullptr = (ETL_HAS_NULLPTR == 1); static ETL_CONSTANT bool has_char8_t = (ETL_HAS_CHAR8_T == 1); static ETL_CONSTANT bool has_native_char8_t = (ETL_HAS_NATIVE_CHAR8_T == 1); diff --git a/test/test_atomic.cpp b/test/test_atomic.cpp index 572a9b47d..281b76508 100644 --- a/test/test_atomic.cpp +++ b/test/test_atomic.cpp @@ -76,10 +76,10 @@ namespace CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); -//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_TRUE(test.is_always_lock_free); -//#endif +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(test.is_always_lock_free); +#endif } //************************************************************************* @@ -90,28 +90,28 @@ namespace CHECK_EQUAL(compare.is_lock_free(), test.is_lock_free()); -#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE CHECK_TRUE(etl::atomic::is_always_lock_free); CHECK_TRUE(test.is_always_lock_free); #endif } -//#if ETL_NOT_USING_STL && ETL_HAS_ATOMIC -// //************************************************************************* -// TEST(test_atomic_is_always_lock_free) -// { -// struct S -// { -// int a; -// int b; -// int c; -// }; -// -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_TRUE(etl::atomic::is_always_lock_free); -// CHECK_FALSE(etl::atomic::is_always_lock_free); -// } -//#endif +#if ETL_HAS_ATOMIC_ALWAYS_LOCK_FREE + //************************************************************************* + TEST(test_atomic_is_always_lock_free) + { + struct S + { + int a; + int b; + int c; + }; + + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_TRUE(etl::atomic::is_always_lock_free); + CHECK_FALSE(etl::atomic::is_always_lock_free); + } +#endif //************************************************************************* TEST(test_atomic_integer_load) From a26fed1a893d4ba088aa7e047b234c4052469ac1 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Mon, 3 Mar 2025 09:52:12 +0100 Subject: [PATCH 080/216] etl::span: Add advance(), copy(), reinterpret_as() (#1024) * etl::span: Add advance(), copy(), reinterpret_as() * Added further tests for span::reinterpret_as * Fix size of unaligned_type on Windows Multiple inheritance leads to additional 1 byte for the second base class. Fixing it by not inheriting but aggregating via typedef. --- include/etl/file_error_numbers.h | 2 + include/etl/span.h | 93 ++++++++++++++++++++++ include/etl/unaligned_type.h | 36 +++++---- test/test_span_dynamic_extent.cpp | 126 ++++++++++++++++++++++++++++++ test/test_span_fixed_extent.cpp | 70 +++++++++++++++++ test/test_unaligned_type.cpp | 20 +++++ 6 files changed, 330 insertions(+), 17 deletions(-) diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 64d94d573..2369f68cf 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -105,4 +105,6 @@ SOFTWARE. #define ETL_BASE64_FILE_ID "72" #define ETL_SINGLETON_BASE_FILE_ID "73" #define ETL_UNALIGNED_TYPE_FILE_ID "74" +#define ETL_SPAN_FILE_ID "75" + #endif diff --git a/include/etl/span.h b/include/etl/span.h index a02fa0991..7b09adf46 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -32,6 +32,10 @@ SOFTWARE. #define ETL_SPAN_INCLUDED #include "platform.h" + +#include "error_handler.h" +#include "exception.h" +#include "alignment.h" #include "iterator.h" #include "algorithm.h" #include "circular_iterator.h" @@ -55,6 +59,34 @@ SOFTWARE. namespace etl { + //*************************************************************************** + ///\ingroup span + /// Exception base for span + //*************************************************************************** + class span_exception : public exception + { + public: + + span_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + ///\ingroup span + /// Bad alignment exception. + //*************************************************************************** + class span_alignment_exception : public span_exception + { + public: + + span_alignment_exception(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:alignment", ETL_SPAN_FILE_ID"A"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** @@ -426,6 +458,18 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + Extent * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -812,6 +856,28 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + + //************************************************************************* + /// Reinterpret the span as a span with different element type. + //************************************************************************* + template + ETL_NODISCARD ETL_CONSTEXPR14 etl::span reinterpret_as() const + { + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + + return etl::span(reinterpret_cast(pbegin), + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + } + private: pointer pbegin; @@ -884,6 +950,33 @@ namespace etl etl::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } + //************************************************************************* + /// Copy complete element data from one span to another. If the destination + /// span is bigger than the source span, only the initial part of + /// destination span is overwritten. + ///\param src Source + ///\param dst Destination + ///\return true, if copy was successful (including empty source span, or + /// spans pointing to the same address) + ///\return false, if the destination span is shorter than the source span. + //************************************************************************* + template + typename etl::enable_if::type, typename etl::remove_cv::type>::value && + !etl::is_const::value, bool>::type + copy(const etl::span& src, const etl::span& dst) + { + if (src.empty() || (src.begin() == dst.begin())) + { + return true; + } + if (src.size() > dst.size()) + { + return false; + } + (void) etl::copy(src.begin(), src.end(), dst.begin()); + return true; + } + //************************************************************************* /// Template deduction guides. //************************************************************************* diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 8910f864d..87519dbff 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -449,7 +449,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type) : public private_unaligned_type::unaligned_type_storage - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -457,6 +456,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage::const_pointer const_pointer; @@ -480,7 +481,7 @@ namespace etl //************************************************************************* unaligned_type(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -506,7 +507,7 @@ namespace etl //************************************************************************* unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); } //************************************************************************* @@ -515,7 +516,7 @@ namespace etl template unaligned_type(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } //************************************************************************* @@ -523,7 +524,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -533,7 +534,7 @@ namespace etl //************************************************************************* unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_, this->storage); return *this; } @@ -544,7 +545,7 @@ namespace etl template unaligned_type& operator =(const unaligned_type& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -556,7 +557,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -568,7 +569,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -589,7 +590,6 @@ namespace etl //************************************************************************* template ETL_PACKED_CLASS(unaligned_type_ext) : public private_unaligned_type::unaligned_type_storage_ext - , public private_unaligned_type::unaligned_copy::value ? false : true> { public: @@ -600,6 +600,8 @@ namespace etl typedef T value_type; + typedef private_unaligned_type::unaligned_copy::value ? false : true> unaligned_copy; + typedef typename private_unaligned_type::unaligned_type_storage_ext::storage_type storage_type; typedef typename private_unaligned_type::unaligned_type_storage_ext::pointer pointer; typedef typename private_unaligned_type::unaligned_type_storage_ext::const_pointer const_pointer; @@ -625,7 +627,7 @@ namespace etl unaligned_type_ext(T value, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); } //************************************************************************* @@ -635,7 +637,7 @@ namespace etl unaligned_type_ext(const unaligned_type_ext& other, pointer storage_) : private_unaligned_type::unaligned_type_storage_ext(storage_) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); } #if ETL_USING_CPP11 @@ -670,7 +672,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(T value) { - this->copy_value_to_store(value, this->storage); + unaligned_copy::copy_value_to_store(value, this->storage); return *this; } @@ -680,7 +682,7 @@ namespace etl //************************************************************************* unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian, this->storage); return *this; } @@ -691,7 +693,7 @@ namespace etl template unaligned_type_ext& operator =(const unaligned_type_ext& other) { - this->copy_store_to_store(other.data(), Endian_Other, this->storage); + unaligned_copy::copy_store_to_store(other.data(), Endian_Other, this->storage); return *this; } @@ -735,7 +737,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } @@ -747,7 +749,7 @@ namespace etl { T value = T(); - this->copy_store_to_value(this->storage, value); + unaligned_copy::copy_store_to_value(this->storage, value); return value; } diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index dd71bae22..ee85f843b 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1244,6 +1245,131 @@ namespace } } + //************************************************************************* + TEST(test_advance) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + } + { + const uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + CHECK_EQUAL(data0.size(), 5); + data0.advance(1); + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data0[0], 0x02); + data0.advance(2); + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data0[0], 0x04); + data0.advance(1); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data0[0], 0x05); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(1); + CHECK_EQUAL(data0.size(), 0); + data0.advance(100); + CHECK_EQUAL(data0.size(), 0); + } + } + + //************************************************************************* + TEST(test_reinterpret_as) + { + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + { + uint32_t data[] = { 0x01020304 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(3); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 0); + } + { + uint32_t data[] = { 0x01020304, 0x06070809 }; + etl::span data0 = data; + etl::span data1 = data0.reinterpret_as(); + data1 = data1.first(6); + etl::span data2 = data1.reinterpret_as(); + CHECK_EQUAL(data2.size(), 1); + + auto it = data2.begin(); + CHECK_NOT_EQUAL(it, data2.end()); + ++it; + CHECK_EQUAL(it, data2.end()); + } + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + + data1 = data1.subspan(1); + + CHECK_EQUAL(etl::copy(data0, data1), false); + + data0 = data0.subspan(0, 0); + + CHECK_EQUAL(etl::copy(data0, data1), true); + + data0 = src; + data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 640126eea..1440fde70 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -30,6 +30,7 @@ SOFTWARE. #include "etl/span.h" #include "etl/array.h" +#include "etl/unaligned_type.h" #include #include @@ -1166,6 +1167,75 @@ namespace } } + //************************************************************************* + TEST(test_reinterpret_as) + { + uint8_t data[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = data; + + etl::span data1 = data0.reinterpret_as(); + + CHECK_EQUAL(data1.size(), 2); + CHECK(data1[0] == 0x102); + CHECK(data1[1] == 0x304); + } + + //************************************************************************* + TEST(test_reinterpret_as_aligned) + { + uint32_t data[] = { 0x01020304, 0x020406080, 0x03400560}; + etl::span data0 = data; + CHECK_EQUAL(data0.size(), 3); + + etl::span data1 = data0.reinterpret_as(); + CHECK_EQUAL(data1.size(), 12); + + etl::span data2 = data1.subspan(2).reinterpret_as(); + CHECK_EQUAL(data2.size(), 5); + + CHECK_THROW(data2 = data1.subspan(1).reinterpret_as(), etl::span_alignment_exception); + } + + //************************************************************************* + TEST(test_copy) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + uint8_t dst[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + { + etl::span data0 = src; + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + { + etl::span data0 = src; + etl::span data1(&dst[1], 5); + + CHECK_EQUAL(etl::copy(data0, data1), true); + CHECK(std::equal(data0.begin(), data0.end(), data1.begin())); + } + + { + etl::span data0 = src; + etl::span data1(&dst[2], 4); + + CHECK_EQUAL(etl::copy(data0, data1), false); + } + { + etl::span data0(&src[0], 0); + etl::span data1 = dst; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + { + etl::span data0 = src; + etl::span data1 = src; + + CHECK_EQUAL(etl::copy(data0, data1), true); + } + } + #include "etl/private/diagnostic_pop.h" }; } diff --git a/test/test_unaligned_type.cpp b/test/test_unaligned_type.cpp index be9ea1ec8..e80eeaebe 100644 --- a/test/test_unaligned_type.cpp +++ b/test/test_unaligned_type.cpp @@ -208,6 +208,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::le_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::le_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::le_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::le_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::le_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::le_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::le_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::le_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::le_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::le_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::le_uint64_t)); } //************************************************************************* @@ -236,6 +246,16 @@ namespace CHECK_EQUAL(sizeof(uint32_t), etl::be_uint32_t::Size); CHECK_EQUAL(sizeof(int64_t), etl::be_int64_t::Size); CHECK_EQUAL(sizeof(uint64_t), etl::be_uint64_t::Size); + + // check if net size equals gross size on platform + CHECK_EQUAL(sizeof(int8_t), sizeof(etl::be_int8_t)); + CHECK_EQUAL(sizeof(uint8_t), sizeof(etl::be_uint8_t)); + CHECK_EQUAL(sizeof(int16_t), sizeof(etl::be_int16_t)); + CHECK_EQUAL(sizeof(uint16_t), sizeof(etl::be_uint16_t)); + CHECK_EQUAL(sizeof(int32_t), sizeof(etl::be_int32_t)); + CHECK_EQUAL(sizeof(uint32_t), sizeof(etl::be_uint32_t)); + CHECK_EQUAL(sizeof(int64_t), sizeof(etl::be_int64_t)); + CHECK_EQUAL(sizeof(uint64_t), sizeof(etl::be_uint64_t)); } //************************************************************************* From ecf2966e4014df60b6dde3cd3682323c6152f5bd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Mar 2025 10:57:26 +0000 Subject: [PATCH 081/216] Minor format change --- include/etl/span.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 7b09adf46..5bb13e7ea 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -458,6 +458,16 @@ namespace etl : etl::span(pbegin + offset, pbegin + offset + count); } + //************************************************************************* + /// Moves the pointer to the first element of the span further by a specified number of elements. + ///\tparam elements Number of elements to move forward + //************************************************************************* + void advance(size_t elements) ETL_NOEXCEPT + { + elements = etl::min(elements, size()); + pbegin += elements; + } + //************************************************************************* /// Reinterpret the span as a span with different element type. //************************************************************************* @@ -467,7 +477,7 @@ namespace etl ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); return etl::span(reinterpret_cast(pbegin), - Extent * sizeof(element_type) / sizeof(TNew)); + Extent * sizeof(element_type) / sizeof(TNew)); } private: @@ -875,7 +885,7 @@ namespace etl ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); return etl::span(reinterpret_cast(pbegin), - (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); + (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); } private: From 9d74b9c0935e2b84fddbe4f34eca02229231d5f1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:26:39 +0000 Subject: [PATCH 082/216] Removed duplicated header includes --- include/etl/basic_string.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1a9f0c9b6..d7f139d56 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -38,13 +38,11 @@ SOFTWARE. #include "char_traits.h" #include "alignment.h" #include "array.h" -#include "algorithm.h" #include "type_traits.h" #include "error_handler.h" #include "integral_limits.h" #include "exception.h" #include "memory.h" -#include "exception.h" #include "binary.h" #include "flags.h" From 02c5933aff6d409595d4f1b9a7cd52aaf58a7baa Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:27:07 +0000 Subject: [PATCH 083/216] Updated bash test script help --- test/run-tests.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index 34af8d07f..fbd015195 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -54,14 +54,14 @@ PrintHeader() PrintHelp() { echo "$HelpColour" - echo "-------------------------------------------------------------------------------------" - echo " Syntax : ./runtests.sh " - echo " C++ Standard : 11, 14, 17 or 20 " - echo " Optimisation : 0, 1, 2 or 3. Default = 0 " - echo " Threads : Number of threads to use. Default = 4 " - echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " - echo " Compiler select : gcc or clang. Default All compilers " - echo "-------------------------------------------------------------------------------------" + echo "--------------------------------------------------------------------------------------------" + echo " Syntax : ./runtests.sh " + echo " C++ Standard : 11, 14, 17 or 20 " + echo " Optimisation : 0, 1, 2 or 3. Default = 0 " + echo " Threads : Number of threads to use. Default = 4 " + echo " Sanitizer : s enables sanitizer checks, n disables. Default disabled " + echo " Compiler : gcc or clang. Default All compilers " + echo "--------------------------------------------------------------------------------------------" echo "$NoColour" } From a6615a419d9c46b3031625e056ba35fe71a8f65f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 4 Mar 2025 09:27:39 +0000 Subject: [PATCH 084/216] Added unit tests for initializer_list construction --- test/test_intrusive_forward_list.cpp | 13 +++++++++++++ test/test_intrusive_list.cpp | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index d39ca7dc5..9e8544861 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -206,6 +206,19 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { diff --git a/test/test_intrusive_list.cpp b/test/test_intrusive_list.cpp index 9d5a08db4..45de60034 100644 --- a/test/test_intrusive_list.cpp +++ b/test/test_intrusive_list.cpp @@ -219,6 +219,19 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_initializer_list) + { + DataNDC0 data0 = { sorted_data[0], sorted_data[1], sorted_data[2], sorted_data[3], sorted_data[4], + sorted_data[5], sorted_data[6], sorted_data[7], sorted_data[8], sorted_data[9] }; + + CHECK(!data0.empty()); + CHECK_EQUAL(10, data0.size()); + + bool are_equal = std::equal(data0.begin(), data0.end(), sorted_data.begin()); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_begin_end) { From d9d9ae1e5327e09873763de1a9411c8276db7f5c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 9 Mar 2025 10:41:15 +0100 Subject: [PATCH 085/216] Add traits to type_list (#1044) --- include/etl/type_list.h | 91 +++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_type_list.cpp | 172 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 test/test_type_list.cpp diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 533ae7618..556787abe 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -30,7 +30,10 @@ SOFTWARE. #define ETL_TYPE_LIST_INCLUDED #include "platform.h" + +#include "algorithm.h" #include "nth_type.h" +#include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" @@ -38,6 +41,9 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { + + static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** /// Type list forward declaration. //*************************************************************************** @@ -61,6 +67,18 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; + namespace private_type_list + { + + // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition + template + struct recursion_helper + { + using type = type_list; + }; + + } + //*************************************************************************** /// Recursive type list implementation for multiple types. //*************************************************************************** @@ -68,6 +86,7 @@ namespace etl struct type_list : type_list { using type = THead; + using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -87,6 +106,7 @@ namespace etl struct type_list : type_list<> { using type = THead; + using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -180,6 +200,77 @@ namespace etl { using type = typename type_list_cat, TTail...>::type; }; + + template + struct type_list_contains + : public etl::integral_constant::value ? true : type_list_contains::value> + { + }; + + template + struct type_list_contains, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif + + template + struct type_list_index_of + : public etl::integral_constant::value ? 0 : + (type_list_index_of::value == type_list_npos ? + type_list_npos : type_list_index_of::value + 1)> + { + }; + + template + struct type_list_index_of, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; +#endif + + template + struct type_list_max_sizeof_type + : public etl::integral_constant::value)> + { + }; + + template<> + struct type_list_max_sizeof_type> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; +#endif + + template + struct type_list_max_alignment + : public etl::integral_constant::value, + type_list_max_alignment::value)> + { + }; + + template<> + struct type_list_max_alignment> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; +#endif } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bcc8a0da7..d2641ab5f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -286,6 +286,7 @@ add_executable(etl_tests test_to_u8string.cpp test_to_wstring.cpp test_type_def.cpp + test_type_list.cpp test_type_lookup.cpp test_type_select.cpp test_type_traits.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp new file mode 100644 index 000000000..44f197f8f --- /dev/null +++ b/test/test_type_list.cpp @@ -0,0 +1,172 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 BMW AG + +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 "unit_test_framework.h" + +#include "etl/type_list.h" + +#include + +namespace +{ +#if ETL_USING_CPP11 + SUITE(test_type_list) + { + //************************************************************************* + TEST(test_nth_type) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type, char>::value)); + CHECK_TRUE((std::is_same::type, int>::value)); + CHECK_TRUE((std::is_same::type, uint32_t>::value)); + } + + //************************************************************************* + TEST(test_type_list_select) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_TRUE((std::is_same::type, t2>::value)); + } + + //************************************************************************* + TEST(test_type_list_size) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_EQUAL(etl::type_list_size::value, 3); + CHECK_EQUAL(etl::type_list_size::value, 2); + } + + //************************************************************************* + TEST(test_type_list_cat) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + typedef etl::type_list t_cat1; + typedef etl::type_list t_cat2; + + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + } + + //************************************************************************* + TEST(test_type_list_contains) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_index_of) + { + typedef etl::type_list t1; + typedef etl::type_list<> t2; + + CHECK_EQUAL((etl::type_list_index_of::value), 0); + CHECK_EQUAL((etl::type_list_index_of::value), 1); + CHECK_EQUAL((etl::type_list_index_of::value), 2); + CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_index_of_v), 0); + CHECK_EQUAL((etl::type_list_index_of_v), 1); + CHECK_EQUAL((etl::type_list_index_of_v), 2); + CHECK_EQUAL((etl::type_list_index_of_v), etl::type_list_npos); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_sizeof_type) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_alignment) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, 1); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), 1); +#endif + } + + }; +#endif +} From 137a5f58f2acaf4edaf3f3e7b07d129a40317f93 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 9 Mar 2025 10:47:24 +0000 Subject: [PATCH 086/216] Added etl::type_list_type_at_index --- include/etl/type_list.h | 46 +++++++++++++++++++++++++++------ test/test_type_list.cpp | 14 ++++++++++ test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 5 +++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 556787abe..f4607dc95 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -41,8 +41,10 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { - - static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t type_list_npos = etl::integral_limits::max; //*************************************************************************** /// Type list forward declaration. @@ -69,14 +71,12 @@ namespace etl namespace private_type_list { - // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition template struct recursion_helper { using type = type_list; }; - } //*************************************************************************** @@ -201,6 +201,9 @@ namespace etl using type = typename type_list_cat, TTail...>::type; }; + //*************************************************************************** + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. + //*************************************************************************** template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> @@ -218,17 +221,21 @@ namespace etl inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif + //*************************************************************************** + /// Defines an integral constant that is the index of the specified type in the type_list. + /// If the type is not in the type_list, then defined as etl::type_list_npos. + //*************************************************************************** template struct type_list_index_of : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == type_list_npos ? - type_list_npos : type_list_index_of::value + 1)> + (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of::value + 1)> { }; template struct type_list_index_of, T> - : public etl::integral_constant + : public etl::integral_constant { }; @@ -237,6 +244,25 @@ namespace etl inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; #endif + //*************************************************************************** + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. + //*************************************************************************** + template + struct type_list_type_at_index + { + ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); + + using type = nth_type_t; + }; + + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; + + //*************************************************************************** + /// Defines an integral constant that is maximum sizeof all types in the type_list. + /// If the type_list is empty, then defined as 0. + //*************************************************************************** template struct type_list_max_sizeof_type : public etl::integral_constant::value)> @@ -254,10 +280,14 @@ namespace etl inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif + //*************************************************************************** + /// Defines an integral constant that is maximum alignment all types in the type_list. + /// If the type_list is empty, then defined as 1. + //*************************************************************************** template struct type_list_max_alignment : public etl::integral_constant::value, - type_list_max_alignment::value)> + type_list_max_alignment::value)> { }; diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 44f197f8f..49641e6f7 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -125,6 +125,20 @@ namespace #endif } + //************************************************************************* + TEST(test_type_list_type_at_index) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + //************************************************************************* TEST(test_type_list_max_sizeof_type) { diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index dfa03400a..b796f072d 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9453,6 +9453,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 5251ef8b5..d5ff0eef6 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1429,7 +1429,7 @@ UnitTest++\Header Files - UnitTest++\Header Files + ETL\Utilities @@ -3431,6 +3431,9 @@ Tests\Syntax Checks\Source + + Tests\Types + From 34f536548f8f0ab3d538fd5c7e1fa595108e3307 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 14 Mar 2025 15:46:25 +0000 Subject: [PATCH 087/216] Renamed type_list_index_of to type_list_index_of_type --- include/etl/type_list.h | 38 +++++++++++++++++++------------------- test/test_type_list.cpp | 10 +++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index f4607dc95..21ee103c0 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -204,20 +204,20 @@ namespace etl //*************************************************************************** /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template + template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> { }; - template + template struct type_list_contains, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif @@ -225,30 +225,30 @@ namespace etl /// Defines an integral constant that is the index of the specified type in the type_list. /// If the type is not in the type_list, then defined as etl::type_list_npos. //*************************************************************************** - template - struct type_list_index_of + template + struct type_list_index_of_type : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of::value + 1)> + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> { }; - template - struct type_list_index_of, T> + template + struct type_list_index_of_type, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; #endif //*************************************************************************** /// Defines type as the type found at Index in the type_list. /// Static asserts if Index is out of range. //*************************************************************************** - template + template struct type_list_type_at_index { ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); @@ -256,27 +256,27 @@ namespace etl using type = nth_type_t; }; - template + template using type_list_type_at_index_t = typename type_list_type_at_index::type; //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template + template struct type_list_max_sizeof_type : public etl::integral_constant::value)> { }; - template<> + template <> struct type_list_max_sizeof_type> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif @@ -284,21 +284,21 @@ namespace etl /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template + template struct type_list_max_alignment : public etl::integral_constant::value, type_list_max_alignment::value)> { }; - template<> + template <> struct type_list_max_alignment> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif } diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 49641e6f7..75c8f3226 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -107,15 +107,15 @@ namespace } //************************************************************************* - TEST(test_type_list_index_of) + TEST(test_type_list_index_of_type) { typedef etl::type_list t1; typedef etl::type_list<> t2; - CHECK_EQUAL((etl::type_list_index_of::value), 0); - CHECK_EQUAL((etl::type_list_index_of::value), 1); - CHECK_EQUAL((etl::type_list_index_of::value), 2); - CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + CHECK_EQUAL((etl::type_list_index_of_type::value), 0); + CHECK_EQUAL((etl::type_list_index_of_type::value), 1); + CHECK_EQUAL((etl::type_list_index_of_type::value), 2); + CHECK_EQUAL((etl::type_list_index_of_type::value), etl::type_list_npos); #if ETL_USING_CPP17 CHECK_EQUAL((etl::type_list_index_of_v), 0); From ebc588a47744eb1ae2b9c7560fac59a28751083f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:06:34 +0000 Subject: [PATCH 088/216] Added etl::index_of_type as a complement to etl::nth_type --- include/etl/index_of_type.h | 80 +++++++++++++++++++++++++++++++++++++ test/test_index_of_type.cpp | 58 +++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 include/etl/index_of_type.h create mode 100644 test/test_index_of_type.cpp diff --git a/include/etl/index_of_type.h b/include/etl/index_of_type.h new file mode 100644 index 000000000..5546ad533 --- /dev/null +++ b/include/etl/index_of_type.h @@ -0,0 +1,80 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_INDEX_OF_TYPE_INCLUDED +#define ETL_INDEX_OF_TYPE_INCLUDED + +#include "platform.h" +#include "static_assert.h" +#include "integral_limits.h" + +namespace etl +{ +#if ETL_USING_CPP11 + + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t index_of_type_npos = etl::integral_limits::max; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant::value ? 0 : + (etl::index_of_type::value == etl::index_of_type_npos ? etl::index_of_type_npos : + etl::index_of_type::value + 1)> + { + }; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + /// No types left. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + inline constexpr size_t index_of_type_v = etl::index_of_type::value; +#endif +#endif +} + +#endif diff --git a/test/test_index_of_type.cpp b/test/test_index_of_type.cpp new file mode 100644 index 000000000..60d211e8a --- /dev/null +++ b/test/test_index_of_type.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 "unit_test_framework.h" + +#include "etl/index_of_type.h" +#include + +namespace +{ + SUITE(test_index_of_type) + { + //************************************************************************* + TEST(test_index_of_type) + { + CHECK_EQUAL(0, (etl::index_of_type::value)); + CHECK_EQUAL(1, (etl::index_of_type::value)); + CHECK_EQUAL(2, (etl::index_of_type::value)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type::value)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_index_of_type_v) + { + CHECK_EQUAL(0, (etl::index_of_type_v)); + CHECK_EQUAL(1, (etl::index_of_type_v)); + CHECK_EQUAL(2, (etl::index_of_type_v)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type_v)); + } +#endif + } +} From a86b1240196462cfb7bbe97b551c43ae5aff5d4a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:07:25 +0000 Subject: [PATCH 089/216] Attempt to fix some sanitizer issues for tests --- include/etl/intrusive_forward_list.h | 5 ++++- test/test_map.cpp | 7 ++++--- test/test_multi_span.cpp | 14 ++------------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 6cb442806..7e6d4dba2 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -322,7 +322,10 @@ namespace etl if (p_next != &this->terminator) { link_type* p_unlinked = etl::unlink_after(link); - p_unlinked->clear(); + if (p_unlinked != ETL_NULLPTR) + { + p_unlinked->clear(); + } --current_size; } } diff --git a/test/test_map.cpp b/test/test_map.cpp index bd8817ce6..2c19e4e4e 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include #include "etl/map.h" +#include "etl/string.h" #include "data.h" @@ -1575,7 +1576,7 @@ namespace #if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST_FIXTURE(SetupFixture, test_map_template_deduction) { - using Pair = std::pair; + using Pair = std::pair, int>; etl::map data { Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5} }; @@ -1596,9 +1597,9 @@ namespace #if ETL_HAS_INITIALIZER_LIST TEST_FIXTURE(SetupFixture, test_make_map) { - using Pair = ETL_OR_STD::pair; + using Pair = ETL_OR_STD::pair, int>; - auto data = etl::make_map>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); + auto data = etl::make_map, int, std::less>>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); auto v = *data.begin(); using Type = decltype(v); diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 11c77196f..c3e20a6ee 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -341,14 +341,7 @@ namespace etl::multi_span::iterator ms_itr = ms_int.begin(); etl::multi_span::iterator ms_end_itr = ms_int.end(); - while (ms_itr != ms_end_itr) - { - // Fill the multi span - *ms_itr++ = *exp_itr++; - } - - ms_itr = ms_int.begin(); - exp_itr = expected.begin(); + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { @@ -554,10 +547,7 @@ namespace multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); - while (ms_itr != ms_end_itr) - { - *ms_itr++ = *exp_itr++; - } + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { From d4f1c89ff4dfce543a31ffacb9c6d7444e7a2e9e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:08:55 +0000 Subject: [PATCH 090/216] Refactored and simplified some features of etl::type_list Removed nth_type specialisation for etl::type_list --- include/etl/type_list.h | 198 +++++++++++++++----------------- test/CMakeLists.txt | 1 + test/test_type_list.cpp | 57 +++++---- test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 5 files changed, 129 insertions(+), 135 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 21ee103c0..4dbc66ec1 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -32,11 +32,12 @@ SOFTWARE. #include "platform.h" #include "algorithm.h" -#include "nth_type.h" +#include "index_of_type.h" #include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" +#include "largest.h" #if ETL_USING_CPP11 namespace etl @@ -85,7 +86,7 @@ namespace etl template struct type_list : type_list { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -105,7 +106,7 @@ namespace etl template struct type_list : type_list<> { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -119,50 +120,10 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list - //*************************************************************************** - template - struct nth_type> - { - ETL_STATIC_ASSERT(N <= sizeof...(TTail), "etl::nth_type out of range for etl::type_list"); - - using type = typename nth_type>::type; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list with index of 0 - //*************************************************************************** - template - struct nth_type<0, type_list> - { - using type = THead; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for empty etl::type_list - //*************************************************************************** - template - struct nth_type> - { - }; - - //*************************************************************************** - /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. - //*************************************************************************** - template - struct type_list_select - { - using type = type_list...>; - }; - - template - using type_list_select_t = typename type_list_select::type; - //*************************************************************************** /// Type list size. //*************************************************************************** - template + template struct type_list_size; template @@ -176,61 +137,38 @@ namespace etl #endif //*************************************************************************** - /// Concatenates two or more type_lists. - //*************************************************************************** - template - struct type_list_cat; - - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for a single type_list (base case) - //*************************************************************************** - template - struct type_list_cat - { - using type = TypeList; - }; - - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for two or more type_lists + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. //*************************************************************************** - template - struct type_list_cat, etl::type_list, TTail...> + template + struct type_list_type_at_index { - using type = typename type_list_cat, TTail...>::type; - }; + ETL_STATIC_ASSERT(Index < type_list_size::value, "etl::type_list_type_at_index out of range"); + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); - //*************************************************************************** - /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. - //*************************************************************************** - template - struct type_list_contains - : public etl::integral_constant::value ? true : type_list_contains::value> - { + using type = typename type_list_type_at_index::type; }; - template - struct type_list_contains, T> - : public etl::integral_constant + template + struct type_list_type_at_index { + using type = typename TTypeList::head; }; -#if ETL_USING_CPP17 - template - inline constexpr bool type_list_contains_v = etl::type_list_contains::value; -#endif + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; //*************************************************************************** /// Defines an integral constant that is the index of the specified type in the type_list. /// If the type is not in the type_list, then defined as etl::type_list_npos. //*************************************************************************** - template + template struct type_list_index_of_type - : public etl::integral_constant::value ? 0 : - (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of_type::value + 1)> + : public etl::integral_constant::value ? 0 : + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); }; template @@ -240,54 +178,67 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; #endif //*************************************************************************** - /// Defines type as the type found at Index in the type_list. - /// Static asserts if Index is out of range. + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template - struct type_list_type_at_index + template + struct type_list_contains; + + template + struct type_list_contains, T> + : public etl::integral_constant::value> { - ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); + }; - using type = nth_type_t; + template + struct type_list_contains, T> + : public etl::integral_constant + { }; - template - using type_list_type_at_index_t = typename type_list_type_at_index::type; +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template - struct type_list_max_sizeof_type - : public etl::integral_constant::value)> + template + struct type_list_max_size; + + template + struct type_list_max_size> + : public etl::integral_constant::size> { }; template <> - struct type_list_max_sizeof_type> + struct type_list_max_size> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; + template + inline constexpr size_t type_list_max_size_v = etl::type_list_max_size::value; #endif //*************************************************************************** /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template - struct type_list_max_alignment - : public etl::integral_constant::value, - type_list_max_alignment::value)> + template + struct type_list_max_alignment; + + template + struct type_list_max_alignment> + : public etl::integral_constant::alignment> { }; @@ -298,9 +249,44 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif + + //*************************************************************************** + /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. + //*************************************************************************** + template + struct type_list_select + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = type_list...>; + }; + + template + using type_list_select_t = typename type_list_select::type; + + //*************************************************************************** + /// Concatenates two or more type_lists. + //*************************************************************************** + template + struct type_list_cat; + + template + struct type_list_cat, etl::type_list, TTail...> + { + using type = typename type_list_cat, TTail...>::type; + }; + + template + struct type_list_cat + { + using type = T; + }; + + template + using type_list_cat_t = typename type_list_cat::type; } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2641ab5f..498fa7db2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,6 +149,7 @@ add_executable(etl_tests test_hfsm.cpp test_hfsm_recurse_to_inner_state_on_start.cpp test_histogram.cpp + test_index_of_type.cpp test_indirect_vector.cpp test_indirect_vector_external_buffer.cpp test_instance_count.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 75c8f3226..de9be9fc5 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -37,16 +37,6 @@ namespace #if ETL_USING_CPP11 SUITE(test_type_list) { - //************************************************************************* - TEST(test_nth_type) - { - typedef etl::type_list t1; - - CHECK_TRUE((std::is_same::type, char>::value)); - CHECK_TRUE((std::is_same::type, int>::value)); - CHECK_TRUE((std::is_same::type, uint32_t>::value)); - } - //************************************************************************* TEST(test_type_list_select) { @@ -54,6 +44,7 @@ namespace typedef etl::type_list t2; CHECK_TRUE((std::is_same::type, t2>::value)); + CHECK_TRUE((std::is_same, t2>::value)); } //************************************************************************* @@ -61,46 +52,54 @@ namespace { typedef etl::type_list t1; typedef etl::type_list t2; + typedef etl::type_list<> t3; CHECK_EQUAL(etl::type_list_size::value, 3); CHECK_EQUAL(etl::type_list_size::value, 2); + CHECK_EQUAL(etl::type_list_size::value, 0); } //************************************************************************* TEST(test_type_list_cat) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; + typedef etl::type_list<> t3; typedef etl::type_list t_cat1; - typedef etl::type_list t_cat2; + typedef etl::type_list t_cat2; - CHECK_TRUE((std::is_same::type, t_cat1>::value)); - CHECK_FALSE((std::is_same::type, t_cat2>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_FALSE((std::is_same, t_cat2>::value)); } //************************************************************************* TEST(test_type_list_contains) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); #if ETL_USING_CPP17 - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); #endif @@ -147,16 +146,16 @@ namespace typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 2); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 0); #if ETL_USING_CPP17 - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 2); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 0); #endif } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index b796f072d..808b085ac 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3169,6 +3169,7 @@ + @@ -8477,6 +8478,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index d5ff0eef6..f778794a4 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1431,6 +1431,9 @@ ETL\Utilities + + ETL\Utilities + @@ -3434,6 +3437,9 @@ Tests\Types + + Tests\Types + From 5d0a77dc76163bc743aa8a047c3f051b14d5f8cd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:09:41 +0000 Subject: [PATCH 091/216] Modified etl::variant_variadic to use etl::type_list in place of etl::parameter_pack --- include/etl/private/variant_variadic.h | 121 +++++-------------------- 1 file changed, 23 insertions(+), 98 deletions(-) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 443346694..6874f7f94 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -31,13 +31,14 @@ SOFTWARE. #include "../platform.h" #include "../utility.h" #include "../largest.h" +#include "../nth_type.h" #include "../exception.h" #include "../type_traits.h" #include "../integral_limits.h" #include "../static_assert.h" #include "../alignment.h" #include "../error_handler.h" -#include "../parameter_pack.h" +#include "../type_list.h" #include "../placement_new.h" #include "../visitor.h" #include "../memory.h" @@ -66,82 +67,6 @@ namespace etl { namespace private_variant { - //*************************************************************************** - // This is a copy of the normal etl::parameter_pack, but without the static_assert - // so that the C++11 versions of do_visitor() & do_operator() do not throw a compile time error. - //*************************************************************************** - template - class parameter_pack - { - public: - - static constexpr size_t size = sizeof...(TTypes); - - //*************************************************************************** - /// index_of_type - //*************************************************************************** - template - class index_of_type - { - private: - - using type = etl::remove_cvref_t; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_type_helper::value; - }; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = 1UL; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in parameter pack"); - - /// The index value. - static constexpr size_t value = index_of_type_helper::value - 1; - }; - - //*************************************************************************** - /// type_from_index - //*************************************************************************** - template - class type_from_index - { - private: - - //*********************************** - template - struct type_from_index_helper - { - using type = typename etl::conditional::type>::type; - }; - - //*********************************** - template - struct type_from_index_helper - { - using type = T1; - }; - - public: - - /// Template alias - using type = typename type_from_index_helper::type; - }; - - //*********************************** - template - using type_from_index_t = typename type_from_index::type; - }; - //******************************************* // The traits an object may have. //******************************************* @@ -327,7 +252,7 @@ namespace etl template struct variant_alternative> { - using type = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type = nth_type_t; }; template @@ -529,13 +454,13 @@ namespace etl // Get the index of a type. //******************************************* template - using index_of_type = typename etl::private_variant::parameter_pack::template index_of_type>; + using index_of_type = etl::type_list_index_of_type, etl::remove_cvref_t>; //******************************************* // Get the type from the index. //******************************************* template - using type_from_index = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type_from_index = typename etl::type_list_type_at_index, Index>::type; public: @@ -546,7 +471,7 @@ namespace etl #include "diagnostic_uninitialized_push.h" ETL_CONSTEXPR14 variant() { - using type = typename etl::private_variant::parameter_pack::template type_from_index<0U>::type; + using type = type_from_index<0U>; default_construct_in_place(data); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; @@ -592,7 +517,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, etl::forward(args)...); @@ -625,7 +550,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, std::initializer_list init, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, init, etl::forward(args)...); @@ -715,7 +640,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -737,7 +662,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -747,9 +672,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative>::type& emplace(TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -769,9 +694,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -803,7 +728,7 @@ namespace etl construct_in_place(data, etl::forward(value)); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *this; } @@ -896,7 +821,7 @@ namespace etl template (), int> = 0> constexpr bool is_type() const noexcept { - return (type_id == etl::private_variant::parameter_pack::template index_of_type::value); + return (type_id == index_of_type::value); } //*************************************************************************** @@ -1469,7 +1394,7 @@ namespace etl template ETL_CONSTEXPR14 bool holds_alternative(const etl::variant& v) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return (Index == variant_npos) ? false : (v.index() == Index); } @@ -1560,7 +1485,7 @@ namespace etl template ETL_CONSTEXPR14 T& get(etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1569,7 +1494,7 @@ namespace etl template ETL_CONSTEXPR14 T&& get(etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1578,7 +1503,7 @@ namespace etl template ETL_CONSTEXPR14 const T& get(const etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1587,7 +1512,7 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1628,7 +1553,7 @@ namespace etl template< class T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { @@ -1644,7 +1569,7 @@ namespace etl template< typename T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(const etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { From 4b3987c5e174d4f628a23c350f241a9a4ad83fcf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 17 Mar 2025 08:53:18 +0000 Subject: [PATCH 092/216] Reversed loop change --- test/test_multi_span.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index c3e20a6ee..19fbee95a 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -341,7 +341,14 @@ namespace etl::multi_span::iterator ms_itr = ms_int.begin(); etl::multi_span::iterator ms_end_itr = ms_int.end(); - std::copy(ms_itr, ms_end_itr, exp_itr); + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } + + ms_itr = ms_int.begin(); + exp_itr = expected.begin(); while (ms_itr != ms_end_itr) { @@ -547,7 +554,11 @@ namespace multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); - std::copy(ms_itr, ms_end_itr, exp_itr); + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } while (ms_itr != ms_end_itr) { From 418513f3f4b8331461aedba1d63ea13ab6022101 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Tue, 4 Mar 2025 04:44:13 -0500 Subject: [PATCH 093/216] Implement << operator for std basic_ostream and etl string_view (#1040) * Implement << operator for std basic_ostream and etl string_view * Implement << operator for std basic_ostream and etl ibasic_string. Still working through tests * Should be all tests * Fix comment --- include/etl/basic_string.h | 21 ++++++++++++ include/etl/string_view.h | 17 ++++++++++ test/test_string_char.cpp | 18 ++++++++++ test/test_string_char_external_buffer.cpp | 19 +++++++++++ test/test_string_u16.cpp | 18 ++++++++++ test/test_string_u16_external_buffer.cpp | 19 +++++++++++ test/test_string_u32.cpp | 18 ++++++++++ test/test_string_u32_external_buffer.cpp | 19 +++++++++++ test/test_string_u8.cpp | 18 ++++++++++ test/test_string_u8_external_buffer.cpp | 19 +++++++++++ test/test_string_view.cpp | 35 ++++++++++++++++++++ test/test_string_wchar_t.cpp | 18 ++++++++++ test/test_string_wchar_t_external_buffer.cpp | 19 +++++++++++ 13 files changed, 258 insertions(+) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index d7f139d56..40a8d0db7 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -54,6 +54,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include "private/minmax_push.h" //***************************************************************************** @@ -2962,6 +2966,23 @@ namespace etl { return !(lhs < rhs); } + + //*************************************************************************** + /// Operator overload to write to std basic_ostream + ///\param os Reference to the output stream. + ///\param str Reference to the string to write. + ///\return Reference to the output stream, for chaining write operations. + ///\ingroup string + //*************************************************************************** +#if ETL_USING_STL + template + std::basic_ostream > &operator<<(std::basic_ostream > &os, + const etl::ibasic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif } #include "private/minmax_pop.h" diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 82bd4502b..69cbe8366 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -47,6 +47,10 @@ SOFTWARE. #include #endif +#if ETL_USING_STL + #include +#endif + #include namespace etl @@ -972,6 +976,19 @@ void swap(etl::basic_string_view >& lhs, etl::basic_strin lhs.swap(rhs); } +//************************************************************************* +/// Operator overload to write to std basic_ostream +//************************************************************************* +#if ETL_USING_STL +template +std::basic_ostream > &operator<<(std::basic_ostream > &os, + etl::basic_string_view > text) +{ + os.write(text.data(), text.size()); + return os; +} +#endif + #include "private/minmax_pop.h" #endif diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 9a4f463ca..55e1bdb37 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -5310,5 +5310,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 1234e1703..a2593660b 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -5689,5 +5689,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index d2cb002b8..01ee5cf88 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index b7a2bfec1..ab7223e74 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 4c19a57d6..4f4c6cb0d 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -5324,5 +5324,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 5e8087267..1187091fe 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -5677,5 +5677,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 4f792225a..e105ed197 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -5327,6 +5327,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index df2724e56..1494e7084 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -5706,6 +5706,25 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::basic_stringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index afa1e6d33..598f63325 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -1120,5 +1120,40 @@ namespace CHECK_TRUE((u16view == U16View{ u"Hello World", etl::strlen(u"Hello World") })); CHECK_TRUE((u32view == U32View{ U"Hello World", etl::strlen(U"Hello World") })); } + + //************************************************************************* +#if ETL_USING_STL + TEST(write_to_std_stream) + { + View view{ "Hello World" }; + WView wview{ L"Hello World" }; + U16View u16view{ u"Hello World" }; + U32View u32view{ U"Hello World" }; + + std::stringstream sstream; + std::wstringstream wsstream; + std::basic_stringstream u16sstream; + std::basic_stringstream u32sstream; + + sstream << view; + std::string sstream_string = sstream.str(); + wsstream << wview; + std::wstring wsstream_string = wsstream.str(); + u16sstream << u16view; + std::u16string u16sstream_string = u16sstream.str(); + u32sstream << u32view; + std::u32string u32sstream_string = u32sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + WView wsstream_view(wsstream_string.data(), wsstream_string.size()); + U16View u16sstream_view(u16sstream_string.data(), u16sstream_string.size()); + U32View u32sstream_view(u32sstream_string.data(), u32sstream_string.size()); + + CHECK_TRUE(view == sstream_view); + CHECK_TRUE(wview == wsstream_view); + CHECK_TRUE(u16view == u16sstream_view); + CHECK_TRUE(u32view == u32sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 4eb16f41a..d28ba6d64 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -5325,5 +5325,23 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + Text text1 = STR("Hello World"); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 8bbbe4963..16cc52a8d 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -5680,5 +5680,24 @@ namespace #endif CHECK_EQUAL(text.max_size(), text.size()); } + + //************************************************************************* +#if ETL_USING_STL + TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) + { + TextBuffer buffer1{0}; + Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif }; } From 13bb9a6df829894845b88214b7ea71c55388213c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 17 Mar 2025 17:59:50 +0000 Subject: [PATCH 094/216] Comments for nth_type --- include/etl/nth_type.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index ca3534582..ac8091669 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -63,7 +63,7 @@ namespace etl }; //*************************************************************************** - /// Finds the 0th type in a variadic type parameter. + /// Handles a zero length type list. //*************************************************************************** template struct nth_type From 5852ab3b743007b8346aae08b31a8564e1a4cd69 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 18 Mar 2025 14:45:38 +0000 Subject: [PATCH 095/216] Refactored variant_variadic to use etl::nth_type for etl::variant_alternative implementation Refactored C++11 & C++14 support. --- .../etl/private/variant_select_do_operator.h | 1020 +++++++++++++++++ .../etl/private/variant_select_do_visitor.h | 1020 +++++++++++++++++ include/etl/private/variant_variadic.h | 239 +--- test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 5 files changed, 2088 insertions(+), 199 deletions(-) create mode 100644 include/etl/private/variant_select_do_operator.h create mode 100644 include/etl/private/variant_select_do_visitor.h diff --git a/include/etl/private/variant_select_do_operator.h b/include/etl/private/variant_select_do_operator.h new file mode 100644 index 000000000..c4b125d00 --- /dev/null +++ b/include/etl/private/variant_select_do_operator.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_operator inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_operator; + + //*************************************************************************** + template <> + struct select_do_operator<1> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<2> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_operator<3> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<4> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<5> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<6> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<7> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<8> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<9> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<10> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<11> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<12> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<13> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<14> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<15> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<16> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<17> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<18> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<19> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<20> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<21> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<22> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<23> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<24> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_operator<25> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<26> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<27> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<28> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<29> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<30> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<31> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_operator<32> + { + template + static void do_operator(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor(etl::get<0>(the_variant)); break; } + case 1: { visitor(etl::get<1>(the_variant)); break; } + case 2: { visitor(etl::get<2>(the_variant)); break; } + case 3: { visitor(etl::get<3>(the_variant)); break; } + case 4: { visitor(etl::get<4>(the_variant)); break; } + case 5: { visitor(etl::get<5>(the_variant)); break; } + case 6: { visitor(etl::get<6>(the_variant)); break; } + case 7: { visitor(etl::get<7>(the_variant)); break; } + case 8: { visitor(etl::get<8>(the_variant)); break; } + case 9: { visitor(etl::get<9>(the_variant)); break; } + case 10: { visitor(etl::get<10>(the_variant)); break; } + case 11: { visitor(etl::get<11>(the_variant)); break; } + case 12: { visitor(etl::get<12>(the_variant)); break; } + case 13: { visitor(etl::get<13>(the_variant)); break; } + case 14: { visitor(etl::get<14>(the_variant)); break; } + case 15: { visitor(etl::get<15>(the_variant)); break; } + case 16: { visitor(etl::get<16>(the_variant)); break; } + case 17: { visitor(etl::get<17>(the_variant)); break; } + case 18: { visitor(etl::get<18>(the_variant)); break; } + case 19: { visitor(etl::get<19>(the_variant)); break; } + case 20: { visitor(etl::get<20>(the_variant)); break; } + case 21: { visitor(etl::get<21>(the_variant)); break; } + case 22: { visitor(etl::get<22>(the_variant)); break; } + case 23: { visitor(etl::get<23>(the_variant)); break; } + case 24: { visitor(etl::get<24>(the_variant)); break; } + case 25: { visitor(etl::get<25>(the_variant)); break; } + case 26: { visitor(etl::get<26>(the_variant)); break; } + case 27: { visitor(etl::get<27>(the_variant)); break; } + case 28: { visitor(etl::get<28>(the_variant)); break; } + case 29: { visitor(etl::get<29>(the_variant)); break; } + case 30: { visitor(etl::get<30>(the_variant)); break; } + case 31: { visitor(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_select_do_visitor.h b/include/etl/private/variant_select_do_visitor.h new file mode 100644 index 000000000..b6e5bc500 --- /dev/null +++ b/include/etl/private/variant_select_do_visitor.h @@ -0,0 +1,1020 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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. +******************************************************************************/ + +//*************************************************************************** +// This file is included in variant_variadic.h for C++11 and C++14, as they +// do not support template fold expressions. +//*************************************************************************** + +namespace private_variant +{ + //*************************************************************************** + // Selects a do_visitor inplementation that is configured for the number of types. + //*************************************************************************** + template + struct select_do_visitor; + + //*************************************************************************** + template <> + struct select_do_visitor<1> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<2> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + default: break; + } + } + }; + + //*************************************************************************** + template <> + struct select_do_visitor<3> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<4> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<5> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<6> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<7> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<8> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<9> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<10> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<11> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<12> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<13> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<14> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<15> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<16> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<17> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<18> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<19> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<20> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<21> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<22> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<23> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<24> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + default: break; + } + }; + }; +#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) + //*************************************************************************** + template <> + struct select_do_visitor<25> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<26> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<27> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<28> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<29> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<30> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<31> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + default: break; + } + }; + }; + + //*************************************************************************** + template <> + struct select_do_visitor<32> + { + template + static void do_visitor(TVariant& the_variant, TVisitor& visitor) + { + switch (the_variant.index()) + { + case 0: { visitor.visit(etl::get<0>(the_variant)); break; } + case 1: { visitor.visit(etl::get<1>(the_variant)); break; } + case 2: { visitor.visit(etl::get<2>(the_variant)); break; } + case 3: { visitor.visit(etl::get<3>(the_variant)); break; } + case 4: { visitor.visit(etl::get<4>(the_variant)); break; } + case 5: { visitor.visit(etl::get<5>(the_variant)); break; } + case 6: { visitor.visit(etl::get<6>(the_variant)); break; } + case 7: { visitor.visit(etl::get<7>(the_variant)); break; } + case 8: { visitor.visit(etl::get<8>(the_variant)); break; } + case 9: { visitor.visit(etl::get<9>(the_variant)); break; } + case 10: { visitor.visit(etl::get<10>(the_variant)); break; } + case 11: { visitor.visit(etl::get<11>(the_variant)); break; } + case 12: { visitor.visit(etl::get<12>(the_variant)); break; } + case 13: { visitor.visit(etl::get<13>(the_variant)); break; } + case 14: { visitor.visit(etl::get<14>(the_variant)); break; } + case 15: { visitor.visit(etl::get<15>(the_variant)); break; } + case 16: { visitor.visit(etl::get<16>(the_variant)); break; } + case 17: { visitor.visit(etl::get<17>(the_variant)); break; } + case 18: { visitor.visit(etl::get<18>(the_variant)); break; } + case 19: { visitor.visit(etl::get<19>(the_variant)); break; } + case 20: { visitor.visit(etl::get<20>(the_variant)); break; } + case 21: { visitor.visit(etl::get<21>(the_variant)); break; } + case 22: { visitor.visit(etl::get<22>(the_variant)); break; } + case 23: { visitor.visit(etl::get<23>(the_variant)); break; } + case 24: { visitor.visit(etl::get<24>(the_variant)); break; } + case 25: { visitor.visit(etl::get<25>(the_variant)); break; } + case 26: { visitor.visit(etl::get<26>(the_variant)); break; } + case 27: { visitor.visit(etl::get<27>(the_variant)); break; } + case 28: { visitor.visit(etl::get<28>(the_variant)); break; } + case 29: { visitor.visit(etl::get<29>(the_variant)); break; } + case 30: { visitor.visit(etl::get<30>(the_variant)); break; } + case 31: { visitor.visit(etl::get<31>(the_variant)); break; } + default: break; + } + }; + }; +#endif +#endif +#endif +} diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 6874f7f94..04b16f8d1 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -70,16 +70,16 @@ namespace etl //******************************************* // The traits an object may have. //******************************************* - static constexpr bool Copyable = true; + static constexpr bool Copyable = true; static constexpr bool Non_Copyable = false; - static constexpr bool Moveable = true; + static constexpr bool Moveable = true; static constexpr bool Non_Moveable = false; //******************************************* // The types of operations we can perform. //******************************************* - static constexpr int Copy = 0; - static constexpr int Move = 1; + static constexpr int Copy = 0; + static constexpr int Move = 1; static constexpr int Destroy = 2; //******************************************* @@ -93,7 +93,7 @@ namespace etl template <> struct operation_type { - static void do_operation(int , char* , const char* ) + static void do_operation(int, char*, const char*) { // This should never occur. #if defined(ETL_IN_UNIT_TEST) @@ -120,9 +120,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -153,9 +153,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -186,9 +186,9 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) +#if defined(ETL_IN_UNIT_TEST) assert(false); - #endif +#endif break; } } @@ -245,14 +245,14 @@ namespace etl //*************************************************************************** /// variant_alternative - //*************************************************************************** + //*************************************************************************** template struct variant_alternative; template struct variant_alternative> { - using type = nth_type_t; + using type = etl::nth_type_t; }; template @@ -299,6 +299,11 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v); +#if ETL_NOT_USING_CPP17 + #include "variant_select_do_visitor.h" + #include "variant_select_do_operator.h" +#endif + //*************************************************************************** /// Monostate for variants. ///\ingroup variant @@ -672,7 +677,7 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative_t>& emplace(TArgs&&... args) { static_assert(Index < sizeof...(TTypes), "Index out of range"); @@ -694,7 +699,7 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative_t>& emplace(std::initializer_list il, TArgs&&... args) { static_assert(Index < sizeof...(TTypes), "Index out of range"); @@ -862,7 +867,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -876,7 +881,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -890,7 +895,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -904,7 +909,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -921,7 +926,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -938,7 +943,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_visitor(v, etl::make_index_sequence{}); #else - do_visitor(v); + do_visitor(v); #endif } @@ -955,7 +960,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -972,7 +977,7 @@ namespace etl #if ETL_USING_CPP17 && !defined(ETL_VARIANT_FORCE_CPP11) do_operator(v, etl::make_index_sequence{}); #else - do_operator(v); + do_operator(v); #endif } @@ -1045,103 +1050,21 @@ namespace etl } #else //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } //*************************************************************************** - /// /// Call the relevant visitor. + /// Call the relevant visitor. //*************************************************************************** - template + template void do_visitor(TVisitor& visitor) const { - switch (index()) - { - case 0: { visitor.visit(etl::get<0>(*this)); break; } - case 1: { visitor.visit(etl::get<1>(*this)); break; } - case 2: { visitor.visit(etl::get<2>(*this)); break; } - case 3: { visitor.visit(etl::get<3>(*this)); break; } - case 4: { visitor.visit(etl::get<4>(*this)); break; } - case 5: { visitor.visit(etl::get<5>(*this)); break; } - case 6: { visitor.visit(etl::get<6>(*this)); break; } - case 7: { visitor.visit(etl::get<7>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: { visitor.visit(etl::get<8>(*this)); break; } - case 9: { visitor.visit(etl::get<9>(*this)); break; } - case 10: { visitor.visit(etl::get<10>(*this)); break; } - case 11: { visitor.visit(etl::get<11>(*this)); break; } - case 12: { visitor.visit(etl::get<12>(*this)); break; } - case 13: { visitor.visit(etl::get<13>(*this)); break; } - case 14: { visitor.visit(etl::get<14>(*this)); break; } - case 15: { visitor.visit(etl::get<15>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: { visitor.visit(etl::get<16>(*this)); break; } - case 17: { visitor.visit(etl::get<17>(*this)); break; } - case 18: { visitor.visit(etl::get<18>(*this)); break; } - case 19: { visitor.visit(etl::get<19>(*this)); break; } - case 20: { visitor.visit(etl::get<20>(*this)); break; } - case 21: { visitor.visit(etl::get<21>(*this)); break; } - case 22: { visitor.visit(etl::get<22>(*this)); break; } - case 23: { visitor.visit(etl::get<23>(*this)); break; } -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: { visitor.visit(etl::get<24>(*this)); break; } - case 25: { visitor.visit(etl::get<25>(*this)); break; } - case 26: { visitor.visit(etl::get<26>(*this)); break; } - case 27: { visitor.visit(etl::get<27>(*this)); break; } - case 28: { visitor.visit(etl::get<28>(*this)); break; } - case 29: { visitor.visit(etl::get<29>(*this)); break; } - case 30: { visitor.visit(etl::get<30>(*this)); break; } - case 31: { visitor.visit(etl::get<31>(*this)); break; } -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_visitor::do_visitor(*this, visitor); } #endif @@ -1207,9 +1130,9 @@ namespace etl } #else //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1226,54 +1149,13 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } //*************************************************************************** - /// Call the relevant visitor. + /// Call the relevant operator. //*************************************************************************** - template + template void do_operator(TVisitor& visitor) const { #if defined(ETL_VARIANT_CPP11_MAX_8_TYPES) @@ -1290,48 +1172,7 @@ namespace etl ETL_STATIC_ASSERT(sizeof...(TTypes) <= 32U, "A maximum of 32 types are allowed in this variant"); - switch (index()) - { - case 0: visitor(etl::get<0>(*this)); break; - case 1: visitor(etl::get<1>(*this)); break; - case 2: visitor(etl::get<2>(*this)); break; - case 3: visitor(etl::get<3>(*this)); break; - case 4: visitor(etl::get<4>(*this)); break; - case 5: visitor(etl::get<5>(*this)); break; - case 6: visitor(etl::get<6>(*this)); break; - case 7: visitor(etl::get<7>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_8_TYPES) - case 8: visitor(etl::get<8>(*this)); break; - case 9: visitor(etl::get<9>(*this)); break; - case 10: visitor(etl::get<10>(*this)); break; - case 11: visitor(etl::get<11>(*this)); break; - case 12: visitor(etl::get<12>(*this)); break; - case 13: visitor(etl::get<13>(*this)); break; - case 14: visitor(etl::get<14>(*this)); break; - case 15: visitor(etl::get<15>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_16_TYPES) - case 16: visitor(etl::get<16>(*this)); break; - case 17: visitor(etl::get<17>(*this)); break; - case 18: visitor(etl::get<18>(*this)); break; - case 19: visitor(etl::get<19>(*this)); break; - case 20: visitor(etl::get<20>(*this)); break; - case 21: visitor(etl::get<21>(*this)); break; - case 22: visitor(etl::get<22>(*this)); break; - case 23: visitor(etl::get<23>(*this)); break; -#if !defined(ETL_VARIANT_CPP11_MAX_24_TYPES) - case 24: visitor(etl::get<24>(*this)); break; - case 25: visitor(etl::get<25>(*this)); break; - case 26: visitor(etl::get<26>(*this)); break; - case 27: visitor(etl::get<27>(*this)); break; - case 28: visitor(etl::get<28>(*this)); break; - case 29: visitor(etl::get<29>(*this)); break; - case 30: visitor(etl::get<30>(*this)); break; - case 31: visitor(etl::get<31>(*this)); break; -#endif -#endif -#endif - default: break; - } + etl::private_variant::select_do_operator::do_operator(*this, visitor); } #endif diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 808b085ac..306e5ea6b 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3185,6 +3185,8 @@ + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index f778794a4..a047f4305 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1434,6 +1434,12 @@ ETL\Utilities + + ETL\Private + + + ETL\Private + From 4f05fbaca1dd643f88a4e8022d6170e9fe9fbc5c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 18 Mar 2025 15:53:51 +0000 Subject: [PATCH 096/216] Added instructions --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aa9253af5..3c1aa1c9c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,4 +10,4 @@ If your are considering creating a pull request, please observe the following: There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang. If you are thinking of adding a new feature then raise this on the GitHub Issues page for disccussion as the maintainers and user of the ETL may have questions or suggestions. -It is possible that the maintainer of the ETL or another contributor is already working on the same or a related feature. +It is possible that the maintainer of the ETL or another contributor is already working on the same or related feature. From c1cc9f584b60f722320d1b5a70a24fbeb57213d5 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Tue, 25 Mar 2025 14:16:44 -0400 Subject: [PATCH 097/216] Potential fix for span construct (#1051) * Try fix for span constructors * Make base class public --- include/etl/span.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 5bb13e7ea..b7291b9a4 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -59,6 +59,8 @@ SOFTWARE. namespace etl { + //empty base optimization means this has zero size + class span_base {}; //*************************************************************************** ///\ingroup span /// Exception base for span @@ -91,7 +93,7 @@ namespace etl /// Span - Fixed Extent //*************************************************************************** template - class span + class span : public span_base { public: @@ -145,7 +147,8 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value&& etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT @@ -190,7 +193,7 @@ namespace etl /// Copy constructor //************************************************************************* template - ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type* = 0) ETL_NOEXCEPT : pbegin(other.data()) { } @@ -565,7 +568,8 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && + !etl::is_pointer>::value && !etl::is_array>::value && etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT From aacde24aa58d06076b87e52616baa14353d76760 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 25 Mar 2025 19:47:32 +0000 Subject: [PATCH 098/216] Changed span_base to span_tag Removed #include of --- include/etl/span.h | 41 ++++++++++++++++++--------------- test/test_span_fixed_extent.cpp | 9 ++++++++ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index b7291b9a4..4995d747a 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -50,15 +50,16 @@ SOFTWARE. #include "private/dynamic_extent.h" -#if ETL_USING_CPP20 && ETL_USING_STL - #include -#endif - ///\defgroup span span ///\ingroup containers namespace etl { + //*************************************************************************** + // Tag to indicate a class is a span. + //*************************************************************************** + class span_tag {}; + //empty base optimization means this has zero size class span_base {}; //*************************************************************************** @@ -93,7 +94,7 @@ namespace etl /// Span - Fixed Extent //*************************************************************************** template - class span : public span_base + class span : public span_tag { public: @@ -147,11 +148,11 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && !etl::is_pointer>::value && !etl::is_array>::value&& etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -161,7 +162,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - span(TContainer& a, typename etl::enable_if::type>::value && + span(TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -173,9 +175,10 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && - !etl::is_array::value&& - etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT + span(const TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && + !etl::is_array::value&& + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -417,14 +420,14 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { // If Extent is static, check that OFFSET is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) ? OFFSET <= Extent : true, "OFFSET is not within the original span"); // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, (pbegin + Extent)) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); } @@ -440,7 +443,7 @@ namespace etl // If count is also static, check that OFFSET + COUNT is within the original span ETL_STATIC_ASSERT((Extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (Extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); - + if (COUNT == etl::dynamic_extent) { return etl::span(pbegin + OFFSET, (pbegin + Extent)); @@ -513,7 +516,7 @@ namespace etl typedef const T& const_reference; typedef T* pointer; typedef const T* const_pointer; - + typedef T* iterator; typedef const T* const_iterator; typedef ETL_OR_STD::reverse_iterator reverse_iterator; @@ -568,11 +571,11 @@ namespace etl /// Construct from a container or other type that supports /// data() and size() member functions. //************************************************************************* - template >::value && + template >::value && !etl::is_pointer>::value && !etl::is_array>::value && etl::is_same, etl::remove_cv_t::value_type>>::value, void>::type> - ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT + ETL_CONSTEXPR span(TContainer&& a) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -838,7 +841,7 @@ namespace etl //************************************************************************* template ETL_NODISCARD ETL_CONSTEXPR - etl::span subspan() const ETL_NOEXCEPT + etl::span subspan() const ETL_NOEXCEPT { return (COUNT == etl::dynamic_extent) ? etl::span(pbegin + OFFSET, pend) : etl::span(pbegin + OFFSET, pbegin + OFFSET + COUNT); @@ -1063,4 +1066,4 @@ namespace etl } } -#endif +#endif \ No newline at end of file diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 1440fde70..4ae305535 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -1167,6 +1167,15 @@ namespace } } + //************************************************************************* + TEST(test_span_issue_1050_questions_on_span_constructors) + { + int arr[5]{}; + etl::span span1(arr); + etl::span span2(span1); + //etl::span span3(span1); // This line should fail to compile. + } + //************************************************************************* TEST(test_reinterpret_as) { From 92cc068f5200490c9a0c692cbcd2459a6fc5eaae Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 26 Mar 2025 08:34:13 +0000 Subject: [PATCH 099/216] Added etl::monostate as a separate header monostate.h so that it can be used without have to include variant.h --- include/etl/monostate.h | 46 ++++++++++++++++++++++++++ include/etl/private/variant_legacy.h | 5 ++- include/etl/private/variant_variadic.h | 9 +---- test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 3 ++ 5 files changed, 53 insertions(+), 11 deletions(-) create mode 100644 include/etl/monostate.h diff --git a/include/etl/monostate.h b/include/etl/monostate.h new file mode 100644 index 000000000..eb7877bf5 --- /dev/null +++ b/include/etl/monostate.h @@ -0,0 +1,46 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 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_MONOSTATE_INCLUDED +#define ETL_MONOSTATE_INCLUDED + +#include "platform.h" + +namespace etl +{ + //*************************************************************************** + /// A 'no-value' placeholder. + //*************************************************************************** + struct monostate + { + }; +} + +#endif diff --git a/include/etl/private/variant_legacy.h b/include/etl/private/variant_legacy.h index 3c0e788e6..d6eb539ae 100644 --- a/include/etl/private/variant_legacy.h +++ b/include/etl/private/variant_legacy.h @@ -40,6 +40,7 @@ SOFTWARE. #include "../error_handler.h" #include "../null_type.h" #include "../placement_new.h" +#include "../monostate.h" #include @@ -75,9 +76,7 @@ namespace etl /// Monostate for variants. ///\ingroup variant //*************************************************************************** - struct monostate - { - }; + typedef etl::monostate monostate; //*************************************************************************** /// Base exception for the variant class. diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 04b16f8d1..8e6874601 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -44,6 +44,7 @@ SOFTWARE. #include "../memory.h" #include "../compare.h" #include "../initializer_list.h" +#include "../monostate.h" #include @@ -304,14 +305,6 @@ namespace etl #include "variant_select_do_operator.h" #endif - //*************************************************************************** - /// Monostate for variants. - ///\ingroup variant - //*************************************************************************** - struct monostate - { - }; - constexpr bool operator >(etl::monostate, etl::monostate) noexcept { return false; } constexpr bool operator <(etl::monostate, etl::monostate) noexcept { return false; } constexpr bool operator !=(etl::monostate, etl::monostate) noexcept { return false; } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 306e5ea6b..fde32d913 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3173,6 +3173,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index a047f4305..322cefa3f 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1440,6 +1440,9 @@ ETL\Private + + ETL\Utilities + From 9953c4d139806296f221e936d5a5ee627da01f21 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 26 Mar 2025 13:17:23 +0100 Subject: [PATCH 100/216] Returning const ref of member from const member function (#1052) The `const` marked function needs to return a `const` reference to a member variable Co-authored-by: Andreas Pelczer --- include/etl/expected.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/etl/expected.h b/include/etl/expected.h index 3f1abd999..fd68ac858 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -188,7 +188,7 @@ namespace etl //******************************************* /// Get the error. - //******************************************* + //******************************************* ETL_CONSTEXPR14 TError&& error() const&& ETL_NOEXCEPT { return etl::move(error_value); @@ -500,7 +500,7 @@ namespace etl //******************************************* /// Get the value. //******************************************* - value_type& value() const + const value_type& value() const { return etl::get(storage); } @@ -660,7 +660,7 @@ namespace etl //******************************************* /// //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -932,7 +932,7 @@ namespace etl /// Returns the error /// Undefined behaviour if an error has not been set. //******************************************* - error_type& error() const + const error_type& error() const { return etl::get(storage); } @@ -1107,4 +1107,3 @@ void swap(etl::unexpected& lhs, etl::unexpected& rhs) } #endif - From 077518f4fb5070e2e4055b353c4ea48314db6eec Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Mar 2025 10:07:21 +0000 Subject: [PATCH 101/216] Added ETL_ASSERT for copy construction of dynamic span to fixed span Asserts if the sizes are not equal --- include/etl/span.h | 49 +++++++++++++++++++++++++++++---- test/test_span_fixed_extent.cpp | 15 ++++++++++ 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 4995d747a..f4082488e 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -90,6 +90,20 @@ namespace etl } }; + //*************************************************************************** + ///\ingroup span + /// span size exception. + //*************************************************************************** + class span_size_mismatch : public span_exception + { + public: + + span_size_mismatch(string_type file_name_, numeric_type line_number_) + : span_exception(ETL_ERROR_TEXT("span:size", ETL_SPAN_FILE_ID"B"), file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Span - Fixed Extent //*************************************************************************** @@ -137,11 +151,22 @@ namespace etl //************************************************************************* /// Construct from C array //************************************************************************* - template::type> +#if ETL_USING_CPP11 + template::type> ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT : pbegin(begin_) { } +#else + //************************************************************************* + /// Construct from C array + //************************************************************************* + template + ETL_CONSTEXPR span(element_type(&begin_)[Array_Size], typename etl::enable_if<(Array_Size == Extent), void>::type* = 0) ETL_NOEXCEPT + : pbegin(begin_) + { + } +#endif #if ETL_USING_CPP11 //************************************************************************* @@ -194,11 +219,23 @@ namespace etl //************************************************************************* /// Copy constructor + /// From fixed extent span. + //************************************************************************* + template + ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if::type* = 0) ETL_NOEXCEPT + : pbegin(other.data()) + { + } + + //************************************************************************* + /// Copy constructor + /// From dynamic extent span. //************************************************************************* template - ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if<(Extent == etl::dynamic_extent) || (N == etl::dynamic_extent) || (N == Extent), void>::type* = 0) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if::type* = 0) : pbegin(other.data()) { + ETL_ASSERT(other.size() == Extent, ETL_ERROR(span_size_mismatch)); } //************************************************************************* @@ -505,7 +542,7 @@ namespace etl /// Span - Dynamic Extent //*************************************************************************** template - class span + class span : public span_tag { public: @@ -586,7 +623,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(TContainer& a, typename etl::enable_if::type>::value && + ETL_CONSTEXPR span(TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) @@ -599,7 +637,8 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && + ETL_CONSTEXPR span(const TContainer& a, typename etl::enable_if::type>::value && + !etl::is_pointer::type>::value && !etl::is_array::value && etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 4ae305535..511b5ae9d 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -1245,6 +1245,21 @@ namespace } } + //************************************************************************* + TEST(test_dynamic_span_to_larger_fixed_span) + { + int data[5] = { 0, 1, 2, 3, 4 }; + etl::span sp1(data); + + using span_4 = etl::span; + using span_5 = etl::span; + using span_8 = etl::span; + + CHECK_NO_THROW({ span_5 sp2(sp1); }); + CHECK_THROW({ span_4 sp3(sp1); }, etl::span_size_mismatch); + CHECK_THROW({ span_8 sp4(sp1); }, etl::span_size_mismatch); + } + #include "etl/private/diagnostic_pop.h" }; } From 7e85fd7926324476259e69f243e9e96d3424705e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Mar 2025 11:16:08 +0000 Subject: [PATCH 102/216] #1057 ETL_DECLARE_DEBUG_COUNT increases RAM usage even when ETL_DEBUG_COUNT NOT defined --- include/etl/debug_count.h | 27 ++++++++++----------------- test/etl_profile.h | 2 +- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/include/etl/debug_count.h b/include/etl/debug_count.h index ebbfb13ef..9e15c21af 100644 --- a/include/etl/debug_count.h +++ b/include/etl/debug_count.h @@ -158,23 +158,16 @@ inline void swap(etl::debug_count& lhs, etl::debug_count& rhs) } #else - #define ETL_DECLARE_DEBUG_COUNT etl::debug_count etl_debug_count - #define ETL_SET_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_GET_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_INCREMENT_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_DECREMENT_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_ADD_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_SUBTRACT_DEBUG_COUNT(n) ETL_DO_NOTHING - #define ETL_RESET_DEBUG_COUNT ETL_DO_NOTHING - #define ETL_OBJECT_RESET_DEBUG_COUNT(object) ETL_DO_NOTHING - #define ETL_OBJECT_GET_DEBUG_COUNT(object) ETL_DO_NOTHING - -namespace etl -{ - class debug_count - { - }; -} + #define ETL_DECLARE_DEBUG_COUNT + #define ETL_SET_DEBUG_COUNT(n) + #define ETL_GET_DEBUG_COUNT + #define ETL_INCREMENT_DEBUG_COUNT + #define ETL_DECREMENT_DEBUG_COUNT + #define ETL_ADD_DEBUG_COUNT(n) + #define ETL_SUBTRACT_DEBUG_COUNT(n) + #define ETL_RESET_DEBUG_COUNT + #define ETL_OBJECT_RESET_DEBUG_COUNT(object) + #define ETL_OBJECT_GET_DEBUG_COUNT(object) #endif // ETL_DEBUG_COUNT #endif diff --git a/test/etl_profile.h b/test/etl_profile.h index 38ec2abe0..9a2fc3bd3 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_IDEQUE_REPAIR_ENABLE #define ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE #define ETL_IN_UNIT_TEST -#define ETL_DEBUG_COUNT +//#define ETL_DEBUG_COUNT #define ETL_ARRAY_VIEW_IS_MUTABLE #define ETL_MESSAGE_TIMER_USE_ATOMIC_LOCK From 60041bf56a13d0f642053440b7c4a144e7e1b517 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Mar 2025 11:19:20 +0000 Subject: [PATCH 103/216] #1057 ETL_DECLARE_DEBUG_COUNT increases RAM usage even when ETL_DEBUG_COUNT NOT defined --- include/etl/span.h | 2 +- test/etl_profile.h | 2 +- test/vs2022/etl.sln | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index bb30cea55..a9d4d7210 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -230,7 +230,7 @@ namespace etl /// From dynamic extent span. //************************************************************************* template - ETL_CONSTEXPR span(const etl::span& other, typename etl::enable_if::type* = 0) + span(const etl::span& other, typename etl::enable_if::type* = 0) : pbegin(other.data()) { ETL_ASSERT(other.size() == Extent, ETL_ERROR(span_size_mismatch)); diff --git a/test/etl_profile.h b/test/etl_profile.h index 9a2fc3bd3..38ec2abe0 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_IDEQUE_REPAIR_ENABLE #define ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE #define ETL_IN_UNIT_TEST -//#define ETL_DEBUG_COUNT +#define ETL_DEBUG_COUNT #define ETL_ARRAY_VIEW_IS_MUTABLE #define ETL_MESSAGE_TIMER_USE_ATOMIC_LOCK diff --git a/test/vs2022/etl.sln b/test/vs2022/etl.sln index 4f341db84..c002c8f2e 100644 --- a/test/vs2022/etl.sln +++ b/test/vs2022/etl.sln @@ -17,10 +17,10 @@ Global Debug MSVC C++17 - No STL|x64 = Debug MSVC C++17 - No STL|x64 Debug MSVC C++17|Win32 = Debug MSVC C++17|Win32 Debug MSVC C++17|x64 = Debug MSVC C++17|x64 + Debug MSVC C++20 - Force C++03 - No virtual messages|Win32 = Debug MSVC C++20 - Force C++03 - No virtual messages|Win32 + Debug MSVC C++20 - Force C++03 - No virtual messages|x64 = Debug MSVC C++20 - Force C++03 - No virtual messages|x64 Debug MSVC C++20 - Force C++03|Win32 = Debug MSVC C++20 - Force C++03|Win32 Debug MSVC C++20 - Force C++03|x64 = Debug MSVC C++20 - Force C++03|x64 - Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 - Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 Debug MSVC C++20 - No STL|Win32 = Debug MSVC C++20 - No STL|Win32 Debug MSVC C++20 - No STL|x64 = Debug MSVC C++20 - No STL|x64 Debug MSVC C++20 - No virtual messages|Win32 = Debug MSVC C++20 - No virtual messages|Win32 @@ -55,14 +55,14 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|Win32.Build.0 = Debug MSVC C++17|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.ActiveCfg = Debug MSVC C++17|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++17|x64.Build.0 = Debug MSVC C++17|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|Win32.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|Win32.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|x64.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03 - No virtual messages|x64.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.ActiveCfg = Debug MSVC C++20 - Force C++03|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|Win32.Build.0 = Debug MSVC C++20 - Force C++03|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|x64.ActiveCfg = Debug MSVC C++20 - Force C++03|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Force C++03|x64.Build.0 = Debug MSVC C++20 - Force C++03|x64 - {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 - {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|Win32 - {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Forve C++03 - No virtual messages|x64.ActiveCfg = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 - {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - Forve C++03 - No virtual messages|x64.Build.0 = Debug MSVC C++20 - Forve C++03 - No virtual messages|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.ActiveCfg = Debug MSVC C++20 - No STL|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|Win32.Build.0 = Debug MSVC C++20 - No STL|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Debug MSVC C++20 - No STL|x64.ActiveCfg = Debug MSVC C++20 - No STL|x64 From 6508e611537369a47950fe7955e60c89442e9f5b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Mar 2025 15:11:29 +0000 Subject: [PATCH 104/216] etl::span constexpr fix --- include/etl/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/span.h b/include/etl/span.h index a9d4d7210..5e364b233 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -230,7 +230,7 @@ namespace etl /// From dynamic extent span. //************************************************************************* template - span(const etl::span& other, typename etl::enable_if::type* = 0) + ETL_CONSTEXPR14 span(const etl::span& other, typename etl::enable_if::type* = 0) : pbegin(other.data()) { ETL_ASSERT(other.size() == Extent, ETL_ERROR(span_size_mismatch)); From 21ea151532921294f3b21423ad9aa4dd6b873d77 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Mar 2025 15:35:45 +0000 Subject: [PATCH 105/216] #1056 Bug: variadic_variant doesn't use the type_id_t type to store type_id --- include/etl/private/variant_variadic.h | 5 ----- 1 file changed, 5 deletions(-) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 8e6874601..37f723a70 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -378,11 +378,6 @@ namespace etl { public: - //*************************************************************************** - /// The type used for ids. - //*************************************************************************** - using type_id_t = uint_least8_t ; - //*************************************************************************** /// get() is a friend function. //*************************************************************************** From 83e8473864015a93ceb78643b15f552b6210ea21 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Mar 2025 11:25:25 +0100 Subject: [PATCH 106/216] Work in progress --- include/etl/scaled_rounding.h | 227 ++++-- test/test_scaled_rounding.cpp | 1409 +++++++++++++++++++++++++++------ 2 files changed, 1313 insertions(+), 323 deletions(-) diff --git a/include/etl/scaled_rounding.h b/include/etl/scaled_rounding.h index d8a97da34..b1dbe18f3 100644 --- a/include/etl/scaled_rounding.h +++ b/include/etl/scaled_rounding.h @@ -46,14 +46,13 @@ namespace etl //***************************************************************************** /// A set of rounding algorithms for scaled integrals. /// \tparam T The integral type. - /// \tparam SCALING The scaling factor. + /// \tparam Scaling The scaling factor. /// /// \example For emulating fixed point of two decimal places we could use a /// scaling factor of '100'. To round the result of scaled int calculations /// using 'Banker's Rounding' we would define this. /// \code - /// typedef etl::scaled_rounding Rounding; - /// int final_result = Rounding::round_half_even_unscaled(accumulated_result); + /// int final_result = round_half_even_unscaled<100>(accumulated_result); /// \endcode /// \link http://www.clivemaxfield.com/diycalculator/sp-round.shtml //***************************************************************************** @@ -63,19 +62,26 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_ceiling_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_ceiling_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } + if (value >= 0) { - return T((value + scale_t(SCALING)) / scale_t(SCALING)); + return T((value + scale_t(Scaling - 1U)) / scale_t(Scaling)); } else { - return T(value / scale_t(SCALING)); + return T(value / scale_t(Scaling)); } } @@ -84,12 +90,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_ceiling_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_ceiling_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return round_ceiling_unscaled(value) * scale_t(SCALING); + return round_ceiling_unscaled(value) * scale_t(Scaling); } //*************************************************************************** @@ -97,19 +105,25 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_floor_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_floor_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } if (value >= 0) { - return T(value / scale_t(SCALING)); + return T(value / scale_t(Scaling)); } else { - return T((value - scale_t(SCALING)) / scale_t(SCALING)); + return T((value - scale_t(Scaling - 1)) / scale_t(Scaling)); } } @@ -118,12 +132,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_floor_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_floor_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_floor_unscaled(value) * scale_t(SCALING)); + return T(round_floor_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -132,20 +148,29 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_up_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_up_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((((SCALING / 2U) * 2U) == SCALING), "Scaling must be divisible by 2"); + ETL_STATIC_ASSERT((Scaling == 1) || (((Scaling / 2U) * 2U) == Scaling), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; - if (value >= 0) + if (Scaling == 1) { - return T((value + scale_t(SCALING / 2U)) / scale_t(SCALING)); + return value; } else { - return T((value - scale_t(SCALING / 2U)) / scale_t(SCALING)); + if (value >= 0) + { + return T((value + scale_t(Scaling / 2U)) / scale_t(Scaling)); + } + else + { + return T((value - scale_t(Scaling / 2U)) / scale_t(Scaling)); + } } } @@ -155,12 +180,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_up_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_up_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_up_unscaled(value) * scale_t(SCALING)); + return T(round_half_up_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -169,20 +196,22 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_down_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_down_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((((SCALING / 2U) * 2U) == SCALING), "Scaling must be divisible by 2"); + ETL_STATIC_ASSERT((Scaling == 1) || (((Scaling / 2U) * 2U) == Scaling), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; if (value >= 0) { - return T((value + scale_t((SCALING / 2U) - 1U)) / scale_t(SCALING)); + return T((value + scale_t(((Scaling - 1) / 2U))) / scale_t(Scaling)); } else { - return T((value - scale_t((SCALING / 2U) - 1U)) / scale_t(SCALING)); + return T((value - scale_t(((Scaling - 1) / 2U))) / scale_t(Scaling)); } } @@ -192,12 +221,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_down_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_down_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_down_unscaled(value) * scale_t(SCALING)); + return T(round_half_down_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -205,13 +236,22 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_zero_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_zero_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - return T(value / scale_t(SCALING)); + if (Scaling == 1) + { + return value; + } + else + { + return T(value / scale_t(Scaling)); + } } //*************************************************************************** @@ -219,46 +259,51 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_zero_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_zero_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_zero_unscaled(value) * scale_t(SCALING)); + return T(round_zero_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** - /// Round toward infinity. + /// Round twords infinity or away from zero. /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_infinity_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_infinity_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - typedef typename scaled_rounding_t::type scale_t; if (value >= 0) { - return T((value + scale_t(SCALING)) / scale_t(SCALING)); + return etl::round_ceiling_unscaled(value); } else { - return T((value - scale_t(SCALING)) / scale_t(SCALING)); + return etl::round_floor_unscaled(value); } } //*************************************************************************** - /// Round toward infinity. + /// Round twords infinity or away from zero. /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_infinity_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_infinity_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_infinity_unscaled(value) * scale_t(SCALING)); + return T(round_infinity_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -267,29 +312,38 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_even_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_even_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - // Half? - if ((etl::absolute(value) % scale_t(SCALING)) == scale_t(SCALING / 2U)) + if (Scaling == 1) { - // Odd? - if ((value / scale_t(SCALING)) & 1U) + return value; + } + else + { + // Half? + if ((etl::absolute(value) % scale_t(Scaling)) == scale_t(Scaling / 2U)) { - return T(round_half_up_unscaled(value)); + // Odd? + if ((value / scale_t(Scaling)) & 1U) + { + return T(round_half_up_unscaled(value)); + } + else + { + return T(round_half_down_unscaled(value)); + } } else { - return T(round_half_down_unscaled(value)); + return T(round_half_up_unscaled(value)); } } - else - { - return T(round_half_up_unscaled(value)); - } } //*************************************************************************** @@ -298,12 +352,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_even_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_even_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_even_unscaled(value) * scale_t(SCALING)); + return T(round_half_even_unscaled(value) * scale_t(Scaling)); } //*************************************************************************** @@ -312,29 +368,38 @@ namespace etl /// \param value Scaled integral. /// \return Unscaled, rounded integral. //*************************************************************************** - template - T round_half_odd_unscaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_odd_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; - // Half? - if ((etl::absolute(value) % scale_t(SCALING)) == scale_t(SCALING / 2U)) + if (Scaling == 1) + { + return value; + } + else { - // Odd? - if ((value / scale_t(SCALING)) & 1U) + // Half? + if ((etl::absolute(value) % scale_t(Scaling)) == scale_t(Scaling / 2U)) { - return T(round_half_down_unscaled(value)); + // Odd? + if ((value / scale_t(Scaling)) & 1U) + { + return T(round_half_down_unscaled(value)); + } + else + { + return T(round_half_up_unscaled(value)); + } } else { - return T(round_half_up_unscaled(value)); + return T(round_half_up_unscaled(value)); } } - else - { - return T(round_half_up_unscaled(value)); - } } //*************************************************************************** @@ -343,12 +408,14 @@ namespace etl /// \param value Scaled integral. /// \return Scaled, rounded integral. //*************************************************************************** - template - T round_half_odd_scaled(T value) + template + ETL_NODISCARD + ETL_CONSTEXPR14 + T round_half_odd_scaled(T value) ETL_NOEXCEPT { typedef typename scaled_rounding_t::type scale_t; - return T(round_half_odd_unscaled(value) * scale_t(SCALING)); + return T(round_half_odd_unscaled(value) * scale_t(Scaling)); } } diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 5099a20e3..998cda82a 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -34,312 +34,1235 @@ SOFTWARE. namespace { - std::array source = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + std::array source = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; SUITE(test_scaled_rounding) { //************************************************************************* TEST(round_ceiling_scaled) { - std::array expected = { 60, 60, 60, 70, 70, 70, -50, -50, -50, -60, -60, -60 }; - - CHECK_EQUAL(expected[0], etl::round_ceiling_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_ceiling_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_ceiling_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_ceiling_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_ceiling_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_ceiling_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_ceiling_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_ceiling_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_ceiling_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_ceiling_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_ceiling_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_ceiling_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, + -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_ceiling_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_scaled(source[39])); } //************************************************************************* TEST(round_ceiling_unscaled) { - std::array expected = { 6, 6, 6, 7, 7, 7, -5, -5, -5, -6, -6, -6 }; - - CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled<10>(source[11])); - } + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6 }; - //************************************************************************* - TEST(round_floor_scaled) - { - std::array expected = { 50, 50, 50, 60, 60, 60, -60, -60, -60, -70, -70, -70 }; - - CHECK_EQUAL(expected[0], etl::round_floor_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_floor_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_floor_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_floor_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_floor_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_floor_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_floor_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_floor_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_floor_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_floor_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_floor_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_floor_scaled<10>(source[11])); + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_unscaled(source[39])); } //************************************************************************* - TEST(round_floor_unscaled) + TEST(round_ceiling_scaled_with_scaling_of_1) { - std::array expected = { 5, 5, 5, 6, 6, 6, -6, -6, -6, -7, -7, -7 }; - - CHECK_EQUAL(expected[0], etl::round_floor_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_floor_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_floor_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_floor_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_floor_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_floor_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_floor_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_floor_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_floor_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_floor_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_floor_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_floor_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_ceiling_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_scaled(source[39])); } //************************************************************************* - TEST(round_half_up_scaled) + TEST(round_ceiling_unscaled_with_scaling_of_1) { - std::array expected = { 50, 60, 60, 60, 70, 70, -50, -60, -60, -60, -70, -70 }; - - CHECK_EQUAL(expected[0], etl::round_half_up_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_up_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_up_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_up_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_up_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_up_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_up_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_up_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_up_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_up_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_up_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_up_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_ceiling_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_ceiling_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_ceiling_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_ceiling_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_ceiling_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_ceiling_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_ceiling_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_ceiling_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_ceiling_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_ceiling_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_ceiling_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_ceiling_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_ceiling_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_ceiling_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_ceiling_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_ceiling_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_ceiling_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_ceiling_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_ceiling_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_ceiling_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_ceiling_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_ceiling_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_ceiling_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_ceiling_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_ceiling_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_ceiling_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_ceiling_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_ceiling_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_ceiling_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_ceiling_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_ceiling_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_ceiling_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_ceiling_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_ceiling_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_ceiling_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_ceiling_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_ceiling_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_ceiling_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_ceiling_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_ceiling_unscaled(source[39])); } //************************************************************************* - TEST(round_half_up_unscaled) + TEST(round_floor_scaled) { - std::array expected = { 5, 6, 6, 6, 7, 7, -5, -6, -6, -6, -7, -7 }; - - CHECK_EQUAL(expected[0], etl::round_half_up_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_up_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_up_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_up_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_up_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_up_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_up_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_up_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_up_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_up_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_up_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_up_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70, -70, -70, -70, -70 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_floor_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_scaled(source[39])); } //************************************************************************* - TEST(round_half_down_scaled) + TEST(round_floor_unscaled) { - std::array expected = { 50, 50, 60, 60, 60, 70, -50, -50, -60, -60, -60, -70 }; - - CHECK_EQUAL(expected[0], etl::round_half_down_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_down_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_down_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_down_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_down_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_down_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_down_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_down_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_down_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_down_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_down_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_down_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_floor_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_unscaled(source[39])); } //************************************************************************* - TEST(round_half_down_unscaled) + TEST(round_floor_scaled_with_scaling_of_1) { - std::array expected = { 5, 5, 6, 6, 6, 7, -5, -5, -6, -6, -6, -7 }; - - CHECK_EQUAL(expected[0], etl::round_half_down_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_down_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_down_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_down_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_down_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_down_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_down_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_down_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_down_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_down_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_down_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_down_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_floor_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_scaled(source[39])); } //************************************************************************* - TEST(round_zero_scaled) + TEST(round_floor_unscaled_with_scaling_of_1) { - std::array expected = { 50, 50, 50, 60, 60, 60, -50, -50, -50, -60, -60, -60 }; - - CHECK_EQUAL(expected[0], etl::round_zero_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_zero_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_zero_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_zero_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_zero_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_zero_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_zero_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_zero_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_zero_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_zero_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_zero_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_zero_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_floor_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_floor_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_floor_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_floor_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_floor_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_floor_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_floor_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_floor_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_floor_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_floor_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_floor_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_floor_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_floor_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_floor_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_floor_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_floor_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_floor_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_floor_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_floor_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_floor_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_floor_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_floor_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_floor_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_floor_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_floor_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_floor_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_floor_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_floor_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_floor_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_floor_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_floor_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_floor_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_floor_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_floor_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_floor_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_floor_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_floor_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_floor_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_floor_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_floor_unscaled(source[39])); } //************************************************************************* - TEST(round_zero_unscaled) + TEST(round_half_up_scaled) { - std::array expected = { 5, 5, 5, 6, 6, 6, -5, -5, -5, -6, -6, -6 }; - - CHECK_EQUAL(expected[0], etl::round_zero_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_zero_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_zero_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_zero_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_zero_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_zero_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_zero_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_zero_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_zero_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_zero_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_zero_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_zero_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, + -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_up_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_scaled(source[39])); } //************************************************************************* - TEST(round_infinity_scaled) + TEST(round_half_up_unscaled) { - std::array expected = { 60, 60, 60, 70, 70, 70, -60, -60, -60, -70, -70, -70 }; - - CHECK_EQUAL(expected[0], etl::round_infinity_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_infinity_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_infinity_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_infinity_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_infinity_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_infinity_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_infinity_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_infinity_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_infinity_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_infinity_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_infinity_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_infinity_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, + -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_up_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_unscaled(source[39])); } //************************************************************************* - TEST(round_infinity_unscaled) + TEST(round_half_up_scaled_with_scaling_of_2) { - std::array expected = { 6, 6, 6, 7, 7, 7, -6, -6, -6, -7, -7, -7 }; - - CHECK_EQUAL(expected[0], etl::round_infinity_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_infinity_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_infinity_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_infinity_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_infinity_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_infinity_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_infinity_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_infinity_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_infinity_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_infinity_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_infinity_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_infinity_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, + -50, -52, -52, -54, -54, -56, -56, -58, -58, -60, -60, -62, -62, -64, -64, -66, -66, -68, -68, -70 }; + + const size_t Scale = 2; + + CHECK_EQUAL(expected[0], etl::round_half_up_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_scaled(source[39])); } //************************************************************************* - TEST(round_half_even_scaled) + TEST(round_half_up_unscaled_with_scaling_of_2) { - std::array expected = { 50, 60, 60, 60, 60, 70, -50, -60, -60, -60, -60, -70 }; - - CHECK_EQUAL(expected[0], etl::round_half_even_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_even_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_even_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_even_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_even_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_even_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_even_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_even_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_even_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_even_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_even_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_even_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, + -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35 }; + + const size_t Scale = 2; + + CHECK_EQUAL(expected[0], etl::round_half_up_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_up_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_up_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_up_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_up_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_up_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_up_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_up_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_up_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_up_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_up_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_up_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_up_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_up_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_up_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_up_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_up_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_up_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_up_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_up_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_up_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_up_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_up_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_up_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_up_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_up_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_up_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_up_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_up_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_up_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_up_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_up_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_up_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_up_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_up_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_up_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_up_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_up_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_up_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_up_unscaled(source[39])); } //************************************************************************* - TEST(round_half_even_unscaled) + TEST(round_half_down_scaled) { - std::array expected = { 5, 6, 6, 6, 6, 7, -5, -6, -6, -6, -6, -7 }; - - CHECK_EQUAL(expected[0], etl::round_half_even_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_even_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_even_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_even_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_even_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_even_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_even_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_even_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_even_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_even_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_even_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_even_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, + -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_scaled(source[39])); } - //************************************************************************* - TEST(round_half_odd_scaled) + ////************************************************************************* + TEST(round_half_down_unscaled) { - std::array expected = { 50, 50, 60, 60, 70, 70, -50, -50, -60, -60, -70, -70 }; - - CHECK_EQUAL(expected[0], etl::round_half_odd_scaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_odd_scaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_odd_scaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_odd_scaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_odd_scaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_odd_scaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_odd_scaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_odd_scaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_odd_scaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_odd_scaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_odd_scaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_odd_scaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, + -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); } //************************************************************************* - TEST(round_half_odd_unscaled) + TEST(round_half_down_scaled_with_scaling_of_2) { - std::array expected = { 5, 5, 6, 6, 7, 7, -5, -5, -6, -6, -7, -7 }; - - CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled<10>(source[0])); - CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled<10>(source[1])); - CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled<10>(source[2])); - CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled<10>(source[3])); - CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled<10>(source[4])); - CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled<10>(source[5])); - CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled<10>(source[6])); - CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled<10>(source[7])); - CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled<10>(source[8])); - CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled<10>(source[9])); - CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled<10>(source[10])); - CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled<10>(source[11])); + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, + -50, -50, -52, -52, -54, -54, -56, -56, -58, -58, -60, -60, -62, -62, -64, -64, -66, -66, -68, -68 }; + + const size_t Scale = 2; + + CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_down_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_scaled(source[39])); } + + ////************************************************************************* + //TEST(round_half_down_unscaled_with_scaling_of_2) + //{ + // std::array expected = { 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, + // -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35 }; + + // const size_t Scale = 2; + + // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + // CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); + // CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); + // CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); + // CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); + // CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); + // CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); + // CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); + // CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); + + // CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); + // CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); + // CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); + // CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); + // CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); + // CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); + // CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); + // CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); + // CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); + // CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); + // CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); + // CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); + // CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); + // CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); + // CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); + // CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); + // CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); + // CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); + // CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); + // CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); + //} + + ////************************************************************************* + //TEST(round_half_down_scaled) + //{ + // std::array expected = { 50, 50, 60, 60, 60, 70, -50, -50, -60, -60, -60, -70 }; + + // CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_down_scaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_down_scaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_down_scaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_down_scaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_down_scaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_down_scaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_down_scaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_down_scaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_down_scaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_down_scaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_down_scaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_down_scaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_down_scaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_down_unscaled) + //{ + // std::array expected = { 5, 5, 6, 6, 6, 7, -5, -5, -6, -6, -6, -7 }; + + // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_down_unscaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_zero_scaled) + //{ + // std::array expected = { 50, 50, 50, 60, 60, 60, -50, -50, -50, -60, -60, -60 }; + + // CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_zero_scaled_of_1) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_zero_scaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_zero_scaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_zero_scaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_zero_scaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_zero_scaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_zero_scaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_zero_scaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_zero_scaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_zero_scaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_zero_scaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_zero_scaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_zero_scaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_zero_unscaled) + //{ + // std::array expected = { 5, 5, 5, 6, 6, 6, -5, -5, -5, -6, -6, -6 }; + + // CHECK_EQUAL(expected[0], etl::round_zero_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_zero_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_zero_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_zero_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_zero_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_zero_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_zero_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_zero_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_zero_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_zero_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_zero_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_zero_unscaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_zero_unscaled_of_1) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_zero_unscaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_zero_unscaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_zero_unscaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_zero_unscaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_zero_unscaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_zero_unscaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_zero_unscaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_zero_unscaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_zero_unscaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_zero_unscaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_zero_unscaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_zero_unscaled<1>(source[11])); + //} + // + ////************************************************************************* + //TEST(round_infinity_scaled) + //{ + // std::array expected = { 60, 60, 60, 70, 70, 70, -60, -60, -60, -70, -70, -70 }; + + // CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_infinity_scaled_of_1) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_infinity_scaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_infinity_scaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_infinity_scaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_infinity_scaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_infinity_scaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_infinity_scaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_infinity_scaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_infinity_scaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_infinity_scaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_infinity_scaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_infinity_scaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_infinity_scaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_infinity_unscaled) + //{ + // std::array expected = { 6, 6, 6, 7, 7, 7, -6, -6, -6, -7, -7, -7 }; + + // CHECK_EQUAL(expected[0], etl::round_infinity_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_infinity_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_infinity_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_infinity_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_infinity_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_infinity_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_infinity_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_infinity_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_infinity_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_infinity_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_infinity_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_infinity_unscaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_infinity_unscaled_of_1) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_infinity_unscaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_infinity_unscaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_infinity_unscaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_infinity_unscaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_infinity_unscaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_infinity_unscaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_infinity_unscaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_infinity_unscaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_infinity_unscaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_infinity_unscaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_infinity_unscaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_infinity_unscaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_even_scaled) + //{ + // std::array expected = { 50, 60, 60, 60, 60, 70, -50, -60, -60, -60, -60, -70 }; + + // CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_even_scaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_even_scaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_even_scaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_even_scaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_even_scaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_even_scaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_even_scaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_even_scaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_even_scaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_even_scaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_even_scaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_even_scaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_even_scaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_even_unscaled) + //{ + // std::array expected = { 5, 6, 6, 6, 6, 7, -5, -6, -6, -6, -6, -7 }; + + // CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_even_unscaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_even_unscaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_even_unscaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_even_unscaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_even_unscaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_even_unscaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_even_unscaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_even_unscaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_even_unscaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_even_unscaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_even_unscaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_even_unscaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_even_unscaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_odd_scaled) + //{ + // std::array expected = { 50, 50, 60, 60, 70, 70, -50, -50, -60, -60, -70, -70 }; + + // CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_odd_scaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_odd_scaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_odd_scaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_odd_scaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_odd_scaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_odd_scaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_odd_scaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_odd_scaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_odd_scaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_odd_scaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_odd_scaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_odd_scaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_odd_scaled<1>(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_odd_unscaled) + //{ + // std::array expected = { 5, 5, 6, 6, 7, 7, -5, -5, -6, -6, -7, -7 }; + + // CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); + //} + + ////************************************************************************* + //TEST(round_half_odd_unscaled_of_2) + //{ + // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + + // CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled<1>(source[0])); + // CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled<1>(source[1])); + // CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled<1>(source[2])); + // CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled<1>(source[3])); + // CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled<1>(source[4])); + // CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled<1>(source[5])); + // CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled<1>(source[6])); + // CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled<1>(source[7])); + // CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled<1>(source[8])); + // CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled<1>(source[9])); + // CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled<1>(source[10])); + // CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled<1>(source[11])); + //} }; } From e46563fafc28549c1bbada125bf02afda5762d40 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Mar 2025 20:25:33 +0100 Subject: [PATCH 107/216] Work in progress --- include/etl/scaled_rounding.h | 11 +- test/test_scaled_rounding.cpp | 897 ++++++++++++++++++++++++---------- 2 files changed, 636 insertions(+), 272 deletions(-) diff --git a/include/etl/scaled_rounding.h b/include/etl/scaled_rounding.h index b1dbe18f3..6f37de4f9 100644 --- a/include/etl/scaled_rounding.h +++ b/include/etl/scaled_rounding.h @@ -154,7 +154,6 @@ namespace etl T round_half_up_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((Scaling == 1) || (((Scaling / 2U) * 2U) == Scaling), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -202,16 +201,20 @@ namespace etl T round_half_down_unscaled(T value) ETL_NOEXCEPT { ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - ETL_STATIC_ASSERT((Scaling == 1) || (((Scaling / 2U) * 2U) == Scaling), "Scaling must be divisible by 2"); typedef typename scaled_rounding_t::type scale_t; + if (Scaling == 1) + { + return value; + } + if (value >= 0) { - return T((value + scale_t(((Scaling - 1) / 2U))) / scale_t(Scaling)); + return T((value + scale_t((Scaling - 1) / 2U)) / scale_t(Scaling)); } else { - return T((value - scale_t(((Scaling - 1) / 2U))) / scale_t(Scaling)); + return T((value - scale_t((Scaling - 1) / 2U)) / scale_t(Scaling)); } } diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 998cda82a..36974f1ee 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -34,7 +34,9 @@ SOFTWARE. namespace { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 std::array source = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; SUITE(test_scaled_rounding) @@ -45,6 +47,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60 }; const size_t Scale = 10; @@ -98,6 +102,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6 }; const size_t Scale = 10; @@ -150,7 +156,9 @@ namespace { // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 - std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; const size_t Scale = 1; @@ -202,8 +210,10 @@ namespace TEST(round_ceiling_unscaled_with_scaling_of_1) { // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 - // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; const size_t Scale = 1; @@ -257,6 +267,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70, -70, -70, -70, -70 }; const size_t Scale = 10; @@ -310,6 +322,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7, -7, -7, -7, -7 }; const size_t Scale = 10; @@ -362,7 +376,9 @@ namespace { // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 - std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; const size_t Scale = 1; @@ -416,6 +432,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; const size_t Scale = 1; @@ -469,6 +487,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70 }; const size_t Scale = 10; @@ -522,6 +542,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7 }; const size_t Scale = 10; @@ -575,6 +597,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -52, -52, -54, -54, -56, -56, -58, -58, -60, -60, -62, -62, -64, -64, -66, -66, -68, -68, -70 }; const size_t Scale = 2; @@ -628,6 +652,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35 }; const size_t Scale = 2; @@ -681,6 +707,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70 }; const size_t Scale = 10; @@ -734,6 +762,8 @@ namespace // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 std::array expected = { 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7 }; const size_t Scale = 10; @@ -782,14 +812,16 @@ namespace } //************************************************************************* - TEST(round_half_down_scaled_with_scaling_of_2) + TEST(round_half_down_scaled_with_scaling_of_1) { // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 - std::array expected = { 50, 50, 52, 52, 54, 54, 56, 56, 58, 58, 60, 60, 62, 62, 64, 64, 66, 66, 68, 68, - -50, -50, -52, -52, -54, -54, -56, -56, -58, -58, -60, -60, -62, -62, -64, -64, -66, -66, -68, -68 }; + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - const size_t Scale = 2; + const size_t Scale = 1; CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); @@ -834,284 +866,613 @@ namespace CHECK_EQUAL(expected[39], etl::round_half_down_scaled(source[39])); } - ////************************************************************************* - //TEST(round_half_down_unscaled_with_scaling_of_2) - //{ - // std::array expected = { 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 32, 33, 33, 34, 34, 35, - // -25, -26, -26, -27, -27, -28, -28, -29, -29, -30, -30, -31, -31, -32, -32, -33, -33, -34, -34, -35 }; - - // const size_t Scale = 2; - - // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); - // CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); - // CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); - // CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); - // CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); - // CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); - // CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); - // CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); - // CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); - - // CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); - // CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); - // CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); - // CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); - // CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); - // CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); - // CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); - // CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); - // CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); - // CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); - // CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); - // CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); - // CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); - // CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); - // CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); - // CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); - // CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); - // CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); - // CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); - // CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); - //} + //************************************************************************* + TEST(round_half_down_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - ////************************************************************************* - //TEST(round_half_down_scaled) - //{ - // std::array expected = { 50, 50, 60, 60, 60, 70, -50, -50, -60, -60, -60, -70 }; - - // CHECK_EQUAL(expected[0], etl::round_half_down_scaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_down_scaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_down_scaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_down_scaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_down_scaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_down_scaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_down_scaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_down_scaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_down_scaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_down_scaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_down_scaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_down_scaled(source[11])); - //} + const size_t Scale = 1; - ////************************************************************************* - //TEST(round_half_down_scaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_down_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_down_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_down_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_down_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_down_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_down_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_down_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_down_unscaled(source[19])); - // CHECK_EQUAL(expected[0], etl::round_half_down_scaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_down_scaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_down_scaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_down_scaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_down_scaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_down_scaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_down_scaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_down_scaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_down_scaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_down_scaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_down_scaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_down_scaled<1>(source[11])); - //} + CHECK_EQUAL(expected[20], etl::round_half_down_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_down_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_down_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_down_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_down_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_down_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_down_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_down_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_down_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_down_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_down_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_down_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_down_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_down_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_down_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_down_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_down_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_down_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_down_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_down_unscaled(source[39])); + } - ////************************************************************************* - //TEST(round_half_down_unscaled) - //{ - // std::array expected = { 5, 5, 6, 6, 6, 7, -5, -5, -6, -6, -6, -7 }; - - // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled(source[11])); - //} + //************************************************************************* + TEST(round_zero_scaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60 }; - ////************************************************************************* - //TEST(round_half_down_unscaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + const size_t Scale = 10; - // CHECK_EQUAL(expected[0], etl::round_half_down_unscaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_down_unscaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_down_unscaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_down_unscaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_down_unscaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_down_unscaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_down_unscaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_down_unscaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_down_unscaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_down_unscaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_down_unscaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_down_unscaled<1>(source[11])); - //} + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); + } - ////************************************************************************* - //TEST(round_zero_scaled) - //{ - // std::array expected = { 50, 50, 50, 60, 60, 60, -50, -50, -50, -60, -60, -60 }; - - // CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); - //} + //************************************************************************* + TEST(round_zero_unscaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6 }; - ////************************************************************************* - //TEST(round_zero_scaled_of_1) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + const size_t Scale = 10; - // CHECK_EQUAL(expected[0], etl::round_zero_scaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_zero_scaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_zero_scaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_zero_scaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_zero_scaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_zero_scaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_zero_scaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_zero_scaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_zero_scaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_zero_scaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_zero_scaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_zero_scaled<1>(source[11])); - //} + CHECK_EQUAL(expected[0], etl::round_zero_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_unscaled(source[39])); + } - ////************************************************************************* - //TEST(round_zero_unscaled) - //{ - // std::array expected = { 5, 5, 5, 6, 6, 6, -5, -5, -5, -6, -6, -6 }; - - // CHECK_EQUAL(expected[0], etl::round_zero_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_zero_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_zero_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_zero_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_zero_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_zero_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_zero_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_zero_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_zero_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_zero_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_zero_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_zero_unscaled(source[11])); - //} + //************************************************************************* + TEST(round_zero_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - ////************************************************************************* - //TEST(round_zero_unscaled_of_1) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + const size_t Scale = 1; - // CHECK_EQUAL(expected[0], etl::round_zero_unscaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_zero_unscaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_zero_unscaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_zero_unscaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_zero_unscaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_zero_unscaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_zero_unscaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_zero_unscaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_zero_unscaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_zero_unscaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_zero_unscaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_zero_unscaled<1>(source[11])); - //} - // - ////************************************************************************* - //TEST(round_infinity_scaled) - //{ - // std::array expected = { 60, 60, 60, 70, 70, 70, -60, -60, -60, -70, -70, -70 }; - - // CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); - //} + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); + } - ////************************************************************************* - //TEST(round_infinity_scaled_of_1) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + //************************************************************************* + TEST(round_zero_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - // CHECK_EQUAL(expected[0], etl::round_infinity_scaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_infinity_scaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_infinity_scaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_infinity_scaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_infinity_scaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_infinity_scaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_infinity_scaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_infinity_scaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_infinity_scaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_infinity_scaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_infinity_scaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_infinity_scaled<1>(source[11])); - //} + const size_t Scale = 1; - ////************************************************************************* - //TEST(round_infinity_unscaled) - //{ - // std::array expected = { 6, 6, 6, 7, 7, 7, -6, -6, -6, -7, -7, -7 }; - - // CHECK_EQUAL(expected[0], etl::round_infinity_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_infinity_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_infinity_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_infinity_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_infinity_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_infinity_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_infinity_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_infinity_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_infinity_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_infinity_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_infinity_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_infinity_unscaled(source[11])); - //} + CHECK_EQUAL(expected[0], etl::round_zero_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_zero_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_zero_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_zero_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_zero_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_zero_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_zero_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_zero_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_zero_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_zero_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_zero_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_zero_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_zero_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_zero_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_zero_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_zero_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_zero_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_zero_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_zero_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_zero_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_zero_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_zero_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_zero_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_zero_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_zero_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_zero_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_zero_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_zero_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_zero_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_zero_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_zero_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_zero_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_zero_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_zero_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_zero_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_zero_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_zero_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_zero_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_zero_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_zero_scaled(source[39])); + } - ////************************************************************************* - //TEST(round_infinity_unscaled_of_1) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + //************************************************************************* + TEST(round_infinity_scaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70, -70, -70, -70, -70 }; - // CHECK_EQUAL(expected[0], etl::round_infinity_unscaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_infinity_unscaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_infinity_unscaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_infinity_unscaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_infinity_unscaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_infinity_unscaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_infinity_unscaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_infinity_unscaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_infinity_unscaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_infinity_unscaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_infinity_unscaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_infinity_unscaled<1>(source[11])); - //} + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); + } + + //************************************************************************* + TEST(round_infinity_unscaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_infinity_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_infinity_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); + } + + //************************************************************************* + TEST(round_infinity_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_infinity_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_infinity_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_infinity_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_infinity_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_infinity_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_infinity_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_infinity_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_infinity_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_infinity_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_infinity_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_infinity_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_infinity_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_infinity_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_infinity_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_infinity_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_infinity_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_infinity_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_infinity_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_infinity_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_infinity_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_infinity_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_infinity_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_infinity_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_infinity_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_infinity_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_infinity_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_infinity_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_infinity_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_infinity_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_infinity_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_infinity_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_infinity_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_infinity_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_infinity_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_infinity_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_infinity_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_infinity_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_infinity_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_infinity_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); + } + + + + + //************************************************************************* + TEST(round_half_even_scaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_even_unscaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_unscaled(source[39])); + } ////************************************************************************* //TEST(round_half_even_scaled) From efc3238765f29304254f88e54ce93e129c9f1515 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 1 Apr 2025 09:36:41 +0100 Subject: [PATCH 108/216] Full updated tests --- test/test_scaled_rounding.cpp | 397 +++++++++++++++++++++++++++------- 1 file changed, 324 insertions(+), 73 deletions(-) diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 36974f1ee..9d6a6ddb8 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -1361,9 +1361,6 @@ namespace CHECK_EQUAL(expected[39], etl::round_infinity_scaled(source[39])); } - - - //************************************************************************* TEST(round_half_even_scaled) { @@ -1474,81 +1471,335 @@ namespace CHECK_EQUAL(expected[39], etl::round_half_even_unscaled(source[39])); } - ////************************************************************************* - //TEST(round_half_even_scaled) - //{ - // std::array expected = { 50, 60, 60, 60, 60, 70, -50, -60, -60, -60, -60, -70 }; - - // CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); - //} + //************************************************************************* + TEST(round_half_even_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - ////************************************************************************* - //TEST(round_half_even_scaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + const size_t Scale = 1; - // CHECK_EQUAL(expected[0], etl::round_half_even_scaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_even_scaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_even_scaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_even_scaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_even_scaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_even_scaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_even_scaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_even_scaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_even_scaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_even_scaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_even_scaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_even_scaled<1>(source[11])); - //} + CHECK_EQUAL(expected[0], etl::round_half_even_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_scaled(source[19])); - ////************************************************************************* - //TEST(round_half_even_unscaled) - //{ - // std::array expected = { 5, 6, 6, 6, 6, 7, -5, -6, -6, -6, -6, -7 }; - - // CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); - //} + CHECK_EQUAL(expected[20], etl::round_half_even_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_scaled(source[39])); + } - ////************************************************************************* - //TEST(round_half_even_unscaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; + //************************************************************************* + TEST(round_half_even_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; - // CHECK_EQUAL(expected[0], etl::round_half_even_unscaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_even_unscaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_even_unscaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_even_unscaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_even_unscaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_even_unscaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_even_unscaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_even_unscaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_even_unscaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_even_unscaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_even_unscaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_even_unscaled<1>(source[11])); - //} + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_even_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_even_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_even_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_even_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_even_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_even_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_even_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_even_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_even_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_even_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_even_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_even_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_even_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_even_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_even_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_even_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_even_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_even_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_even_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_even_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_even_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_even_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_even_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_even_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_even_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_even_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_even_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_even_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_even_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_even_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_even_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_even_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_even_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_even_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_even_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_even_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_even_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_even_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_even_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_even_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_half_odd_scaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60, 60, 70, 70, 70, 70, 70, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -50, -50, -50, -50, -50, -60, -60, -60, -60, -60, -60, -60, -60, -60, -70, -70, -70, -70, -70 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_odd_unscaled) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -5, -5, -5, -5, -5, -5, -6, -6, -6, -6, -6, -6, -6, -6, -6, -7, -7, -7, -7, -7 }; + + const size_t Scale = 10; + + CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); + } + + //************************************************************************* + TEST(round_half_odd_scaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_scaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_scaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_scaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_scaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_scaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_scaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_scaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_scaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_scaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_scaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_scaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_scaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_scaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_scaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_scaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_scaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_scaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_scaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_scaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_scaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_scaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_scaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_scaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_scaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_scaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_scaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_scaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_scaled(source[39])); + } + + //************************************************************************* + TEST(round_half_odd_unscaled_with_scaling_of_1) + { + // Index = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 14 16 17 18 19 + // Source = 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 + std::array expected = { 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + // Index = 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 34 36 37 38 39 + // Source = -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 + -50, -51, -52, -53, -54, -55, -56, -57, -58, -59, -60, -61, -62, -63, -64, -65, -66, -67, -68, -69 }; + + const size_t Scale = 1; + + CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); + CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); + CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); + CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); + CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); + CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); + CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); + CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); + CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); + CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); + CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); + CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); + CHECK_EQUAL(expected[12], etl::round_half_odd_unscaled(source[12])); + CHECK_EQUAL(expected[13], etl::round_half_odd_unscaled(source[13])); + CHECK_EQUAL(expected[14], etl::round_half_odd_unscaled(source[14])); + CHECK_EQUAL(expected[15], etl::round_half_odd_unscaled(source[15])); + CHECK_EQUAL(expected[16], etl::round_half_odd_unscaled(source[16])); + CHECK_EQUAL(expected[17], etl::round_half_odd_unscaled(source[17])); + CHECK_EQUAL(expected[18], etl::round_half_odd_unscaled(source[18])); + CHECK_EQUAL(expected[19], etl::round_half_odd_unscaled(source[19])); + + CHECK_EQUAL(expected[20], etl::round_half_odd_unscaled(source[20])); + CHECK_EQUAL(expected[21], etl::round_half_odd_unscaled(source[21])); + CHECK_EQUAL(expected[22], etl::round_half_odd_unscaled(source[22])); + CHECK_EQUAL(expected[23], etl::round_half_odd_unscaled(source[23])); + CHECK_EQUAL(expected[24], etl::round_half_odd_unscaled(source[24])); + CHECK_EQUAL(expected[25], etl::round_half_odd_unscaled(source[25])); + CHECK_EQUAL(expected[26], etl::round_half_odd_unscaled(source[26])); + CHECK_EQUAL(expected[27], etl::round_half_odd_unscaled(source[27])); + CHECK_EQUAL(expected[28], etl::round_half_odd_unscaled(source[28])); + CHECK_EQUAL(expected[29], etl::round_half_odd_unscaled(source[29])); + CHECK_EQUAL(expected[30], etl::round_half_odd_unscaled(source[30])); + CHECK_EQUAL(expected[31], etl::round_half_odd_unscaled(source[31])); + CHECK_EQUAL(expected[32], etl::round_half_odd_unscaled(source[32])); + CHECK_EQUAL(expected[33], etl::round_half_odd_unscaled(source[33])); + CHECK_EQUAL(expected[34], etl::round_half_odd_unscaled(source[34])); + CHECK_EQUAL(expected[35], etl::round_half_odd_unscaled(source[35])); + CHECK_EQUAL(expected[36], etl::round_half_odd_unscaled(source[36])); + CHECK_EQUAL(expected[37], etl::round_half_odd_unscaled(source[37])); + CHECK_EQUAL(expected[38], etl::round_half_odd_unscaled(source[38])); + CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); + } ////************************************************************************* //TEST(round_half_odd_scaled) From a6ed8bd4e9f435b974f14b5e6effa7b14294b183 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 1 Apr 2025 09:43:02 +0100 Subject: [PATCH 109/216] Remove unnecessary asserts --- include/etl/scaled_rounding.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/include/etl/scaled_rounding.h b/include/etl/scaled_rounding.h index 6f37de4f9..595f8ea67 100644 --- a/include/etl/scaled_rounding.h +++ b/include/etl/scaled_rounding.h @@ -67,7 +67,6 @@ namespace etl ETL_CONSTEXPR14 T round_ceiling_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -110,7 +109,6 @@ namespace etl ETL_CONSTEXPR14 T round_floor_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) { @@ -153,7 +151,6 @@ namespace etl ETL_CONSTEXPR14 T round_half_up_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -200,7 +197,6 @@ namespace etl ETL_CONSTEXPR14 T round_half_down_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -244,7 +240,6 @@ namespace etl ETL_CONSTEXPR14 T round_zero_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -282,8 +277,6 @@ namespace etl ETL_CONSTEXPR14 T round_infinity_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); - if (value >= 0) { return etl::round_ceiling_unscaled(value); @@ -320,7 +313,6 @@ namespace etl ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) @@ -376,7 +368,6 @@ namespace etl ETL_CONSTEXPR14 T round_half_odd_unscaled(T value) ETL_NOEXCEPT { - ETL_STATIC_ASSERT(etl::is_integral::value, "Type must be an integral"); typedef typename scaled_rounding_t::type scale_t; if (Scaling == 1) From a1bfce9a417f3fd43bb0c8c1d8557b79c1812299 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 1 Apr 2025 11:58:55 +0100 Subject: [PATCH 110/216] Full updated tests --- test/test_scaled_rounding.cpp | 106 ++++++++++------------------------ 1 file changed, 31 insertions(+), 75 deletions(-) diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 9d6a6ddb8..f59d45a82 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -1801,80 +1801,36 @@ namespace CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); } - ////************************************************************************* - //TEST(round_half_odd_scaled) - //{ - // std::array expected = { 50, 50, 60, 60, 70, 70, -50, -50, -60, -60, -70, -70 }; - - // CHECK_EQUAL(expected[0], etl::round_half_odd_scaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_odd_scaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_odd_scaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_odd_scaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_odd_scaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_odd_scaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_odd_scaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_odd_scaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_odd_scaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_odd_scaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_odd_scaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_odd_scaled(source[11])); - //} - - ////************************************************************************* - //TEST(round_half_odd_scaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; - - // CHECK_EQUAL(expected[0], etl::round_half_odd_scaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_odd_scaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_odd_scaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_odd_scaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_odd_scaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_odd_scaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_odd_scaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_odd_scaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_odd_scaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_odd_scaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_odd_scaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_odd_scaled<1>(source[11])); - //} - - ////************************************************************************* - //TEST(round_half_odd_unscaled) - //{ - // std::array expected = { 5, 5, 6, 6, 7, 7, -5, -5, -6, -6, -7, -7 }; - - // CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled(source[11])); - //} - - ////************************************************************************* - //TEST(round_half_odd_unscaled_of_2) - //{ - // std::array expected = { 54, 55, 56, 64, 65, 66, -54, -55, -56, -64, -65, -66 }; - - // CHECK_EQUAL(expected[0], etl::round_half_odd_unscaled<1>(source[0])); - // CHECK_EQUAL(expected[1], etl::round_half_odd_unscaled<1>(source[1])); - // CHECK_EQUAL(expected[2], etl::round_half_odd_unscaled<1>(source[2])); - // CHECK_EQUAL(expected[3], etl::round_half_odd_unscaled<1>(source[3])); - // CHECK_EQUAL(expected[4], etl::round_half_odd_unscaled<1>(source[4])); - // CHECK_EQUAL(expected[5], etl::round_half_odd_unscaled<1>(source[5])); - // CHECK_EQUAL(expected[6], etl::round_half_odd_unscaled<1>(source[6])); - // CHECK_EQUAL(expected[7], etl::round_half_odd_unscaled<1>(source[7])); - // CHECK_EQUAL(expected[8], etl::round_half_odd_unscaled<1>(source[8])); - // CHECK_EQUAL(expected[9], etl::round_half_odd_unscaled<1>(source[9])); - // CHECK_EQUAL(expected[10], etl::round_half_odd_unscaled<1>(source[10])); - // CHECK_EQUAL(expected[11], etl::round_half_odd_unscaled<1>(source[11])); - //} + //************************************************************************* + TEST(round_constexpr_scaled_rounding) + { + constexpr int round_ceiling = etl::round_ceiling_scaled<10>(10); + constexpr int round_floor = etl::round_floor_scaled<10>(10); + constexpr int round_half_down_scaled = etl::round_half_down_scaled<10>(10); + constexpr int round_half_even_scaled = etl::round_half_even_scaled<10>(10); + constexpr int round_half_odd_scaled = etl::round_half_odd_scaled<10>(10); + constexpr int round_half_up_scaled = etl::round_half_up_scaled<10>(10); + constexpr int round_infinity = etl::round_infinity_scaled<10>(10); + constexpr int round_zero = etl::round_zero_scaled<10>(10); + + // Ensure that the value are constexpr. + std::array a{}; + std::array b{}; + std::array c{}; + std::array d{}; + std::array e{}; + std::array f{}; + std::array g{}; + std::array h{}; + + CHECK_EQUAL(10, round_ceiling); + CHECK_EQUAL(10, round_floor); + CHECK_EQUAL(10, round_half_down_scaled); + CHECK_EQUAL(10, round_half_even_scaled); + CHECK_EQUAL(10, round_half_odd_scaled); + CHECK_EQUAL(10, round_half_up_scaled); + CHECK_EQUAL(10, round_infinity); + CHECK_EQUAL(10, round_zero); + } }; } From 1ada87ad76663b83e99919791d1643b69a8df95c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 2 Apr 2025 12:58:38 +0100 Subject: [PATCH 111/216] Changed minimum cmake version to 3.10.0 --- test/CMakeLists.txt | 2 +- test/syntax_check/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 498fa7db2..09d5e364e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10.0) project(etl_unit_tests LANGUAGES CXX) #include(FetchContent) diff --git a/test/syntax_check/CMakeLists.txt b/test/syntax_check/CMakeLists.txt index 84cce67b2..0dab0a415 100644 --- a/test/syntax_check/CMakeLists.txt +++ b/test/syntax_check/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10.0) project(etl_syntax_check) add_definitions(-DETL_DEBUG) From e30a0e676a31e8f30b97b9cd4b0428a72491713a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 2 Apr 2025 12:59:06 +0100 Subject: [PATCH 112/216] Removed appveyor notification for Slack --- appveyor.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index a3cba3df1..0b8eef403 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -16,11 +16,5 @@ install: build: project: test/vs2022/etl.vcxproj verbosity: minimal -notifications: -- provider: Webhook - url: https://hooks.slack.com/services/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 - method: POST - on_build_success: true - on_build_failure: true - on_build_status_changed: true + \ No newline at end of file From a5f0cfe60e89891d1e0c9ebdab5a9878fef58a0e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 2 Apr 2025 13:16:57 +0100 Subject: [PATCH 113/216] Enabled constexpr rounding tests for C++14 and above. --- test/test_scaled_rounding.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index f59d45a82..8b709f91f 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -1801,6 +1801,7 @@ namespace CHECK_EQUAL(expected[39], etl::round_half_odd_unscaled(source[39])); } +#if ETL_USING_CPP14 //************************************************************************* TEST(round_constexpr_scaled_rounding) { @@ -1832,5 +1833,6 @@ namespace CHECK_EQUAL(10, round_infinity); CHECK_EQUAL(10, round_zero); } +#endif }; } From 409dae2c36ab0ac96eb52b3cdf8ac1944a5efaef Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 2 Apr 2025 13:29:59 +0100 Subject: [PATCH 114/216] Fix unused variable warnings --- test/test_scaled_rounding.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test_scaled_rounding.cpp b/test/test_scaled_rounding.cpp index 8b709f91f..518eada24 100644 --- a/test/test_scaled_rounding.cpp +++ b/test/test_scaled_rounding.cpp @@ -1824,6 +1824,15 @@ namespace std::array g{}; std::array h{}; + (void)a; + (void)b; + (void)c; + (void)d; + (void)e; + (void)f; + (void)g; + (void)h; + CHECK_EQUAL(10, round_ceiling); CHECK_EQUAL(10, round_floor); CHECK_EQUAL(10, round_half_down_scaled); From 7d91e1f152c000850cef316aa294fbc3bb5e54f3 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 2 Apr 2025 16:59:37 +0200 Subject: [PATCH 115/216] Alignment typed storage (#1023) * Add etl::typed_storage based on etl::aligned_storage_as * Have create() instead of emplace() --- include/etl/alignment.h | 117 ++++++++++++++++++++++++++++++++++++++++ test/test_alignment.cpp | 43 +++++++++++++++ 2 files changed, 160 insertions(+) diff --git a/include/etl/alignment.h b/include/etl/alignment.h index c6a4de066..47ae77447 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -36,6 +36,7 @@ SOFTWARE. #include "static_assert.h" #include "error_handler.h" #include "exception.h" +#include "utility.h" #include @@ -71,6 +72,19 @@ namespace etl } }; + //*************************************************************************** + /// Typed storage exception. + //*************************************************************************** + class typed_storage_error : public alignment_exception + { + public: + + typed_storage_error(string_type file_name_, numeric_type line_number_) + : alignment_exception(ETL_ERROR_TEXT("typed_storage:error", ETL_ALIGNMENT_FILE_ID"B"), file_name_, line_number_) + { + } + }; + //***************************************************************************** /// Check that 'p' has 'required_alignment'. //***************************************************************************** @@ -333,6 +347,109 @@ namespace etl #if ETL_USING_CPP11 template using aligned_storage_as_t = typename aligned_storage_as::type; + + //*************************************************************************** + /// Wrapper class that provides a memory area and lets the user emplace and + /// instance of T in this memory at runtime. This class also erases the + /// destructor call of T, i.e. if typed_storage goes out of scope, the + /// destructor if the wrapped type will not be called. This can be done + /// explicitly by calling destroy(). + /// \tparam T Type of element stored in this instance of typed_storage. + //*************************************************************************** + template + class typed_storage + { + public: + + using value_type = T; + using reference = T&; + using const_reference = T const&; + using pointer = T*; + using const_pointer = T const*; + + // Constructor + typed_storage() + : valid(false) + { + } + + //*************************************************************************** + /// Default destructor which will NOT call the destructor of the object which + /// was created by calling emplace(). + //*************************************************************************** + ~typed_storage() = default; + + //*************************************************************************** + /// Calls the destructor of the wrapped object and asserts if has_value() is false. + //*************************************************************************** + void destroy() + { + ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error)); + data.template get_reference().~T(); + valid = false; + } + + //*************************************************************************** + /// \returns true if object has been constructed using emplace(). + /// \returns false otherwise. + //*************************************************************************** + bool has_value() const + { + return valid; + } + + //*************************************************************************** + /// Constructs the instance of T forwarding the given \p args to its constructor and + /// asserts if has_value() is true before calling emplace(). + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(Args&&... args) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(etl::forward(args)...); + } + + //*************************************************************************** + /// \returns a pointer of type T and asserts if has_value() is false. + //*************************************************************************** + pointer operator->() + { + ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error)); + return data.template get_address(); + } + + //*************************************************************************** + /// \returns a const pointer of type T and asserts if has_value() is false. + //*************************************************************************** + const_pointer operator->() const + { + return operator->(); + } + + //*************************************************************************** + /// \returns reference of type T and asserts if has_value() is false. + //*************************************************************************** + reference operator*() + { + return *operator->(); + } + + //*************************************************************************** + /// \returns const reference of type T and asserts if has_value() is false. + //*************************************************************************** + const_reference operator*() const + { + return *operator->(); + } + + private: + + typename aligned_storage_as::type data; + bool valid; + }; #endif } diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index 29de827a1..7563bbbcc 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -48,6 +48,23 @@ void f(int) { } +struct A_t +{ + A_t(uint32_t v_x, uint8_t v_y) + : x(v_x) + , y(v_y) + { + } + + bool operator==(A_t& other) + { + return other.x == x && other.y == y; + } + + uint32_t x; + uint8_t y; +}; + namespace { SUITE(test_alignment) @@ -155,5 +172,31 @@ namespace CHECK_EQUAL(32, alignof(etl::type_with_alignment_t<32>)); CHECK_EQUAL(64, alignof(etl::type_with_alignment_t<64>)); } + + //************************************************************************* +#if ETL_USING_CPP11 + TEST(test_typed_storage) + { + etl::typed_storage a; + + CHECK_EQUAL(false, a.has_value()); + + auto& b = a.create(123, 4); + + CHECK_EQUAL(true, a.has_value()); + + CHECK_EQUAL(a->x, 123); + CHECK_EQUAL(a->y, 4); + + CHECK_EQUAL(b.x, 123); + CHECK_EQUAL(b.y, 4); + + CHECK_TRUE(*a == b); + + CHECK_EQUAL(true, a.has_value()); + a.destroy(); + CHECK_EQUAL(false, a.has_value()); + } +#endif }; } From 209e8ceeddd4236508e278e4dcbf30154490106f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Apr 2025 10:46:27 +0100 Subject: [PATCH 116/216] Added C++03 compatibility --- include/etl/alignment.h | 62 +++++++++++++++++++++++++++++++++++++++-- test/test_alignment.cpp | 2 -- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/include/etl/alignment.h b/include/etl/alignment.h index 47ae77447..7ee760429 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -347,6 +347,7 @@ namespace etl #if ETL_USING_CPP11 template using aligned_storage_as_t = typename aligned_storage_as::type; +#endif //*************************************************************************** /// Wrapper class that provides a memory area and lets the user emplace and @@ -398,9 +399,10 @@ namespace etl return valid; } +#if ETL_USING_CPP11 //*************************************************************************** /// Constructs the instance of T forwarding the given \p args to its constructor and - /// asserts if has_value() is true before calling emplace(). + /// asserts if has_value() is false. /// /// \returns the instance of T which has been constructed in the internal byte array. //*************************************************************************** @@ -411,6 +413,63 @@ namespace etl valid = true; return *::new (data.template get_address()) value_type(etl::forward(args)...); } +#else + //*************************************************************************** + /// Constructs the instance of T with type T1 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2, T3 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2, const T3& t3) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2, t3); + } + + //*************************************************************************** + /// Constructs the instance of T with types T1, T2, T3, T4 + /// asserts if has_value() is false. + /// + /// \returns the instance of T which has been constructed in the internal byte array. + //*************************************************************************** + template + reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4) + { + ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); + valid = true; + return *::new (data.template get_address()) value_type(t1, t2, t3, t4); + } +#endif //*************************************************************************** /// \returns a pointer of type T and asserts if has_value() is false. @@ -450,7 +509,6 @@ namespace etl typename aligned_storage_as::type data; bool valid; }; -#endif } #endif diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index 7563bbbcc..d9a9de57b 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -174,7 +174,6 @@ namespace } //************************************************************************* -#if ETL_USING_CPP11 TEST(test_typed_storage) { etl::typed_storage a; @@ -197,6 +196,5 @@ namespace a.destroy(); CHECK_EQUAL(false, a.has_value()); } -#endif }; } From 520bcf876bbbc18cfb21780cd2b3c020215df455 Mon Sep 17 00:00:00 2001 From: Mario Luzeiro Date: Sat, 12 Apr 2025 10:52:36 +0100 Subject: [PATCH 117/216] fix missing is_secure function when building without ETL_HAS_STRING_CLEAR_AFTER_USE (#1067) --- include/etl/basic_string.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 40a8d0db7..c17bf9332 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -283,15 +283,19 @@ namespace etl { flags.set(); } +#endif //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* bool is_secure() const { +#if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); - } +#else + return false; #endif + } protected: From 73308ede0061c04c2cf9f99f736fad71a48b44b6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Apr 2025 15:04:21 +0100 Subject: [PATCH 118/216] Made is_truncated available for all configurations --- include/etl/basic_string.h | 10 +- test/test_string_char.cpp | 711 +++++----- test/test_string_char_external_buffer.cpp | 819 ++++++------ test/test_string_u16.cpp | 1211 ++++++++--------- test/test_string_u16_external_buffer.cpp | 902 ++++++------- test/test_string_u32.cpp | 1227 +++++++++--------- test/test_string_u32_external_buffer.cpp | 902 ++++++------- test/test_string_u8.cpp | 1130 ++++++++-------- test/test_string_u8_external_buffer.cpp | 956 +++++++------- test/test_string_wchar_t.cpp | 1211 ++++++++--------- test/test_string_wchar_t_external_buffer.cpp | 883 ++++++------- 11 files changed, 4973 insertions(+), 4989 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index c17bf9332..0b0404b5c 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -245,7 +245,6 @@ namespace etl return max_size() - size(); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS //************************************************************************* /// Returns whether the string was truncated by the last operation. /// Deprecated. Use is_truncated() @@ -254,7 +253,11 @@ namespace etl ETL_DEPRECATED bool truncated() const { +#if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); +#else + return false; +#endif } //************************************************************************* @@ -263,9 +266,14 @@ namespace etl //************************************************************************* bool is_truncated() const { +#if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); +#else + return false; +#endif } +#if ETL_HAS_STRING_TRUNCATION_CHECKS //************************************************************************* /// Clears the 'truncated' flag. //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 55e1bdb37..a0789c1c8 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/string.h" #include "etl/string_view.h" @@ -104,9 +105,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -118,9 +117,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -138,9 +135,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -150,7 +145,9 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -165,9 +162,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -182,7 +177,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -197,9 +194,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -214,7 +209,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -229,9 +226,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -246,7 +241,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -259,9 +256,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -274,7 +269,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -307,9 +304,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -319,9 +314,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -332,7 +325,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -342,7 +337,7 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -357,9 +352,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -374,7 +367,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -387,9 +380,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -404,7 +395,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -419,10 +412,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -436,8 +427,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -455,10 +449,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -476,8 +468,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -494,10 +489,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -514,8 +507,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -528,9 +524,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -543,7 +537,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -557,9 +553,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -586,9 +580,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -622,9 +614,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -642,9 +632,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -658,7 +646,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -672,9 +662,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -694,9 +682,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -837,10 +823,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -850,9 +833,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -862,9 +843,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -873,9 +852,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -885,9 +862,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -897,9 +872,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -908,9 +881,7 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -924,9 +895,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -940,9 +909,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -956,10 +923,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -974,10 +938,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -988,9 +949,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1000,9 +959,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1012,9 +969,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1024,9 +979,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1041,9 +994,7 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1058,9 +1009,7 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1077,9 +1026,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1091,9 +1038,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1111,9 +1056,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1131,7 +1074,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1145,9 +1090,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1161,7 +1104,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1175,9 +1120,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1193,7 +1136,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1208,9 +1153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1225,7 +1168,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1245,9 +1190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1265,7 +1208,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1290,9 +1235,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1309,9 +1252,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1322,7 +1263,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1384,7 +1327,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1396,7 +1341,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1408,7 +1355,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1432,9 +1381,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1458,7 +1405,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1473,7 +1422,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1488,7 +1439,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1503,7 +1456,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1525,10 +1480,8 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1552,7 +1505,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1567,7 +1522,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1583,7 +1540,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1606,9 +1565,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1627,9 +1584,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1648,9 +1603,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1670,7 +1623,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1693,7 +1648,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1711,9 +1668,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1726,9 +1681,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1739,9 +1692,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1757,9 +1708,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1773,7 +1722,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1790,9 +1741,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1806,7 +1755,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1822,7 +1773,9 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif //#include "etl/private/diagnostic_pop.h" } @@ -1840,7 +1793,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1854,7 +1807,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1872,7 +1827,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1887,7 +1842,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1902,7 +1857,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1917,7 +1874,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1935,7 +1894,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1949,7 +1908,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1967,7 +1928,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1981,7 +1942,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1999,7 +1962,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2014,7 +1977,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2032,7 +1997,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2046,7 +2011,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2060,7 +2025,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2074,7 +2041,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2088,7 +2057,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2102,7 +2071,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2116,7 +2087,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2134,7 +2107,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2148,7 +2121,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2162,7 +2135,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2176,7 +2151,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2190,7 +2167,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2204,7 +2181,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2218,7 +2197,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2236,7 +2217,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2250,7 +2231,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2264,7 +2247,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2278,7 +2261,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2296,7 +2281,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2310,7 +2295,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2324,7 +2311,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2338,7 +2325,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2356,7 +2345,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2370,7 +2359,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2384,7 +2373,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2398,7 +2389,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2412,7 +2405,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2426,7 +2419,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2440,7 +2433,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2454,7 +2449,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2472,7 +2469,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2486,7 +2483,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2500,7 +2497,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2514,7 +2513,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2528,7 +2529,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2542,7 +2543,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2556,7 +2557,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2570,7 +2573,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2588,7 +2593,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2602,7 +2607,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2616,7 +2621,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2630,7 +2637,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2644,7 +2653,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2658,7 +2667,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2672,7 +2681,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2686,7 +2697,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2704,7 +2717,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2718,7 +2731,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2732,7 +2747,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2746,7 +2761,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2764,7 +2781,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2778,7 +2795,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2792,7 +2809,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2806,7 +2825,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2820,7 +2841,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2834,7 +2855,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2848,7 +2869,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2862,7 +2885,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2880,7 +2905,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2896,7 +2921,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2912,7 +2939,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2928,7 +2955,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2948,7 +2977,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2962,7 +2991,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2976,7 +3005,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2990,7 +3021,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3004,7 +3037,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -3018,7 +3051,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3032,7 +3065,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3046,7 +3081,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3064,7 +3101,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3078,7 +3115,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3092,7 +3131,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3106,7 +3145,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3127,7 +3168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3141,7 +3182,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3155,7 +3198,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3169,7 +3212,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3186,7 +3231,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3203,7 +3248,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3220,7 +3265,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3232,7 +3277,7 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3245,7 +3290,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3258,7 +3303,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3271,7 +3316,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3284,7 +3329,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3479,7 +3524,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3499,7 +3544,7 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3520,7 +3565,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3546,7 +3591,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -5048,25 +5093,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5075,8 +5120,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5091,7 +5136,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -5106,10 +5151,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5130,7 +5175,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5276,7 +5323,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5291,7 +5338,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5306,7 +5353,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index a2593660b..1e9e5e446 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/string.h" #include "etl/string_view.h" @@ -116,9 +117,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -132,9 +131,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -147,9 +144,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -162,9 +157,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -177,9 +170,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -192,9 +183,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -213,9 +202,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -226,7 +213,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -242,9 +231,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -260,7 +247,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -276,9 +265,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -294,7 +281,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -310,9 +299,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -328,7 +315,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -342,9 +331,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -358,7 +345,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -429,7 +418,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -443,7 +434,9 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -481,7 +474,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -497,9 +492,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -517,7 +510,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -535,10 +530,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -555,8 +548,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -601,8 +597,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -622,10 +621,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -645,8 +642,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -660,9 +660,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -676,7 +674,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -693,6 +693,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -709,6 +711,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -722,9 +726,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -765,9 +767,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -786,9 +786,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -803,7 +801,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -818,9 +818,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -841,9 +839,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -988,9 +984,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1001,9 +995,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1013,9 +1005,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1026,9 +1016,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1039,9 +1027,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1051,9 +1037,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1069,9 +1053,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1087,9 +1069,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1105,9 +1085,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1125,9 +1103,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1141,9 +1117,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1155,9 +1129,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1169,9 +1141,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1183,9 +1153,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1201,9 +1169,7 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1219,9 +1185,7 @@ namespace compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1242,9 +1206,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1257,9 +1219,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); - #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - #endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1279,9 +1239,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1303,7 +1261,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1318,9 +1278,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1335,7 +1293,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1350,9 +1310,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1369,7 +1327,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1385,9 +1345,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1403,7 +1361,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1424,9 +1384,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1445,7 +1403,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1472,9 +1432,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1493,9 +1451,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1506,7 +1462,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1573,7 +1531,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1585,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1597,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1622,9 +1586,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1649,7 +1611,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1664,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1679,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1694,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1717,9 +1687,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1745,7 +1713,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1760,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1776,7 +1748,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1801,9 +1775,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1826,9 +1798,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1849,9 +1819,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1875,7 +1843,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1903,7 +1873,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1925,9 +1897,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1940,9 +1910,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1953,9 +1921,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1975,9 +1941,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1991,7 +1955,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2009,9 +1975,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2025,7 +1989,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2040,11 +2006,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -2063,9 +2033,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -2078,7 +2046,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2099,9 +2069,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -2114,9 +2082,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2130,7 +2096,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2144,11 +2112,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2167,9 +2139,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2182,7 +2152,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2201,9 +2173,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2216,7 +2186,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2237,9 +2209,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2253,7 +2223,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2272,9 +2244,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -2286,9 +2256,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2301,7 +2269,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2315,7 +2285,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2328,9 +2300,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2343,7 +2313,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2357,7 +2329,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2375,10 +2349,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); @@ -2389,9 +2360,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2404,7 +2373,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2418,7 +2389,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2431,9 +2404,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2446,7 +2417,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2460,7 +2433,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2479,9 +2454,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2494,7 +2467,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2507,9 +2482,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2522,7 +2495,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2540,9 +2515,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2555,7 +2528,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2568,9 +2543,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2583,7 +2556,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2602,9 +2577,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2616,9 +2589,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2631,7 +2602,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2645,7 +2618,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2658,9 +2633,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2672,9 +2645,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2687,7 +2658,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2701,7 +2674,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2719,9 +2694,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2733,9 +2706,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2748,7 +2719,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2762,7 +2735,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2775,9 +2750,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2789,9 +2762,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2804,7 +2775,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2818,7 +2791,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2837,9 +2812,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2851,9 +2824,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2866,7 +2837,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2880,7 +2853,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2893,9 +2868,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2907,9 +2880,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2922,7 +2893,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2936,7 +2909,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2955,9 +2930,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2970,7 +2943,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2983,9 +2958,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2998,7 +2971,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3017,9 +2992,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3031,9 +3004,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3046,7 +3017,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3060,7 +3033,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3073,9 +3048,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3087,9 +3060,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3102,7 +3073,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3116,7 +3089,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3135,9 +3110,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3152,7 +3125,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3167,9 +3142,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3184,7 +3157,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3205,9 +3180,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3219,9 +3192,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3234,7 +3205,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3248,7 +3221,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3261,9 +3236,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3275,9 +3248,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3290,7 +3261,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3304,7 +3277,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3323,9 +3298,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3338,7 +3311,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3351,9 +3326,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3366,7 +3339,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3388,9 +3363,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3403,7 +3376,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3416,9 +3391,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3431,7 +3404,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3448,9 +3423,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3467,9 +3440,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3480,9 +3451,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3495,9 +3464,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3510,9 +3477,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3525,9 +3490,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3540,9 +3503,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3767,9 +3728,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3788,9 +3747,7 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3811,9 +3768,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -3839,9 +3794,7 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, buffer1 + length1, @@ -5402,25 +5355,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5433,7 +5386,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5467,10 +5420,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5493,7 +5446,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5652,9 +5607,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -5668,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5685,7 +5636,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 01ee5cf88..d55c64b48 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u16string.h" @@ -97,7 +98,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -119,9 +119,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -129,19 +127,17 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); @@ -153,9 +149,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -165,7 +159,9 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -180,9 +176,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -197,7 +191,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -212,9 +208,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -229,7 +223,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -244,9 +240,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -261,7 +255,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -274,9 +270,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -289,7 +283,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -322,9 +318,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -334,9 +328,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -347,7 +339,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -357,7 +351,7 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -372,9 +366,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -389,7 +381,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -402,24 +394,24 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -434,10 +426,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -451,8 +441,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -470,10 +463,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -491,8 +482,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -509,10 +503,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -529,8 +521,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -543,9 +538,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -558,7 +551,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -572,9 +567,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -601,9 +594,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -612,40 +603,39 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; Text text(initial_text.c_str(), INITIAL_SIZE); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -656,46 +646,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -708,24 +696,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -739,35 +725,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -780,7 +766,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -793,16 +779,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); @@ -817,17 +803,17 @@ namespace Text text(initial_text.c_str(), INITIAL_SIZE); // Overwrite from index 1 to one less than the new size and set to that size. - text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } - - return i; - }); + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -851,10 +837,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -864,9 +847,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -876,9 +857,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -887,9 +866,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -899,9 +876,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -911,9 +886,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -922,9 +895,7 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -938,9 +909,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -954,9 +923,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -970,10 +937,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -988,10 +952,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1002,9 +963,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1014,9 +973,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1026,9 +983,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1038,9 +993,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1051,13 +1004,11 @@ namespace Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1068,13 +1019,11 @@ namespace const Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1091,9 +1040,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1105,9 +1052,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1125,9 +1070,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1145,7 +1088,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1159,9 +1104,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1175,7 +1118,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1189,9 +1134,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1207,7 +1150,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1222,9 +1167,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1239,14 +1182,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1259,16 +1204,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) { const size_t INITIAL_SIZE = SIZE; - const size_t EXCESS_SIZE = SIZE + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1279,7 +1222,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1304,9 +1249,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1323,9 +1266,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1336,7 +1277,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1362,10 +1305,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; @@ -1392,37 +1335,43 @@ namespace const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1435,20 +1384,18 @@ namespace TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1461,63 +1408,71 @@ namespace TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1527,22 +1482,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1551,22 +1504,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1576,12 +1531,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1592,12 +1549,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1608,32 +1567,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1641,9 +1598,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1662,20 +1617,18 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - TextSTD compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); + Text text(initial_text.cbegin(), initial_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1684,7 +1637,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1692,13 +1647,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(longer_text.cbegin(), longer_text.cend()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1707,7 +1662,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1715,9 +1672,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(0, insert, 0, insert.size()); compare_text.insert(0, insert_text, 0, insert_text.size()); @@ -1725,12 +1682,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1740,12 +1695,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -1753,9 +1706,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1771,9 +1722,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1787,7 +1736,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1804,9 +1755,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1820,14 +1769,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { -#include "etl/private/diagnostic_array_bounds_push.h" + //#include "etl/private/diagnostic_array_bounds_push.h" Text text(short_text.c_str()); TextS append(short_text.c_str()); #if ETL_HAS_STRING_TRUNCATION_CHECKS @@ -1836,9 +1787,11 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" + //#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1854,7 +1807,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1868,7 +1821,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1886,7 +1841,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1901,7 +1856,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1916,7 +1871,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1931,7 +1888,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1949,7 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1963,7 +1922,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1981,7 +1942,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1995,7 +1956,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2013,7 +1976,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2028,7 +1991,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2046,7 +2011,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2060,7 +2025,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2074,7 +2039,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2088,7 +2055,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2102,7 +2071,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2116,7 +2085,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2130,7 +2101,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2148,7 +2121,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2162,7 +2135,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2176,7 +2149,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2190,7 +2165,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2204,7 +2181,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2218,7 +2195,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2232,7 +2211,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2250,7 +2231,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2264,7 +2245,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2278,7 +2261,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2292,7 +2275,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2310,7 +2295,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2324,7 +2309,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2338,7 +2325,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2352,7 +2339,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2370,7 +2359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2384,7 +2373,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2398,7 +2387,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2412,7 +2403,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2426,7 +2419,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2440,7 +2433,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2454,7 +2447,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2468,7 +2463,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2486,7 +2483,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2500,7 +2497,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2514,7 +2511,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2528,7 +2527,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2542,7 +2543,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2556,7 +2557,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2570,7 +2571,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2584,7 +2587,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2595,112 +2600,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2711,56 +2724,60 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2771,112 +2788,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2887,14 +2912,14 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2903,14 +2928,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2919,14 +2946,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2935,14 +2962,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2962,7 +2991,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2976,7 +3005,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2990,7 +3019,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3004,7 +3035,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3018,7 +3051,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -3032,7 +3065,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3046,7 +3079,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3060,7 +3095,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3078,7 +3115,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3092,7 +3129,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3106,7 +3145,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3120,7 +3159,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3141,7 +3182,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3155,7 +3196,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3169,7 +3212,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3183,7 +3226,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3200,7 +3245,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3217,7 +3262,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3234,7 +3279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3246,7 +3291,7 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3259,7 +3304,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3272,7 +3317,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3285,7 +3330,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3298,7 +3343,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3343,7 +3388,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -3358,17 +3403,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3378,8 +3423,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -3393,17 +3438,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3428,17 +3473,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3448,8 +3493,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -3463,17 +3508,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -3493,7 +3538,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3513,7 +3558,7 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3534,7 +3579,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3560,7 +3605,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3580,8 +3625,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3640,8 +3685,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3654,7 +3699,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(TextL::npos, position2); } @@ -3669,8 +3714,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3683,7 +3728,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(TextL::npos, position2); } @@ -3872,7 +3917,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3898,7 +3943,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3923,12 +3968,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = TextSTD::npos; + etl::iu16string::size_type position1 = TextL::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); @@ -5062,25 +5107,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5089,8 +5134,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5105,7 +5150,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -5120,10 +5165,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5144,7 +5189,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5290,7 +5337,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5305,7 +5352,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5320,27 +5367,11 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - Text text1 = STR("Hello World"); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index ab7223e74..fffa53c79 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u16string.h" #include "etl/fnv_1.h" @@ -130,9 +131,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -146,9 +145,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -161,9 +158,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -176,9 +171,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -191,9 +184,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -206,9 +197,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -227,9 +216,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -240,7 +227,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -256,9 +245,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -274,7 +261,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -290,9 +279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -308,7 +295,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -324,9 +313,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -342,7 +329,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -356,9 +345,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -372,7 +359,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -443,7 +432,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -457,7 +448,9 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -495,7 +488,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -511,9 +506,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -531,7 +524,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -549,10 +544,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -569,8 +562,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -615,8 +611,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -636,10 +635,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -659,8 +656,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -674,9 +674,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -690,7 +688,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -707,6 +707,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -723,6 +725,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -736,9 +740,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -779,9 +781,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -800,9 +800,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -817,7 +815,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -832,9 +832,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -855,9 +853,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -933,6 +929,32 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { @@ -944,16 +966,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -976,9 +998,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -989,9 +1009,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1001,9 +1019,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1014,9 +1030,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1027,9 +1041,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1039,9 +1051,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1057,9 +1067,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1075,9 +1083,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1093,9 +1099,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1113,9 +1117,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1129,9 +1131,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1143,9 +1143,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1157,9 +1155,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1171,9 +1167,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1185,13 +1179,11 @@ namespace Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1203,13 +1195,11 @@ namespace const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1230,9 +1220,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1245,9 +1233,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1267,9 +1253,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1291,7 +1275,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1306,9 +1292,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1323,7 +1307,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1338,9 +1324,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1357,7 +1341,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1373,9 +1359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1391,7 +1375,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1412,9 +1398,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1433,7 +1417,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1460,9 +1446,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1481,9 +1465,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1494,7 +1476,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1561,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1573,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1585,7 +1573,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1610,9 +1600,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1637,7 +1625,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1652,7 +1642,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1667,7 +1659,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1682,7 +1676,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1705,9 +1701,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1733,7 +1727,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1748,7 +1744,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1764,7 +1762,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1789,9 +1789,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1814,9 +1812,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1837,9 +1833,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1863,7 +1857,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1891,7 +1887,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1913,9 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1928,9 +1924,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1941,9 +1935,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1963,9 +1955,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1979,7 +1969,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1997,9 +1989,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2013,7 +2003,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2028,11 +2020,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -2051,9 +2047,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -2066,7 +2060,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2087,9 +2083,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -2102,9 +2096,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2118,7 +2110,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2132,11 +2126,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2155,9 +2153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2170,7 +2166,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2189,9 +2187,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2204,7 +2200,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2225,9 +2223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2241,7 +2237,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2260,9 +2258,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -2274,9 +2270,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2289,7 +2283,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2303,7 +2299,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2316,9 +2314,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2331,7 +2327,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2345,7 +2343,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2363,10 +2363,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); @@ -2377,9 +2374,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2392,7 +2387,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2406,7 +2403,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2419,9 +2418,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2434,7 +2431,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2448,7 +2447,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2467,9 +2468,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2482,7 +2481,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2495,9 +2496,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2510,7 +2509,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2528,9 +2529,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2543,7 +2542,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2556,9 +2557,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2571,7 +2570,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2590,9 +2591,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2604,9 +2603,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2619,7 +2616,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2633,7 +2632,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2646,9 +2647,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2660,9 +2659,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2675,7 +2672,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2689,7 +2688,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2707,9 +2708,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2721,9 +2720,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2736,7 +2733,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2750,7 +2749,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2763,9 +2764,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2777,9 +2776,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2792,7 +2789,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2806,7 +2805,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2825,9 +2826,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2839,9 +2838,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2854,7 +2851,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2868,7 +2867,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2881,9 +2882,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2895,9 +2894,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2910,7 +2907,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2924,7 +2923,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2943,9 +2944,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2958,7 +2957,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2971,9 +2972,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2986,7 +2985,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3005,9 +3006,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3019,9 +3018,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3034,7 +3031,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3048,7 +3047,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3061,9 +3062,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3075,9 +3074,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3090,7 +3087,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3104,7 +3103,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3123,9 +3124,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3140,7 +3139,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3155,9 +3156,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3172,7 +3171,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3193,9 +3194,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3207,9 +3206,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3222,7 +3219,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3236,7 +3235,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3249,9 +3250,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3263,9 +3262,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3278,7 +3275,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3292,7 +3291,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3311,9 +3312,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3326,7 +3325,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3339,9 +3340,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3354,7 +3353,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3376,9 +3377,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3391,7 +3390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3404,9 +3405,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3419,7 +3418,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3436,9 +3437,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3455,9 +3454,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3468,9 +3465,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3483,9 +3478,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3498,9 +3491,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3513,9 +3504,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3528,9 +3517,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3755,13 +3742,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3776,9 +3761,7 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3799,13 +3782,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3827,13 +3808,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -5390,25 +5369,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5421,7 +5400,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5455,10 +5434,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5481,7 +5460,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5640,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -5656,9 +5635,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5673,28 +5650,11 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - TextBuffer buffer1{0}; - Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 4f4c6cb0d..0da7930e4 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u32string.h" @@ -97,7 +98,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -119,9 +119,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -129,19 +127,17 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); @@ -153,9 +149,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -165,7 +159,9 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -180,9 +176,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -197,7 +191,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -212,9 +208,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -229,7 +223,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -244,9 +240,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -261,7 +255,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -274,9 +270,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -289,7 +283,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -322,9 +318,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -334,9 +328,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -347,7 +339,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -357,7 +351,7 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -372,9 +366,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -389,7 +381,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -402,9 +394,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -419,7 +409,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -434,10 +426,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -451,8 +441,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -470,10 +463,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -491,8 +482,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -509,10 +503,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -529,8 +521,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -543,9 +538,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -558,7 +551,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -572,9 +567,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -601,9 +594,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -612,40 +603,39 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; Text text(initial_text.c_str(), INITIAL_SIZE); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -656,46 +646,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -708,24 +696,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -739,35 +725,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -780,7 +766,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -793,16 +779,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); @@ -817,17 +803,17 @@ namespace Text text(initial_text.c_str(), INITIAL_SIZE); // Overwrite from index 1 to one less than the new size and set to that size. - text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } - - return i; - }); + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -851,10 +837,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -864,9 +847,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -876,9 +857,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -887,9 +866,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -899,9 +876,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -911,9 +886,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -922,9 +895,7 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -938,9 +909,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -954,9 +923,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -970,10 +937,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -988,10 +952,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1002,9 +963,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1014,9 +973,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1026,9 +983,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1038,9 +993,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1051,13 +1004,11 @@ namespace Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1068,13 +1019,11 @@ namespace const Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1091,9 +1040,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1105,9 +1052,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1125,9 +1070,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1145,7 +1088,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1159,9 +1104,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1175,7 +1118,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1189,9 +1134,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1207,7 +1150,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1222,9 +1167,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1239,14 +1182,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1259,16 +1204,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) { const size_t INITIAL_SIZE = SIZE; - const size_t EXCESS_SIZE = SIZE + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1279,7 +1222,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1304,9 +1249,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1323,9 +1266,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1336,7 +1277,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1362,10 +1305,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; @@ -1392,37 +1335,43 @@ namespace const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1435,20 +1384,18 @@ namespace TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1461,63 +1408,71 @@ namespace TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1527,22 +1482,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1551,22 +1504,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1576,12 +1531,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1592,12 +1549,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1608,32 +1567,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1641,9 +1598,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1662,20 +1617,18 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - TextSTD compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); + Text text(initial_text.cbegin(), initial_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1684,7 +1637,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1692,13 +1647,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(longer_text.cbegin(), longer_text.cend()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1707,7 +1662,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1715,9 +1672,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(0, insert, 0, insert.size()); compare_text.insert(0, insert_text, 0, insert_text.size()); @@ -1725,12 +1682,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1740,12 +1695,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -1753,9 +1706,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1771,9 +1722,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1787,7 +1736,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1804,9 +1755,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1820,14 +1769,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { -#include "etl/private/diagnostic_array_bounds_push.h" + //#include "etl/private/diagnostic_array_bounds_push.h" Text text(short_text.c_str()); TextS append(short_text.c_str()); #if ETL_HAS_STRING_TRUNCATION_CHECKS @@ -1836,9 +1787,11 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" + //#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1854,7 +1807,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1868,7 +1821,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1880,13 +1835,13 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::u32string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1901,7 +1856,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1916,7 +1871,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1931,7 +1888,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1949,7 +1908,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1963,7 +1922,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1981,7 +1942,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1995,7 +1956,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2013,7 +1976,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2028,7 +1991,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2046,7 +2011,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2060,7 +2025,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2074,7 +2039,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2088,7 +2055,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2102,7 +2071,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2116,7 +2085,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2130,7 +2101,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2148,7 +2121,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2162,7 +2135,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2176,7 +2149,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2190,7 +2165,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2204,7 +2181,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2218,7 +2195,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2232,7 +2211,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2250,7 +2231,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2264,7 +2245,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2278,7 +2261,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2292,7 +2275,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2310,7 +2295,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2324,7 +2309,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2338,7 +2325,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2352,7 +2339,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2370,7 +2359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2384,7 +2373,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2398,7 +2387,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2412,7 +2403,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2426,7 +2419,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2440,7 +2433,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2454,7 +2447,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2468,7 +2463,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2486,7 +2483,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2500,7 +2497,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2514,7 +2511,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2528,7 +2527,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2542,7 +2543,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2556,7 +2557,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2570,7 +2571,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2584,7 +2587,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2595,112 +2600,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2711,56 +2724,60 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2771,112 +2788,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2887,14 +2912,14 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2903,14 +2928,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2919,14 +2946,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2935,14 +2962,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2962,7 +2991,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2976,7 +3005,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2990,7 +3019,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3004,7 +3035,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3018,7 +3051,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -3032,7 +3065,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3046,7 +3079,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3060,7 +3095,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3078,7 +3115,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3092,7 +3129,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3106,7 +3145,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3120,7 +3159,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3141,7 +3182,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3155,7 +3196,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3169,7 +3212,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3183,7 +3226,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3200,7 +3245,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3217,7 +3262,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3234,7 +3279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3246,7 +3291,7 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3259,7 +3304,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3272,7 +3317,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3285,7 +3330,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3298,7 +3343,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3343,7 +3388,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -3358,17 +3403,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3378,8 +3423,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -3393,17 +3438,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3428,17 +3473,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3448,8 +3493,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -3463,17 +3508,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -3493,12 +3538,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3513,7 +3558,7 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3534,12 +3579,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3560,12 +3605,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3580,8 +3625,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3640,8 +3685,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3654,7 +3699,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(TextL::npos, position2); } @@ -3669,8 +3714,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3683,7 +3728,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(TextL::npos, position2); } @@ -3825,7 +3870,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3853,7 +3898,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3872,14 +3917,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); @@ -3898,14 +3943,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); @@ -3923,12 +3968,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u32string::npos; + etl::iu32string::size_type position1 = TextL::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); @@ -5062,25 +5107,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5089,8 +5134,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5105,7 +5150,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -5120,10 +5165,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5144,7 +5189,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5290,7 +5337,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5305,7 +5352,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5320,27 +5367,11 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - Text text1 = STR("Hello World"); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 1187091fe..3c02629cf 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u32string.h" #include "etl/fnv_1.h" @@ -130,9 +131,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -146,9 +145,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -161,9 +158,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -176,9 +171,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -191,9 +184,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -206,9 +197,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -227,9 +216,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -240,7 +227,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -256,9 +245,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -274,7 +261,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -290,9 +279,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -308,7 +295,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -324,9 +313,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -342,7 +329,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -356,9 +345,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -372,7 +359,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -443,7 +432,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -457,7 +448,9 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -495,7 +488,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -511,9 +506,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -531,7 +524,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -549,10 +544,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -569,8 +562,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -615,8 +611,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -636,10 +635,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -659,8 +656,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -674,9 +674,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -690,7 +688,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -707,6 +707,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -723,6 +725,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -736,9 +740,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -779,9 +781,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -800,9 +800,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -817,7 +815,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -832,9 +832,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -855,9 +853,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -933,6 +929,32 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { @@ -944,16 +966,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -976,9 +998,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -989,9 +1009,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1001,9 +1019,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1014,9 +1030,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1027,9 +1041,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1039,9 +1051,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1057,9 +1067,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1075,9 +1083,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1093,9 +1099,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1113,9 +1117,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1129,9 +1131,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1143,9 +1143,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1157,9 +1155,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1171,9 +1167,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1185,13 +1179,11 @@ namespace Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1203,13 +1195,11 @@ namespace const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1230,9 +1220,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1245,9 +1233,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1267,9 +1253,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1291,7 +1275,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1306,9 +1292,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1323,7 +1307,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1338,9 +1324,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1357,7 +1341,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1373,9 +1359,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1391,7 +1375,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1412,9 +1398,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1433,7 +1417,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1460,9 +1446,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1481,9 +1465,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1494,7 +1476,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1561,7 +1545,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1573,7 +1559,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1585,7 +1573,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1610,9 +1600,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1637,7 +1625,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1652,7 +1642,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1667,7 +1659,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1682,7 +1676,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1705,9 +1701,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1733,7 +1727,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1748,7 +1744,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1764,7 +1762,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1789,9 +1789,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1814,9 +1812,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1837,9 +1833,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1863,7 +1857,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1891,7 +1887,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1913,9 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1928,9 +1924,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1941,9 +1935,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1963,9 +1955,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1979,7 +1969,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1997,9 +1989,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2013,7 +2003,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2028,11 +2020,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -2051,9 +2047,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -2066,7 +2060,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2087,9 +2083,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -2102,9 +2096,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2118,7 +2110,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2132,11 +2126,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2155,9 +2153,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2170,7 +2166,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2189,9 +2187,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2204,7 +2200,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2225,9 +2223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2241,7 +2237,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2260,9 +2258,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -2274,9 +2270,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2289,7 +2283,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2303,7 +2299,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2316,9 +2314,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2331,7 +2327,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2345,7 +2343,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2363,10 +2363,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); @@ -2377,9 +2374,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2392,7 +2387,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2406,7 +2403,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2419,9 +2418,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2434,7 +2431,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2448,7 +2447,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2467,9 +2468,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2482,7 +2481,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2495,9 +2496,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2510,7 +2509,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2528,9 +2529,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2543,7 +2542,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2556,9 +2557,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2571,7 +2570,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2590,9 +2591,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2604,9 +2603,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2619,7 +2616,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2633,7 +2632,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2646,9 +2647,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2660,9 +2659,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2675,7 +2672,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2689,7 +2688,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2707,9 +2708,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2721,9 +2720,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2736,7 +2733,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2750,7 +2749,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2763,9 +2764,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2777,9 +2776,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2792,7 +2789,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2806,7 +2805,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2825,9 +2826,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2839,9 +2838,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2854,7 +2851,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2868,7 +2867,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2881,9 +2882,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2895,9 +2894,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2910,7 +2907,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2924,7 +2923,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2943,9 +2944,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2958,7 +2957,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2971,9 +2972,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2986,7 +2985,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3005,9 +3006,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3019,9 +3018,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3034,7 +3031,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3048,7 +3047,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3061,9 +3062,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3075,9 +3074,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3090,7 +3087,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3104,7 +3103,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3123,9 +3124,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3140,7 +3139,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3155,9 +3156,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3172,7 +3171,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3193,9 +3194,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3207,9 +3206,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3222,7 +3219,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3236,7 +3235,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3249,9 +3250,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3263,9 +3262,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3278,7 +3275,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3292,7 +3291,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3311,9 +3312,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3326,7 +3325,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3339,9 +3340,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3354,7 +3353,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3376,9 +3377,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3391,7 +3390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3404,9 +3405,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3419,7 +3418,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3436,9 +3437,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3455,9 +3454,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3468,9 +3465,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3483,9 +3478,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3498,9 +3491,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3513,9 +3504,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3528,9 +3517,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3755,13 +3742,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3776,9 +3761,7 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3799,13 +3782,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3827,13 +3808,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -5390,25 +5369,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5421,7 +5400,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5455,10 +5434,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5481,7 +5460,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5640,9 +5621,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -5656,9 +5635,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5673,28 +5650,11 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - TextBuffer buffer1{0}; - Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index e105ed197..224d24c19 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -34,6 +34,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u8string.h" @@ -100,7 +101,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -122,9 +122,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -132,19 +130,17 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); @@ -156,9 +152,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -168,7 +162,9 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -183,9 +179,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -200,7 +194,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -215,9 +211,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -232,7 +226,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -247,9 +243,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -264,7 +258,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -277,9 +273,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -292,7 +286,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -325,9 +321,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -337,9 +331,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -350,7 +342,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -360,7 +354,7 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -375,9 +369,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -392,7 +384,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -405,24 +397,24 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -437,10 +429,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -454,8 +444,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -473,10 +466,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -494,8 +485,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -512,10 +506,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -532,8 +524,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -546,9 +541,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -561,7 +554,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -575,9 +570,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -604,9 +597,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -615,40 +606,39 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; Text text(initial_text.c_str(), INITIAL_SIZE); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -659,46 +649,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -711,24 +699,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -742,35 +728,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -783,7 +769,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -793,19 +779,19 @@ namespace const size_t NEW_SIZE = 8UL; Text text(initial_text.c_str(), INITIAL_SIZE); - + // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); @@ -820,17 +806,17 @@ namespace Text text(initial_text.c_str(), INITIAL_SIZE); // Overwrite from index 1 to one less than the new size and set to that size. - text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } - - return i; - }); + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -854,10 +840,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -867,9 +850,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -879,9 +860,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -890,9 +869,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -902,9 +879,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -914,9 +889,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -925,9 +898,7 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -941,9 +912,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -957,9 +926,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -973,10 +940,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -991,10 +955,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1005,9 +966,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1017,9 +976,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1029,9 +986,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1041,9 +996,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1054,13 +1007,11 @@ namespace Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1071,13 +1022,11 @@ namespace const Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1094,9 +1043,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1108,9 +1055,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1128,9 +1073,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1148,7 +1091,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1162,9 +1107,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1178,7 +1121,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1192,9 +1137,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1210,7 +1153,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1225,9 +1170,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1242,14 +1185,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1262,16 +1207,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) { const size_t INITIAL_SIZE = SIZE; - const size_t EXCESS_SIZE = SIZE + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1282,7 +1225,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1307,9 +1252,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1326,9 +1269,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1339,7 +1280,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1365,10 +1308,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; @@ -1395,37 +1338,43 @@ namespace const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1438,20 +1387,18 @@ namespace TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1464,63 +1411,71 @@ namespace TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1530,22 +1485,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1554,22 +1507,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1579,12 +1534,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1595,12 +1552,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1611,32 +1570,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1644,9 +1601,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1665,20 +1620,18 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - TextSTD compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); + Text text(initial_text.cbegin(), initial_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1687,7 +1640,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1695,13 +1650,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(longer_text.cbegin(), longer_text.cend()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1710,7 +1665,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1718,9 +1675,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(0, insert, 0, insert.size()); compare_text.insert(0, insert_text, 0, insert_text.size()); @@ -1728,12 +1685,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1743,12 +1698,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -1756,9 +1709,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1774,9 +1725,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1790,7 +1739,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1807,9 +1758,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1823,14 +1772,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { -#include "etl/private/diagnostic_array_bounds_push.h" + //#include "etl/private/diagnostic_array_bounds_push.h" Text text(short_text.c_str()); TextS append(short_text.c_str()); #if ETL_HAS_STRING_TRUNCATION_CHECKS @@ -1839,9 +1790,11 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" + //#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1857,7 +1810,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1871,7 +1824,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1883,13 +1838,13 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::u8string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1904,7 +1859,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1919,7 +1874,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1934,7 +1891,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1952,7 +1911,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1966,7 +1925,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1984,7 +1945,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1998,7 +1959,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2016,7 +1979,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2031,7 +1994,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2049,7 +2014,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2063,7 +2028,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2077,7 +2042,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2091,7 +2058,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2105,7 +2074,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2119,7 +2088,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2133,7 +2104,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2151,7 +2124,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2165,7 +2138,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2179,7 +2152,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2193,7 +2168,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2207,7 +2184,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2221,7 +2198,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2235,7 +2214,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2253,7 +2234,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2267,7 +2248,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2281,7 +2264,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2295,7 +2278,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2313,7 +2298,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2327,7 +2312,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2341,7 +2328,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2355,7 +2342,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2373,7 +2362,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2387,7 +2376,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2401,7 +2390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2415,7 +2406,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2429,7 +2422,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2443,7 +2436,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2457,7 +2450,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2471,7 +2466,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2489,7 +2486,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2503,7 +2500,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2517,7 +2514,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2531,7 +2530,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2545,7 +2546,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2559,7 +2560,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2573,7 +2574,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2587,7 +2590,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2605,7 +2610,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2619,7 +2624,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2633,7 +2638,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2647,7 +2654,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2661,7 +2670,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2675,7 +2684,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2689,7 +2698,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2703,7 +2714,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2721,7 +2734,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2735,7 +2748,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2749,7 +2764,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2763,7 +2778,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2781,7 +2798,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2795,7 +2812,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2809,7 +2826,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2823,7 +2842,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2837,7 +2858,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2851,7 +2872,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2865,7 +2886,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2879,7 +2902,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2897,7 +2922,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2913,7 +2938,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2929,7 +2956,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2945,7 +2972,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2965,7 +2994,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2979,7 +3008,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2993,7 +3022,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3007,7 +3038,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3021,7 +3054,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -3035,7 +3068,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3049,7 +3082,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3063,7 +3098,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3081,7 +3118,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3095,7 +3132,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3109,7 +3148,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3123,7 +3162,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3144,7 +3185,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3158,7 +3199,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3172,7 +3215,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3186,7 +3229,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3203,7 +3248,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3220,7 +3265,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3237,7 +3282,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3249,7 +3294,7 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3262,7 +3307,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3275,7 +3320,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3288,7 +3333,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3301,7 +3346,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3346,7 +3391,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -3361,17 +3406,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3381,8 +3426,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -3396,17 +3441,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3431,17 +3476,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3451,8 +3496,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -3466,17 +3511,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -3496,7 +3541,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3516,7 +3561,7 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3537,7 +3582,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3563,7 +3608,7 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, @@ -3583,8 +3628,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3643,8 +3688,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3657,7 +3702,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(TextL::npos, position2); } @@ -3672,8 +3717,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3686,7 +3731,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(TextL::npos, position2); } @@ -3828,7 +3873,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3856,7 +3901,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3875,14 +3920,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); @@ -3901,14 +3946,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); @@ -3926,12 +3971,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::u8string::npos; + etl::iu8string::size_type position1 = TextL::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); @@ -5065,25 +5110,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5092,8 +5137,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5108,7 +5153,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -5123,10 +5168,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5147,7 +5192,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5293,7 +5340,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5308,7 +5355,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5323,29 +5370,12 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - Text text1 = STR("Hello World"); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } - -#endif +#endif \ No newline at end of file diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index 1494e7084..296ee6690 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -34,6 +34,7 @@ SOFTWARE. #include #include #include +#include #include "etl/u8string.h" #include "etl/fnv_1.h" @@ -133,9 +134,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -149,9 +148,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -164,9 +161,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -179,9 +174,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -194,9 +187,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -209,9 +200,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -230,9 +219,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -243,7 +230,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -259,9 +248,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -277,7 +264,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -293,9 +282,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -311,7 +298,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -327,9 +316,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -345,7 +332,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -359,9 +348,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -375,7 +362,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -446,7 +435,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -460,7 +451,9 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -498,7 +491,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -514,9 +509,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -534,7 +527,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -552,10 +547,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -572,8 +565,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -618,8 +614,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -639,10 +638,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -662,8 +659,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -677,9 +677,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -693,7 +691,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -710,6 +710,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -726,6 +728,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -739,9 +743,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -782,9 +784,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -803,9 +803,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -820,7 +818,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -835,9 +835,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -858,9 +856,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -947,16 +943,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); @@ -973,16 +969,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -1005,9 +1001,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1018,9 +1012,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1030,9 +1022,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1043,9 +1033,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1056,9 +1044,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1068,9 +1054,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1086,9 +1070,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1104,9 +1086,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1122,9 +1102,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1142,9 +1120,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1158,9 +1134,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1172,9 +1146,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1186,9 +1158,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1200,9 +1170,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1214,13 +1182,11 @@ namespace Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1232,13 +1198,11 @@ namespace const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1259,9 +1223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1274,9 +1236,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1296,9 +1256,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1320,7 +1278,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1335,9 +1295,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1352,7 +1310,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1367,9 +1327,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1386,7 +1344,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1402,9 +1362,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1420,7 +1378,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1441,9 +1401,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1462,7 +1420,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1489,9 +1449,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1510,9 +1468,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1523,7 +1479,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1590,7 +1548,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1602,7 +1562,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1614,7 +1576,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1639,9 +1603,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1666,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1681,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1696,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1711,7 +1679,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1734,9 +1704,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1762,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1777,7 +1747,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1793,7 +1765,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1818,9 +1792,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1843,9 +1815,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1866,9 +1836,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1892,7 +1860,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1920,7 +1890,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1942,9 +1914,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1957,9 +1927,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1970,9 +1938,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1992,9 +1958,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2008,7 +1972,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2026,9 +1992,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2042,7 +2006,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2057,11 +2023,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -2080,9 +2050,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -2095,7 +2063,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2116,9 +2086,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -2131,9 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2147,7 +2113,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2161,11 +2129,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2184,9 +2156,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2199,7 +2169,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2218,9 +2190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2233,7 +2203,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2254,9 +2226,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2270,7 +2240,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2289,9 +2261,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -2303,9 +2273,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2318,7 +2286,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2332,7 +2302,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2345,9 +2317,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2360,7 +2330,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2374,7 +2346,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2392,10 +2366,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); @@ -2406,9 +2377,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2421,7 +2390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2435,7 +2406,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2448,9 +2421,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2463,7 +2434,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2477,7 +2450,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2496,9 +2471,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2511,7 +2484,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2524,9 +2499,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2539,7 +2512,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2557,9 +2532,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2572,7 +2545,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2585,9 +2560,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2600,7 +2573,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2619,9 +2594,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2633,9 +2606,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2648,7 +2619,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2662,7 +2635,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2675,9 +2650,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2689,9 +2662,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2704,7 +2675,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2718,7 +2691,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2736,9 +2711,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2750,9 +2723,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2765,7 +2736,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2779,7 +2752,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2792,9 +2767,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2806,9 +2779,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2821,7 +2792,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2835,7 +2808,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2854,9 +2829,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2868,9 +2841,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2883,7 +2854,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2897,7 +2870,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2910,9 +2885,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2924,9 +2897,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2939,7 +2910,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2953,7 +2926,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2972,9 +2947,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2987,7 +2960,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3000,9 +2975,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3015,7 +2988,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3034,9 +3009,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3048,9 +3021,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3063,7 +3034,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3077,7 +3050,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3090,9 +3065,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3104,9 +3077,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3119,7 +3090,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3133,7 +3106,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3152,9 +3127,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3169,7 +3142,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3184,9 +3159,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3201,7 +3174,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3222,9 +3197,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3236,9 +3209,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3251,7 +3222,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3265,7 +3238,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3278,9 +3253,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3292,9 +3265,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3307,7 +3278,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3321,7 +3294,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3340,9 +3315,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3355,7 +3328,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3368,9 +3343,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3383,7 +3356,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3405,9 +3380,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3420,7 +3393,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3433,9 +3408,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3448,7 +3421,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3465,9 +3440,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3484,9 +3457,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3497,9 +3468,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3512,9 +3481,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3527,9 +3494,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3542,9 +3507,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3557,9 +3520,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3784,13 +3745,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3805,9 +3764,7 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3828,13 +3785,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3856,13 +3811,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3962,6 +3915,37 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + const value_t* needle = STR("needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = 0; + size_t position2 = 0; + + position1 = compare_haystack.find(needle, position1, 3); + position2 = haystack.find(needle, position2, 3); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(needle, position1 + 1, 3); + position2 = haystack.find(needle, position2 + 1, 3); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1, 3); + CHECK_EQUAL(IText::npos, position2); + + const value_t *pin = STR("pin"); + position2 = haystack.find(pin, 0, 3); + CHECK_EQUAL(IText::npos, position2); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_contains_string) { @@ -4107,37 +4091,6 @@ namespace CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - const value_t* needle = STR("needle"); - - TextSTD compare_haystack(the_haystack); - - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); - - size_t position1 = 0; - size_t position2 = 0; - - position1 = compare_haystack.find(needle, position1, 3); - position2 = haystack.find(needle, position2, 3); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(needle, position1 + 1, 3); - position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(IText::npos, position2); - - const value_t *pin = STR("pin"); - position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(IText::npos, position2); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { @@ -5419,25 +5372,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5450,7 +5403,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5484,10 +5437,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5510,7 +5463,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5669,9 +5624,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -5685,9 +5638,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5702,29 +5653,12 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } - - //************************************************************************* -#if ETL_USING_STL - TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) - { - TextBuffer buffer1{0}; - Text text1(STR("Hello World"), buffer1.data(), buffer1.size()); - - std::basic_stringstream sstream; - - sstream << text1; - - TextSTD sstream_string = sstream.str(); - - View sstream_view(sstream_string.data(), sstream_string.size()); - - CHECK(text1 == sstream_view); - } -#endif }; } diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index d28ba6d64..1a2acec52 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/wstring.h" @@ -98,7 +99,6 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); initial_text = STR("Hello World"); insert_text = STR("Insert"); less_text = STR("Hello Vorld"); @@ -120,9 +120,7 @@ namespace CHECK_EQUAL(text.capacity(), SIZE); CHECK_EQUAL(text.max_size(), SIZE); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -130,19 +128,17 @@ namespace { Text text; - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); @@ -154,9 +150,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -166,7 +160,9 @@ namespace CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -181,9 +177,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -198,7 +192,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -213,9 +209,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -230,7 +224,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -245,9 +241,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -262,7 +256,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -275,9 +271,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -290,7 +284,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -323,9 +319,7 @@ namespace Text text(initial_text.c_str()); Text text2(text); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -335,9 +329,7 @@ namespace IText& itext = text; Text text2(itext); CHECK(text2 == text); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -348,7 +340,9 @@ namespace Text text2(textl); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -358,7 +352,7 @@ namespace Text text(longer_text.c_str()); Text text2(text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -373,9 +367,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -390,7 +382,7 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); #endif } @@ -403,9 +395,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -420,7 +410,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -435,10 +427,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -452,8 +442,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -471,10 +464,8 @@ namespace bool is_equal = Equal(text1, text2); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text1.is_truncated()); - CHECK(!text2.is_truncated()); -#endif + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); } //************************************************************************* @@ -492,8 +483,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -510,10 +504,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -530,8 +522,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -544,9 +539,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -559,7 +552,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -573,9 +568,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); -#endif } //************************************************************************* @@ -602,9 +595,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -613,40 +604,39 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; Text text(initial_text.c_str(), INITIAL_SIZE); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_up_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -657,46 +647,44 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; Text text(INITIAL_SIZE, STR('A')); text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_down_value) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); Text text(INITIAL_SIZE, INITIAL_VALUE); @@ -709,24 +697,22 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 8; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -740,35 +726,35 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up_excess) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = SIZE + 1; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = SIZE + 1UL; Text text(INITIAL_SIZE, STR('A')); text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; - const size_t NEW_SIZE = 2; + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 2UL; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); Text text(INITIAL_SIZE, INITIAL_VALUE); Text::pointer pbegin = &text.front(); - Text::pointer pend = &text.back() + 1; - Text::pointer pmax = pbegin + text.max_size(); + Text::pointer pend = &text.back() + 1; + Text::pointer pmax = pbegin + text.max_size(); // Fill free space with a pattern. std::fill(pend, pmax, FILL_VALUE); @@ -781,7 +767,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -794,16 +780,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); @@ -818,17 +804,17 @@ namespace Text text(initial_text.c_str(), INITIAL_SIZE); // Overwrite from index 1 to one less than the new size and set to that size. - text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } - - return i; - }); + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -852,10 +838,7 @@ namespace bool is_equal = Equal(expected, text); CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -865,9 +848,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -877,9 +858,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -888,9 +867,7 @@ namespace Text text; CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -900,9 +877,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -912,9 +887,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -923,9 +896,7 @@ namespace Text text; CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -939,9 +910,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -955,9 +924,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -971,10 +938,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -989,10 +953,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1003,9 +964,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1015,9 +974,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1027,9 +984,7 @@ namespace Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1039,9 +994,7 @@ namespace const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1052,13 +1005,11 @@ namespace Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1069,13 +1020,11 @@ namespace const Text text(compare_text.begin(), compare_text.end()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data_end(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1092,9 +1041,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1106,9 +1053,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1126,9 +1071,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1146,7 +1089,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1160,9 +1105,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1176,7 +1119,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1190,9 +1135,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1208,7 +1151,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1223,9 +1168,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1240,14 +1183,16 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; @@ -1260,16 +1205,14 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value_excess) { const size_t INITIAL_SIZE = SIZE; - const size_t EXCESS_SIZE = SIZE + 1; + const size_t EXCESS_SIZE = SIZE + 1UL; const value_t INITIAL_VALUE = STR('A'); std::array compare_text; compare_text.fill(INITIAL_VALUE); @@ -1280,7 +1223,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1305,9 +1250,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1324,9 +1267,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1337,7 +1278,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1363,10 +1306,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; @@ -1393,37 +1336,43 @@ namespace const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1436,20 +1385,18 @@ namespace TextSTD compare_text; Text text; - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1462,63 +1409,71 @@ namespace TextSTD compare_text; Text text; - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1528,22 +1483,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { TextSTD compare_text; Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + CHECK_FALSE(text.is_truncated()); +# bool is_equal = Equal(compare_text, text); CHECK(is_equal); } @@ -1552,22 +1505,24 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); TextSTD compare_text; Text text; - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1577,12 +1532,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1593,12 +1550,14 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1609,32 +1568,30 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_self) { - size_t length = TextL::MAX_SIZE / 2; + size_t length = TextL::MAX_SIZE / 2UL; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1642,9 +1599,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1663,20 +1618,18 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - TextSTD compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); + Text text(initial_text.cbegin(), initial_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1685,7 +1638,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1693,13 +1648,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(longer_text.cbegin(), longer_text.cend()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1708,7 +1663,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1716,9 +1673,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - TextSTD compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(0, insert, 0, insert.size()); compare_text.insert(0, insert_text, 0, insert_text.size()); @@ -1726,12 +1683,10 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1741,12 +1696,10 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -1754,9 +1707,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1772,9 +1723,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1788,7 +1737,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1805,9 +1756,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1821,14 +1770,16 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { -#include "etl/private/diagnostic_array_bounds_push.h" + //#include "etl/private/diagnostic_array_bounds_push.h" Text text(short_text.c_str()); TextS append(short_text.c_str()); #if ETL_HAS_STRING_TRUNCATION_CHECKS @@ -1837,9 +1788,11 @@ namespace text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" + //#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1855,7 +1808,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1869,7 +1822,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1881,13 +1836,13 @@ namespace Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::wstring::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Partial string. @@ -1902,7 +1857,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1917,7 +1872,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1932,7 +1889,9 @@ namespace text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1950,7 +1909,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1964,7 +1923,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1982,7 +1943,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -1996,7 +1957,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2014,7 +1977,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2029,7 +1992,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2047,7 +2012,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2061,7 +2026,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2075,7 +2040,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2089,7 +2056,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2103,7 +2072,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2117,7 +2086,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2131,7 +2102,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2149,7 +2122,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text. @@ -2163,7 +2136,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2177,7 +2150,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2191,7 +2166,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2205,7 +2182,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2219,7 +2196,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2233,7 +2212,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2251,7 +2232,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2265,7 +2246,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2279,7 +2262,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2293,7 +2276,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2311,7 +2296,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2325,7 +2310,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2339,7 +2326,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2353,7 +2340,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2371,7 +2360,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2385,7 +2374,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2399,7 +2388,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2413,7 +2404,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2427,7 +2420,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2441,7 +2434,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2455,7 +2448,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2469,7 +2464,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2487,7 +2484,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2501,7 +2498,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2515,7 +2512,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2529,7 +2528,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2543,7 +2544,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -2557,7 +2558,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -2571,7 +2572,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2585,7 +2588,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2596,112 +2601,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2712,56 +2725,60 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2772,112 +2789,120 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2888,14 +2913,14 @@ namespace TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2904,14 +2929,16 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2920,14 +2947,14 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_array_bounds_push.h" @@ -2936,14 +2963,16 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -2963,7 +2992,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow short text, npos. @@ -2977,7 +3006,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -2991,7 +3020,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3005,7 +3036,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3019,7 +3052,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow, npos. @@ -3033,7 +3066,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3047,7 +3080,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3061,7 +3096,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3079,7 +3116,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3093,7 +3130,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3107,7 +3146,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3121,7 +3160,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3142,7 +3183,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text. @@ -3156,7 +3197,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3170,7 +3213,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif // Overflow. @@ -3184,7 +3227,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3201,7 +3246,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3218,7 +3263,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3235,7 +3280,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3247,7 +3292,7 @@ namespace CHECK_EQUAL(text.size(), size_t(0)); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3260,7 +3305,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3273,7 +3318,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3286,7 +3331,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3299,7 +3344,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3344,7 +3389,7 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); const Text greater(greater_text.c_str()); @@ -3359,17 +3404,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3379,8 +3424,8 @@ namespace const Text initial(initial_text.c_str()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); const Text greater(greater_text.c_str()); CHECK((greater <= initial) == (greater_text <= initial_text)); @@ -3394,17 +3439,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3429,17 +3474,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3449,8 +3494,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); const Text greater(greater_text.begin(), greater_text.end()); CHECK((greater >= initial) == (greater_text >= initial_text)); @@ -3464,17 +3509,17 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* @@ -3494,12 +3539,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3514,7 +3559,7 @@ namespace CHECK_EQUAL(0U, length1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif } @@ -3535,12 +3580,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3561,12 +3606,12 @@ namespace CHECK_EQUAL(length1, length2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3581,8 +3626,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); position2 = haystack.find(needle, position2); @@ -3641,8 +3686,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1); position2 = haystack.find(needle, position2); @@ -3655,7 +3700,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(TextL::npos, position2); } @@ -3670,8 +3715,8 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(needle, position1, 3); position2 = haystack.find(needle, position2, 3); @@ -3684,7 +3729,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(TextL::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(TextL::npos, position2); } @@ -3826,7 +3871,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3854,7 +3899,7 @@ namespace TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); @@ -3873,14 +3918,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); @@ -3899,14 +3944,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); @@ -3924,12 +3969,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_c_position) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); - size_t position1 = std::wstring::npos; + etl::iwstring::size_type position1 = TextL::npos; size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); @@ -5063,25 +5108,25 @@ namespace TEST_FIXTURE(SetupFixture, test_truncate_over_many_operations) { Text text(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5090,8 +5135,8 @@ namespace Text text1(short_text.c_str()); TextS text2(short_text.c_str()); - CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_FALSE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5106,7 +5151,7 @@ namespace Text text2(short_text.c_str()); CHECK(text1.is_truncated()); - CHECK(!text2.is_truncated()); + CHECK_FALSE(text2.is_truncated()); // Clear text but not the truncate flag. text1.erase(text1.begin(), text1.end()); @@ -5121,10 +5166,10 @@ namespace TEST_FIXTURE(SetupFixture, test_clear_truncated) { Text text(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5145,7 +5190,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5291,7 +5338,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5306,7 +5353,7 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5321,7 +5368,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } @@ -5330,7 +5379,7 @@ namespace #if ETL_USING_STL TEST_FIXTURE(SetupFixture, test_write_string_to_std_basic_ostream) { - Text text1 = STR("Hello World"); + Text text1(STR("Hello World")); std::wstringstream sstream; diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 16cc52a8d..36d18c8ff 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include #include #include +#include #include "etl/wstring.h" #include "etl/fnv_1.h" @@ -133,9 +134,7 @@ namespace CHECK_EQUAL(SIZE, text.capacity()); CHECK_EQUAL(SIZE, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -149,9 +148,7 @@ namespace CHECK_EQUAL(length, text.capacity()); CHECK_EQUAL(length, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -164,9 +161,7 @@ namespace CHECK_EQUAL(etl::strlen(p_text), text.capacity()); CHECK_EQUAL(etl::strlen(p_text), text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -179,9 +174,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() == text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -194,9 +187,7 @@ namespace CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.capacity()); CHECK_EQUAL(ETL_OR_STD17::size(array_text) - 1, text.max_size()); CHECK(text.begin() != text.end()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -209,9 +200,7 @@ namespace CHECK(text.cbegin() == text.cend()); CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -230,9 +219,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -243,7 +230,9 @@ namespace CHECK_EQUAL(buffer.size() - 1, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -259,9 +248,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -277,7 +264,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -293,9 +282,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -311,7 +298,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -327,9 +316,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -345,7 +332,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -359,9 +348,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -375,7 +362,9 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -446,7 +435,9 @@ namespace Text text2(textl, buffer2.data(), buffer2.size()); CHECK(text2 == text); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -460,7 +451,9 @@ namespace Text text2(text, buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -498,7 +491,9 @@ namespace bool is_equal = Equal(compare_text2, text2); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text2.is_truncated()); #endif } @@ -514,9 +509,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -534,7 +527,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } #endif @@ -552,10 +547,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -572,8 +565,11 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -618,8 +614,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text1.is_truncated()); + CHECK_TRUE(text2.is_truncated()); +#else + CHECK_FALSE(text1.is_truncated()); + CHECK_FALSE(text2.is_truncated()); #endif } @@ -639,10 +638,8 @@ namespace bool is_equal = Equal(text, other_text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); - CHECK(!other_text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); } //************************************************************************* @@ -662,8 +659,11 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); - CHECK(other_text.is_truncated()); + CHECK_TRUE(text.is_truncated()); + CHECK_TRUE(other_text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); + CHECK_FALSE(other_text.is_truncated()); #endif } @@ -677,9 +677,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -693,7 +691,9 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -710,6 +710,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -726,6 +728,8 @@ namespace CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); +#else + CHECK_FALSE(itext.is_truncated()); #endif } @@ -739,9 +743,7 @@ namespace bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -782,9 +784,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -803,9 +803,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } @@ -820,7 +818,9 @@ namespace text.resize(NEW_SIZE, STR('A')); CHECK_EQUAL(SIZE, text.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -835,9 +835,7 @@ namespace text.resize(NEW_SIZE); CHECK_EQUAL(text.size(), NEW_SIZE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -858,9 +856,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -936,6 +932,32 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) { @@ -947,16 +969,16 @@ namespace // Overwrite from index 1 to one less than the new size and set to that size. text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) - { - size_t i = 1; - while (i < (n - 1)) - { - p[i] = '1' + Text::value_type(i); - ++i; - } + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } - return i; - }); + return i; + }); CHECK_EQUAL(NEW_SIZE - 1, text.size()); CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); @@ -979,9 +1001,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -992,9 +1012,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1004,9 +1022,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(text.empty()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1017,9 +1033,7 @@ namespace text.resize(text.max_size(), STR('A')); CHECK(text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1030,9 +1044,7 @@ namespace text.resize(text.max_size() / 2, STR('A')); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1042,9 +1054,7 @@ namespace Text text(buffer.data(), buffer.size()); CHECK(!text.full()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1060,9 +1070,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1078,9 +1086,7 @@ namespace CHECK_EQUAL(text[i], compare_text[i]); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1096,9 +1102,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1116,9 +1120,7 @@ namespace CHECK_EQUAL(text.at(i), compare_text.at(i)); } -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_THROW(text.at(text.size()), etl::string_out_of_bounds); } @@ -1132,9 +1134,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1146,9 +1146,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.front() == compare_text.front()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1160,9 +1158,7 @@ namespace Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1174,9 +1170,7 @@ namespace const Text text(initial_text.c_str(), buffer.data(), buffer.size()); CHECK(text.back() == compare_text.back()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1188,13 +1182,11 @@ namespace Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1206,13 +1198,11 @@ namespace const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); bool is_equal = std::equal(text.data(), - text.data() + text.size(), - compare_text.begin()); + text.data() + text.size(), + compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1233,9 +1223,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1248,9 +1236,7 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1270,9 +1256,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1294,7 +1278,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1309,9 +1295,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1326,7 +1310,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1341,9 +1327,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1360,7 +1344,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1376,9 +1362,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1394,7 +1378,9 @@ namespace bool is_equal = Equal(initial_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1415,9 +1401,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1436,7 +1420,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1463,9 +1449,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1484,9 +1468,7 @@ namespace for (size_t i = 0UL; i < SIZE; ++i) { text.push_back(STR('A') + value_t(i)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } text.push_back(STR('A') + value_t(SIZE)); @@ -1497,7 +1479,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -1564,7 +1548,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1576,7 +1562,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1588,7 +1576,9 @@ namespace compare_text.erase(compare_text.cend() - 1); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1613,9 +1603,7 @@ namespace text.insert(text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INITIAL_VALUE); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1640,7 +1628,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1655,7 +1645,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1670,7 +1662,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1685,7 +1679,9 @@ namespace text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1708,9 +1704,7 @@ namespace text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1736,7 +1730,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif bool is_equal = Equal(compare_text, text); @@ -1751,7 +1747,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif is_equal = Equal(compare_text, text); @@ -1767,7 +1765,9 @@ namespace text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(compare_text.size(), text.size()); @@ -1792,9 +1792,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1817,9 +1815,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1840,9 +1836,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } } @@ -1866,7 +1860,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1894,7 +1890,9 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } } @@ -1916,9 +1914,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1931,9 +1927,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); compare_text.assign(short_text.cbegin(), short_text.cend()); text.assign(short_text.cbegin(), short_text.cend()); @@ -1944,9 +1938,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -1966,9 +1958,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -1982,7 +1972,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2000,9 +1992,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2016,7 +2006,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2031,11 +2023,15 @@ namespace Text append(short_text.c_str(), buffers.data(), buffers.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" } @@ -2054,9 +2050,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(shorter_text.c_str()); @@ -2069,7 +2063,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2090,9 +2086,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Partial string. compare_text.assign(short_text.c_str()); @@ -2105,9 +2099,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2121,7 +2113,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2135,11 +2129,15 @@ namespace Text append(short_text.c_str(), buffer2.data(), buffer2.size()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(append.is_truncated()); +#else + CHECK_FALSE(append.is_truncated()); #endif text.append(append, 1, 2); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2158,9 +2156,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2173,7 +2169,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2192,9 +2190,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2207,7 +2203,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2228,9 +2226,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(short_text.c_str()); @@ -2244,7 +2240,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2263,9 +2261,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); @@ -2277,9 +2273,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2292,7 +2286,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2306,7 +2302,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2319,9 +2317,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2334,7 +2330,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2348,7 +2346,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2366,10 +2366,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - + CHECK_FALSE(text.is_truncated()); // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); @@ -2380,9 +2377,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2395,7 +2390,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2409,7 +2406,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2422,9 +2421,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2437,7 +2434,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2451,7 +2450,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2470,9 +2471,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2485,7 +2484,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2498,9 +2499,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2513,7 +2512,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2531,9 +2532,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2546,7 +2545,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2559,9 +2560,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2574,7 +2573,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2593,9 +2594,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2607,9 +2606,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2622,7 +2619,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2636,7 +2635,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2649,9 +2650,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2663,9 +2662,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2678,7 +2675,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2692,7 +2691,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2710,9 +2711,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2724,9 +2723,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2739,7 +2736,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2753,7 +2752,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2766,9 +2767,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2780,9 +2779,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2795,7 +2792,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2809,7 +2808,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2828,9 +2829,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -2842,9 +2841,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2857,7 +2854,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -2871,7 +2870,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2884,9 +2885,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -2898,9 +2897,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2913,7 +2910,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -2927,7 +2926,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -2946,9 +2947,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -2961,7 +2960,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -2974,9 +2975,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -2989,7 +2988,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3008,9 +3009,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3022,9 +3021,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3037,7 +3034,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3051,7 +3050,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3064,9 +3065,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3078,9 +3077,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3093,7 +3090,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3107,7 +3106,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3126,9 +3127,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3143,7 +3142,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3158,9 +3159,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); #include "etl/private/diagnostic_array_bounds_push.h" #include "etl/private/diagnostic_stringop_overread_push.h" @@ -3175,7 +3174,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif #include "etl/private/diagnostic_pop.h" #include "etl/private/diagnostic_pop.h" @@ -3196,9 +3197,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); @@ -3210,9 +3209,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3225,7 +3222,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow short text, npos. @@ -3239,7 +3238,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3252,9 +3253,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Non-overflow, npos. compare_text.assign(initial_text.c_str()); @@ -3266,9 +3265,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3281,7 +3278,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Overflow, npos. @@ -3295,7 +3294,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3314,9 +3315,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3329,7 +3328,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3342,9 +3343,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3357,7 +3356,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3379,9 +3380,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow short text. compare_text.assign(short_text.c_str()); @@ -3394,7 +3393,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif // Non-overflow. @@ -3407,9 +3408,7 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); // Overflow. compare_text.assign(initial_text.c_str()); @@ -3422,7 +3421,9 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif } @@ -3439,9 +3440,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3458,9 +3457,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3471,9 +3468,7 @@ namespace text.clear(); CHECK_EQUAL(text.size(), size_t(0)); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3486,9 +3481,7 @@ namespace bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3501,9 +3494,7 @@ namespace bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3516,9 +3507,7 @@ namespace bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3531,9 +3520,7 @@ namespace bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3758,13 +3745,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3779,9 +3764,7 @@ namespace size_t length1 = text.copy(buffer1, 5, SIZE); CHECK_EQUAL(0U, length1); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -3802,13 +3785,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3830,13 +3811,11 @@ namespace buffer2[length2] = STR('\0'); CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -5393,25 +5372,25 @@ namespace { TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.insert(3, initial_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); while (text.size() != 0) { text.pop_back(); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); } text.clear(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); text.assign(longer_text.c_str()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.assign(short_text.c_str()); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } //************************************************************************* @@ -5424,7 +5403,7 @@ namespace Text text2(short_text.c_str(), buffers.data(), buffers.size()); CHECK(!text1.is_truncated()); - CHECK(text2.is_truncated()); + CHECK_TRUE(text2.is_truncated()); // text2 has the truncate flag set. text1 += text2; @@ -5458,10 +5437,10 @@ namespace { TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); text.clear_truncated(); - CHECK(!text.is_truncated()); + CHECK_FALSE(text.is_truncated()); } #endif @@ -5484,7 +5463,9 @@ namespace Text::pointer pe = text.end(); // Destroy the text object. + std::atomic_signal_fence(std::memory_order_seq_cst); text.~Text(); + std::atomic_signal_fence(std::memory_order_seq_cst); // Check there no non-zero values in the string. CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); @@ -5643,9 +5624,7 @@ namespace std::fill(text.data(), text.data() + text.max_size(), STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size(), text.size()); } @@ -5659,9 +5638,7 @@ namespace std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); text.trim_to_terminator(); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_FALSE(text.is_truncated()); CHECK_EQUAL(text.max_size() - 1, text.size()); } @@ -5676,7 +5653,9 @@ namespace text.trim_to_terminator(); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK_TRUE(text.is_truncated()); +#else + CHECK_FALSE(text.is_truncated()); #endif CHECK_EQUAL(text.max_size(), text.size()); } From f85bac450c97170abd6ca929e834ab59e7399b77 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 09:50:09 +0100 Subject: [PATCH 119/216] Added etl::tuple --- include/etl/private/tuple_element.h | 54 ++ include/etl/private/tuple_size.h | 53 ++ include/etl/tuple.h | 1242 +++++++++++++++++++++++++++ test/test_tuple.cpp | 591 +++++++++++++ 4 files changed, 1940 insertions(+) create mode 100644 include/etl/private/tuple_element.h create mode 100644 include/etl/private/tuple_size.h create mode 100644 include/etl/tuple.h create mode 100644 test/test_tuple.cpp diff --git a/include/etl/private/tuple_element.h b/include/etl/private/tuple_element.h new file mode 100644 index 000000000..ca6231a36 --- /dev/null +++ b/include/etl/private/tuple_element.h @@ -0,0 +1,54 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_TUPLE_ELEMENT_INCLUDED +#define ETL_TUPLE_ELEMENT_INCLUDED + +namespace etl +{ +#if ETL_USING_CPP11 + //*************************************************************************** + template + struct tuple_element; + + //*************************************************************************** + template + struct tuple_element + { + using type = typename etl::add_const_t::type>; + }; + + //*************************************************************************** + template + using tuple_element_t = typename tuple_element::type; +#endif +} + +#endif diff --git a/include/etl/private/tuple_size.h b/include/etl/private/tuple_size.h new file mode 100644 index 000000000..640677498 --- /dev/null +++ b/include/etl/private/tuple_size.h @@ -0,0 +1,53 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_TUPLE_SIZE_INCLUDED +#define ETL_TUPLE_SIZE_INCLUDED + +namespace etl +{ + //*************************************************************************** + template + struct tuple_size; + + //*************************************************************************** + template + struct tuple_size : etl::integral_constant::value> + { + }; + + //*************************************************************************** +#if ETL_USING_CPP17 + template + inline constexpr size_t tuple_size_v = tuple_size::value; +#endif +} + +#endif diff --git a/include/etl/tuple.h b/include/etl/tuple.h new file mode 100644 index 000000000..32b8686c2 --- /dev/null +++ b/include/etl/tuple.h @@ -0,0 +1,1242 @@ +#pragma once + +#if ETL_USING_STL + #include +#endif + +#include "etl/nth_type.h" +#include "etl/type_traits.h" +#include "etl/utility.h" +#include "etl/functional.h" + +#include "etl/private/tuple_element.h" +#include "etl/private/tuple_size.h" + +namespace etl +{ + //*************************************************************************** + /// A tuple type + /// etl::tuple + //*************************************************************************** + template + class tuple; + + //*************************************************************************** + /// Type trait to check if a type is an etl::tuple + /// Default implementation. + //*************************************************************************** + template + struct is_tuple : etl::false_type + { + }; + + //*************************************************************************** + /// Type trait to check if a type is an etl::tuple + /// Specialisation for etl::tuple + //*************************************************************************** + template + struct is_tuple> : etl::true_type + { + }; + + namespace private_tuple + { + //*************************************************************************** + /// Get the base of a tuple type whose head type is T. + //*************************************************************************** + template + struct tuple_type_base; + + // Specialisation for an empty tuple + template + struct tuple_type_base> + { + using type = void; + }; + + // Recursive definition of the type. + template + struct tuple_type_base> + { + using type = etl::conditional_t::value, + tuple, + typename tuple_type_base>::type>; + }; + + // Get the base of a tuple type whose head type is T. + template + using tuple_type_base_t = typename tuple_type_base::type; + + //*************************************************************************** + /// ignore + /// An object of unspecified type such that any value can be assigned to it with no effect. + /// Intended for use with etl::tie when unpacking a etl::tuple, as a placeholder for the arguments that are not used. + /// https://en.cppreference.com/w/cpp/utility/tuple/ignore + //*************************************************************************** + struct ignore_t + { + template + ETL_CONSTEXPR void operator =(T&&) const ETL_NOEXCEPT + { + } + }; + } + + //*************************************************************************** + /// Empty tuple + //*************************************************************************** + template<> + class tuple<> + { + public: + + using value_type = void; ///< The type contained by this tuple. + using this_type = tuple<>; ///< The type of this tuple. + using base_type = void; ///< The type of the base tuple. + using index_sequence_type = etl::make_index_sequence<0>; ///< The index_sequence type for this tuple. + + //********************************* + // No-op copy_assignment for the base case + //********************************* + ETL_CONSTEXPR14 + void copy_assignment(const this_type& /*other*/) + { + } + + //********************************* + // No-op forward_assignment for the base case + //********************************* + ETL_CONSTEXPR14 + void forward_assignment(this_type&& /*other*/) + { + } + + //********************************* + // No-op swap for the base case + //********************************* + ETL_CONSTEXPR14 + void swap(this_type& /*other*/) + { + } + + //********************************* + // Returns the size of the base case. + // Always zero. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR + static size_t size() + { + return 0U; + } + }; + + //*************************************************************************** + /// Tuple + //*************************************************************************** + template + class tuple : public tuple + { + private: + + //********************************* + /// Helper function to calculate the number + /// of types from a type list. + //********************************* + template + static constexpr size_t number_of_types() + { + return sizeof...(UTypes); + } + + public: + + //********************************* + /// Friends + //********************************* + template + friend class tuple; + + template + ETL_CONSTEXPR14 + friend auto& get(tuple&); + + template + ETL_CONSTEXPR14 + friend auto&& get(tuple&&); + + template + ETL_CONSTEXPR14 + friend const auto& get(const tuple&); + + template + ETL_CONSTEXPR14 + friend const auto&& get(const tuple&&); + + template + ETL_CONSTEXPR14 + friend auto& get(tuple&); + + template + ETL_CONSTEXPR14 + friend auto&& get(tuple&&); + + template + ETL_CONSTEXPR14 + friend const auto& get(const tuple&); + + template + ETL_CONSTEXPR14 + friend const auto&& get(const tuple&&); + + //********************************* + /// Types + //********************************* + using value_type = THead; ///< The type contained by this tuple. + using this_type = tuple; ///< The type of this tuple. + using base_type = tuple; ///< The type of the base tuple. + using index_sequence_type = etl::make_index_sequence()>; ///< The index_sequence type for this tuple. + + //********************************* + /// Default constructor. + //********************************* + ETL_CONSTEXPR14 + tuple() + : value(THead()) + { + } + + //********************************* + /// Copy constructor. + //********************************* + ETL_CONSTEXPR14 + tuple(const tuple& other) = default; + + //********************************* + /// Move constructor. + //********************************* + ETL_CONSTEXPR14 + tuple(tuple&& other) = default; + + //********************************* + /// Copy assignment. + //********************************* + ETL_CONSTEXPR14 + tuple& operator =(const tuple& other) = default; + + //********************************* + /// Move assignment. + //********************************* + ETL_CONSTEXPR14 + tuple& operator =(tuple&& other) = default; + + //********************************* + /// Copy construct from lvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from lvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from const lvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Copy construct from const lvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const tuple& other) + : base_type(other.get_base()) + , value(other.get_value()) + { + } + + //********************************* + /// Move construct from rvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Move construct from rvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from const rvalue reference tuple type. + /// Implicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from const rvalue reference tuple type. + /// Explicit conversion + //********************************* + template () == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const tuple&& other) + : base_type(etl::forward>(other.get_base())) + , value(etl::forward(other.get_value())) + { + } + + //********************************* + /// Construct from arguments. + //********************************* + ETL_CONSTEXPR14 + tuple(const THead& head, const TTail&... tail) + : base_type(tail...) + , value(head) + { + } + + //********************************* + /// Construct from arguments. + /// Implicit conversion. + //********************************* + template >::value && + (number_of_types() == number_of_types()) && + (number_of_types() >= 1U) && + etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT + : base_type(etl::forward(tail)...) + , value(etl::forward(head)) + { + } + + //********************************* + /// Construct from arguments. + /// explicit conversion. + //********************************* + template >::value && + (number_of_types() == number_of_types()) && + (number_of_types() >= 1U) && + !etl::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + explicit tuple(UHead&& head, UTail&&... tail) ETL_NOEXCEPT + : base_type(etl::forward(tail)...) + , value(etl::forward(head)) + { + } + + //********************************* + /// Construct from lvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from lvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from const lvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from const lvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const ETL_OR_STD::pair& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Construct from rvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from rvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from const rvalue reference pair. + /// Implicit conversion. + //********************************* + template () == 2U && + etl ::is_convertible::value && + etl ::is_convertible::value, int> = 0> + ETL_CONSTEXPR14 + tuple(const ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(etl::forward(p.second)) + , value(etl::forward(p.first)) + { + } + + //********************************* + /// Construct from const rvalue reference pair. + /// Explicit conversion. + //********************************* + template () == 2U && + (!etl ::is_convertible::value || + !etl ::is_convertible::value), int> = 0> + ETL_CONSTEXPR14 + explicit tuple(const ETL_OR_STD::pair&& p) ETL_NOEXCEPT + : base_type(p.second) + , value(p.first) + { + } + + //********************************* + /// Copy assign from other tuple type. + //********************************* + template () == number_of_types()), int> = 0> + ETL_CONSTEXPR14 + tuple& operator =(const tuple& other) + { + copy_assignment(other); + + return *this; + } + + //********************************* + /// Move assign from other tuple type. + //********************************* + template () == number_of_types()), int> = 0> + ETL_CONSTEXPR14 + tuple& operator =(tuple&& other) + { + forward_assignment(etl::forward>(other)); + + return *this; + } + + //********************************* + /// Assign from lvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(pair& p) + { + get_value() = p.first; + get_base().get_value() = p.second; + + return *this; + } + + //********************************* + /// Assign from const lvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(const pair& p) + { + get_value() = p.first; + get_base().get_value() = p.second; + + return *this; + } + + //********************************* + /// Assign from rvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(pair&& p) + { + get_value() = etl::forward(p.first); + get_base().get_value() = etl::forward(p.second); + + return *this; + } + + //********************************* + /// Assign from const rvalue pair tuple type. + //********************************* + template , etl::enable_if_t = 0> + ETL_CONSTEXPR14 + tuple& operator =(const pair&& p) + { + get_value() = etl::forward(p.first); + get_base().get_value() = etl::forward(p.second); + + return *this; + } + + //********************************* + /// Swaps this tuple with another. + //********************************* + ETL_CONSTEXPR14 + void swap(this_type& other) + { + using ETL_OR_STD::swap; + + // Swap the head + swap(get_value(), other.get_value()); + + auto& this_base = get_base(); + auto& other_base = other.get_base(); + + // Recursively swap the tail by calling the base class's swap implementation. + this_base.swap(other_base); + } + + //********************************* + /// Returns the number of elements in the tuple. + //********************************* + ETL_NODISCARD + constexpr + static size_t size() + { + return number_of_types(); + } + + protected: + + //********************************* + /// Returns a reference to the head value. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + THead& get_value() + { + return value; + } + + //********************************* + /// Returns a const reference to the head value. + //********************************* + ETL_CONSTEXPR + const THead& get_value() const + { + return value; + } + + //********************************* + /// Get a reference to the base class. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + base_type& get_base() + { + return static_cast(*this); + } + + //********************************* + /// Get a const reference to the base class. + //********************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const base_type& get_base() const + { + return static_cast(*this); + } + + //********************************* + /// Handles copy assignment from another tuple. + //********************************* + template + ETL_CONSTEXPR14 + void copy_assignment(const tuple& other) + { + // Assign the head + this->value = other.get_value(); + + // Get the base classes + auto& this_base = get_base(); + const auto& other_base = other.get_base(); + + // Recursively assign the tail by calling the base class's assignment implementation + this_base.copy_assignment(other_base); + } + + //********************************* + /// Handles move assignment from another tuple. + //********************************* + template + ETL_CONSTEXPR14 + void forward_assignment(tuple&& other) + { + // Assign the head + this->value = etl::forward(other.get_value()); + + auto& this_base = get_base(); + auto&& other_base = other.get_base(); + + // Recursively assign the tail by calling the base class's move assignment implementation + this_base.forward_assignment(etl::forward>(other_base)); + } + + private: + + THead value; + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Template deduction guideline from variadic arguments. + //*************************************************************************** + template + tuple(TArgs... args) -> tuple; + + //*************************************************************************** + /// Template deduction guideline from pair. + //*************************************************************************** + template + tuple(ETL_OR_STD::pair) -> tuple; +#endif + + //*************************************************************************** + /// Gets the element type at the index in the tuple. + //*************************************************************************** + template + struct tuple_element> + { + using type = etl::nth_type_t; + }; + + //*************************************************************************** + /// Gets the size of the tuple. + //*************************************************************************** + template + struct tuple_size> + : etl::integral_constant + { + }; + + //*************************************************************************** + /// Gets the common type of a tuple. + //*************************************************************************** + template + struct common_type> + { + using type = etl::common_type_t; + }; + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in sizeof...(TTypes)). + /// Returns a reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto& get(tuple& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = etl::nth_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns a const reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const auto& get(const tuple& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = const etl::nth_base_t>&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns an rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto&& get(tuple&& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = etl::nth_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element at Index from the tuple. + /// Index must be an integer value in [?0?, sizeof...(TTypes)). + /// Returns a const rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const auto&& get(const tuple&& t) + { + ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); + + // Get the type at this index. + using tuple_type = const etl::nth_base_t>&&; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto& get(tuple& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a const reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const auto& get(const tuple& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns an rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto&& get(tuple&& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + + //*************************************************************************** + /// Extracts the element with type T from the tuple. + /// Static asserts if the tuple contain more than one T, or does not contain a T element. + /// Returns a const rvalue reference. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + const auto&& get(const tuple&& t) + { + ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + + // Get the tuple base type that contains a T + using tuple_type = etl::private_tuple::tuple_type_base_t>; + + // Cast the tuple to the selected type and get the value. + return static_cast(t).get_value(); + } + +#if ETL_USING_CPP17 + inline constexpr private_tuple::ignore_t ignore; +#else + static constexpr private_tuple::ignore_t ignore; +#endif + + //*************************************************************************** + /// Creates a tuple of references to the provided arguments. + //*************************************************************************** + template + ETL_CONSTEXPR etl::tuple tie(TTypes&... args) + { + return { args... }; + } + + //*************************************************************************** + // Creates a tuple from the provided arguments. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple...> make_tuple(TTypes&&... args) + { + return etl::tuple...>(etl::forward(args)...); + } + + //*************************************************************************** + /// Creates a new tuple by selecting elements from another, given a run time index sequence. + /// Static asserts if the number of indices does not match the tuple size. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto select_from_tuple(TTuple&& tuple, etl::index_sequence) + { + ETL_STATIC_ASSERT(sizeof...(Indices) <= etl::tuple_size>::value, "Number of indices is greater than the tuple size"); + + return etl::make_tuple(etl::forward>>(etl::get(etl::forward(tuple)))...); + } + + //*************************************************************************** + /// Creates a new tuple by selecting elements from another, given a template parameter index sequence. + /// Static asserts if the number of indices does not match the tuple size. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto select_from_tuple(TTuple&& tuple) + { + return select_from_tuple(etl::forward(tuple), etl::index_sequence{}); + } + + //*************************************************************************** + /// Forwards the arguments as a tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + etl::tuple forward_as_tuple(TTypes&&... args) + { + return tuple(etl::forward(args)...); + } + + namespace private_tuple + { + //********************************** + // Helper to concatenate two tuples + //********************************** + template + ETL_CONSTEXPR14 + auto tuple_cat_impl(Tuple1&& t1, etl::index_sequence, Tuple2&& t2, etl::index_sequence) + { + return etl::tuple>..., + etl::tuple_element_t>...> + (etl::get(etl::forward(t1))..., etl::get(etl::forward(t2))...); + } + } + + //*************************************************************************** + /// Base case for concatenating one tuple + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto tuple_cat(Tuple&& t) + { + return etl::forward(t); + } + + //*************************************************************************** + /// Recursive case for concatenating multiple tuples + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto tuple_cat(Tuple1&& t1, Tuple2&& t2, Tuples&&... ts) + { + auto concatenated = private_tuple::tuple_cat_impl(etl::forward(t1), + etl::make_index_sequence>::value>{}, + etl::forward(t2), + etl::make_index_sequence>::value>{}); + + return tuple_cat(etl::move(concatenated), etl::forward(ts)...); + } + +#if ETL_USING_STL + //*************************************************************************** + // Tuple conversion functions. + // From ETL to STL + //*************************************************************************** + namespace private_tuple + { + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std_impl(const TEtl_Tuple& etl_tuple, etl::index_sequence) + { + return std::tuple::type...>(etl::get(etl_tuple)...); + } + + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std_impl(TEtl_Tuple&& etl_tuple, etl::index_sequence) + { + return std::tuple::type...>(etl::move(etl::get(etl_tuple))...); + } + } + + //*************************************************************************** + /// Converts an etl::tuple to a std::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std(const etl::tuple& etl_tuple) + { + return private_tuple::to_std_impl(etl_tuple, etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Converts an etl::tuple to a std::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_std(etl::tuple&& etl_tuple) + { + return private_tuple::to_std_impl(etl::move(etl_tuple), etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Tuple conversion functions. + /// From STL to ETL + //*************************************************************************** + namespace private_tuple + { + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl_impl(const TStd_Tuple& std_tuple, etl::index_sequence) + { + return etl::tuple::type...>(std::get(std_tuple)...); + } + + ///********************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl_impl(TStd_Tuple&& std_tuple, etl::index_sequence) + { + return etl::tuple::type...>(std::move(std::get(std_tuple))...); + } + } + + //*************************************************************************** + /// Converts a std::tuple to an etl::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl(const std::tuple& std_tuple) + { + return private_tuple::to_etl_impl(std_tuple, etl::make_index_sequence_for()); + } + + //*************************************************************************** + /// Converts a std::tuple to an etl::tuple. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + auto to_etl(std::tuple&& std_tuple) + { + return private_tuple::to_etl_impl(etl::move(std_tuple), etl::make_index_sequence_for()); + } +#endif + + namespace private_tuple + { + //*************************************************************************** + /// Equality + //*************************************************************************** + // When there are no indices left to compare. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_equality(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) + { + return true; + } + + // Recursive case: compare the current element and recurse. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_equality(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence) + { + return etl::get(lhs) == etl::get(rhs) && tuple_equality(lhs, rhs, etl::index_sequence{}); + } + + //*************************************************************************** + /// Less than + //*************************************************************************** + // When there are no indices left to compare. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_less_than(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) + { + return false; + } + + // Recursively compare the current element and the rest. + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool tuple_less_than(const TTuple1& lhs, const TTuple2& rhs, etl::index_sequence) + { + if (get(lhs) < get(rhs)) + { + return true; + } + + if (get(rhs) < get(lhs)) + { + return false; + } + + return tuple_less_than(lhs, rhs, etl::index_sequence{}); + } + } + + //*************************************************************************** + /// Equality operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator ==(const etl::tuple& lhs, + const etl::tuple& rhs) + { + ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes"); + + // Compare each element of the tuples. + return private_tuple::tuple_equality(lhs, rhs, etl::make_index_sequence::size()>{}); + } + + //*************************************************************************** + /// Inequality operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator !=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(lhs == rhs); + } + + //*************************************************************************** + /// Less than operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator <(const etl::tuple& lhs, + const etl::tuple& rhs) + { + ETL_STATIC_ASSERT(sizeof...(TTypes) == sizeof...(UTypes), "Cannot compare tuples of different sizes"); + + // Compare the elements. + return private_tuple::tuple_less_than(lhs, rhs, etl::make_index_sequence::size()>{}); + } + + //*************************************************************************** + /// Less than or equals operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator <=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(rhs < lhs); + } + + //*************************************************************************** + /// Greater than operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator >(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return (rhs < lhs); + } + + //*************************************************************************** + /// Greater than or equals operator. + //*************************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR14 + bool operator >=(const etl::tuple& lhs, + const etl::tuple& rhs) + { + return !(lhs < rhs); + } + + //*************************************************************************** + /// Swap two tuples. + //*************************************************************************** + template + ETL_CONSTEXPR14 + void swap(etl::tuple& lhs, etl::tuple& rhs) + { + lhs.swap(rhs); + } +} + +namespace std +{ + //*************************************************************************** + /// Specialisation of tuple_size to allow the use of C++ structured bindings. + //*************************************************************************** + template + struct tuple_size> : etl::integral_constant + { + }; + + //*************************************************************************** + /// Specialisation of tuple_element to allow the use of C++ structured bindings. + //*************************************************************************** + template + struct tuple_element> + { + using type = typename etl::nth_type_t; + }; +} diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp new file mode 100644 index 000000000..ed3ff2cdc --- /dev/null +++ b/test/test_tuple.cpp @@ -0,0 +1,591 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 John Wellbelove + +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 "unit_test_framework.h" + +#include "Data.h" + +#include "etl/tuple.h" +#include "etl/private/tuple_size.h" + +#include +#include +#include + +namespace +{ + using Data = TestDataDC; + using DataM = TestDataM; + + template + auto to_array(etl::index_sequence) + { + return std::array{Indices...}; + } + + SUITE(test_tuple) + { + //************************************************************************* + TEST(test_tuple_size) + { + using Tuple = etl::tuple; + + Tuple tp; + + CHECK_EQUAL(4U, etl::tuple_size::value); + CHECK_EQUAL(4U, tp.size()); + +#if (ETL_USING_CPP17) + CHECK_EQUAL(4U, etl::tuple_size_v); +#endif + } + + //************************************************************************* + TEST(test_tuple_element) + { + using Tuple = etl::tuple; + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + + //************************************************************************* + TEST(test_default_constructor) + { + etl::tuple tp; + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(0, i0); + CHECK_EQUAL(0, d1); + CHECK_EQUAL(0, i2); + CHECK_TRUE(s3.empty()); + } + + //************************************************************************* + TEST(test_constructor_single_element) + { + etl::tuple tp(1); + + CHECK_EQUAL(1, etl::get<0>(tp)); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + etl::tuple tp; + etl::tuple otherTuple(tp); + } + + //************************************************************************* + TEST(test_copy_constructor_single_element) + { + etl::tuple tp(1); + etl::tuple otherTuple(tp); + } + + //************************************************************************* + TEST(test_copy_assignment) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + etl::tuple otherTuple(5, 6.6, 7, Data("8")); + + otherTuple = tp; + + CHECK_EQUAL(etl::get<0>(tp), etl::get<0>(otherTuple)); + CHECK_EQUAL(etl::get<1>(tp), etl::get<1>(otherTuple)); + CHECK_EQUAL(etl::get<2>(tp), etl::get<2>(otherTuple)); + CHECK_EQUAL(etl::get<3>(tp), etl::get<3>(otherTuple)); + } + + //************************************************************************* + TEST(test_move_assignment) + { + etl::tuple tp(1, 2.2, 3, DataM("4")); + etl::tuple otherTuple(5, 6.6, 7, DataM("8")); + + otherTuple = std::move(tp); + + CHECK_EQUAL(etl::get<0>(otherTuple), 1); + CHECK_EQUAL(etl::get<1>(otherTuple), 2.2); + CHECK_EQUAL(etl::get<2>(otherTuple), 3); + CHECK_EQUAL(etl::get<3>(otherTuple), DataM("4")); + } + + //************************************************************************* + TEST(test_construct_from_parameters) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + + //************************************************************************* + TEST(test_construct_from_convertible_types) + { + etl::tuple tp(char(1), float(2.2), short(3)); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + } + + //************************************************************************* + TEST(test_construct_from_parameters_including_move_only) + { + etl::tuple tp(1, 2.2, 3, etl::move(DataM("4"))); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_parameters_using_template_deduction_guideline) + { + etl::tuple tp(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp); + double d1 = etl::get<1>(tp); + int i2 = etl::get<2>(tp); + std::string& s3 = etl::get<3>(tp).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } +#endif + + //************************************************************************* + TEST(test_make_tuple) + { + auto tp1 = etl::make_tuple(1, 2.2, 3, Data("4")); + + int i0 = etl::get<0>(tp1); + double d1 = etl::get<1>(tp1); + int i2 = etl::get<2>(tp1); + std::string& s3 = etl::get<3>(tp1).value; + + CHECK_EQUAL(1, i0); + CHECK_CLOSE(2.2, d1, 0.01); + CHECK_EQUAL(3, i2); + CHECK_EQUAL(std::string("4"), s3); + } + + //************************************************************************* + TEST(test_swap) + { + etl::tuple tp1(1, 2); + etl::tuple tp2(3, 4); + + swap(tp1, tp2); + + CHECK_EQUAL(3, etl::get<0>(tp1)); + CHECK_EQUAL(4, etl::get<1>(tp1)); + + CHECK_EQUAL(1, etl::get<0>(tp2)); + CHECK_EQUAL(2, etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_get) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data d0 = etl::get<0>(data); + Data d1 = etl::get<0>(const_data); + DataM d2 = etl::move(etl::get<1>(data)); + DataM d3 = etl::move(etl::get<1>(const_data)); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_construct_from_pair) + { + ETL_OR_STD::pair p(1, Data("2")); + + etl::tuple tp(p); + + int i = etl::get<0>(tp); + Data d = etl::get<1>(tp); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + TEST(test_construct_from_const_pair) + { + const ETL_OR_STD::pair p(1, Data("2")); + + etl::tuple tp(p); + + int i = etl::get<0>(tp); + Data d = etl::get<1>(tp); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + TEST(test_construct_from_move_only_pair) + { + ETL_OR_STD::pair p(1, etl::move(DataM("2"))); + + etl::tuple tp(etl::move(p)); + + int i = etl::get<0>(tp); + DataM d = etl::move(etl::get<1>(tp)); + + CHECK_EQUAL(1, i); + CHECK_EQUAL(std::string("2"), d.value); + } + + //************************************************************************* + ETL_NODISCARD bool Get() + { + return true; + } + + TEST(test_ignore_t) + { + // Should compile without error. + etl::ignore = Get(); + } + + //************************************************************************* + TEST(test_tie) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + int i1; + double d; + int i2; + Data data; + + etl::tie(i1, d, i2, data) = tp; + + CHECK_EQUAL(etl::get<0>(tp), i1); + CHECK_CLOSE(etl::get<1>(tp), d, 0.01); + CHECK_EQUAL(etl::get<2>(tp), i2); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_moved_tie) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + int i1; + double d; + int i2; + Data data; + + etl::tie(i1, d, i2, data) = etl::move(tp); + + CHECK_EQUAL(etl::get<0>(tp), i1); + CHECK_CLOSE(etl::get<1>(tp), d, 0.01); + CHECK_EQUAL(etl::get<2>(tp), i2); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_tie_from_convertible_types) + { + etl::tuple tp{1, 2.3, 4, Data("Data", 5)}; + + char c; + long double ld; + short s; + Data data; + + etl::tie(c, ld, s, data) = tp; + + CHECK_EQUAL(etl::get<0>(tp), c); + CHECK_CLOSE(etl::get<1>(tp), ld, 0.01); + CHECK_EQUAL(etl::get<2>(tp), s); + CHECK_EQUAL(etl::get<3>(tp), data); + } + + //************************************************************************* + TEST(test_tuple_cat) + { + etl::tuple tp1{1, 2.3}; + etl::tuple tp2{4, Data("Data", 5)}; + + auto tp3 = etl::tuple_cat(tp1, tp2); + + CHECK_EQUAL(etl::get<0>(tp3), etl::get<0>(tp1)); + CHECK_EQUAL(etl::get<1>(tp3), etl::get<1>(tp1)); + CHECK_EQUAL(etl::get<2>(tp3), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<3>(tp3), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_forward_as_tuple) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + + auto tp = etl::forward_as_tuple(v1, v2, v3); + + CHECK_EQUAL(v1, etl::get<0>(tp)); + CHECK_EQUAL(v2, etl::get<1>(tp)); + CHECK_EQUAL(v3, etl::get<2>(tp)); + } + + ////************************************************************************* + // Uncomment to test. + // TEST(test_static_assert) + //{ + // etl::tuple tp; + + // auto result = etl::get<4>(tp); + //} + + //************************************************************************* + TEST(test_select_tuple_run_time) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + + using Sequence = etl::index_sequence<3, 2, 1, 0>; + Tuple2 tp2 = etl::select_from_tuple(tp1, Sequence()); + + CHECK_EQUAL(etl::get<0>(tp1), etl::get<3>(tp2)); + CHECK_EQUAL(etl::get<1>(tp1), etl::get<2>(tp2)); + CHECK_EQUAL(etl::get<2>(tp1), etl::get<1>(tp2)); + CHECK_EQUAL(etl::get<3>(tp1), etl::get<0>(tp2)); + } + + //************************************************************************* + TEST(test_select_a_subset_of_a_tuple_using_a_run_time_index_sequence) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + + using Sequence = etl::index_sequence<1, 0>; + Tuple2 tp2 = etl::select_from_tuple(tp1, Sequence()); + + CHECK_EQUAL(etl::get<1>(tp1), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<0>(tp1), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_select_a_subset_of_a_tuple_using_a_compile_time_index_sequence) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, Data("Data", 5)}; + Tuple2 tp2 = etl::select_from_tuple<1, 0>(tp1); + + CHECK_EQUAL(etl::get<1>(tp1), etl::get<0>(tp2)); + CHECK_EQUAL(etl::get<0>(tp1), etl::get<1>(tp2)); + } + + //************************************************************************* + TEST(test_move_select_tuple) + { + using Tuple1 = etl::tuple; + using Tuple2 = etl::tuple; + + Tuple1 tp1{1, 2.3, 4, DataM("DataM")}; + + using Sequence = etl::index_sequence<3, 2, 1, 0>; + Tuple2 tp2 = etl::select_from_tuple(etl::move(tp1), Sequence()); + + CHECK_EQUAL(etl::get<0>(tp1), etl::get<3>(tp2)); + CHECK_EQUAL(etl::get<1>(tp1), etl::get<2>(tp2)); + CHECK_EQUAL(etl::get<2>(tp1), etl::get<1>(tp2)); + CHECK_EQUAL(std::string("DataM"), etl::get<0>(tp2).value); + CHECK_EQUAL(true, etl::get<0>(tp2).valid); + + // Check that the data was moved. + CHECK_EQUAL(std::string(""), etl::get<3>(tp1).value); + CHECK_EQUAL(false, etl::get<3>(tp1).valid); + } + + //************************************************************************* + TEST(test_index_sequence_type) + { + using Tuple = etl::tuple; + + auto actual = to_array(Tuple::index_sequence_type{}); + decltype(actual) expected{0, 1, 2, 3}; + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), expected.size()); + } + + //************************************************************************* + TEST(test_comparison_operators) + { + etl::tuple tp1(1, 2); + etl::tuple tp2(1, 2); + etl::tuple tp3(3, 4); + etl::tuple tp4(4, 3); + + CHECK_TRUE(tp1 == tp2); + CHECK_FALSE(tp1 == tp3); + + CHECK_FALSE(tp1 != tp2); + CHECK_TRUE(tp1 != tp3); + + CHECK_TRUE(tp1 < tp3); + CHECK_FALSE(tp3 < tp1); + CHECK_TRUE(tp3 < tp4); + CHECK_FALSE(tp4 < tp3); + + CHECK_TRUE(tp1 <= tp2); + CHECK_TRUE(tp1 <= tp3); + CHECK_FALSE(tp3 <= tp1); + CHECK_TRUE(tp3 <= tp4); + CHECK_FALSE(tp4 <= tp3); + + CHECK_FALSE(tp1 > tp3); + CHECK_TRUE(tp3 > tp1); + CHECK_FALSE(tp3 > tp4); + CHECK_TRUE(tp4 > tp3); + + CHECK_TRUE(tp1 >= tp2); + CHECK_FALSE(tp1 >= tp3); + CHECK_TRUE(tp3 >= tp1); + CHECK_FALSE(tp3 >= tp4); + CHECK_TRUE(tp4 >= tp3); + } + +#if ETL_USING_STL + //************************************************************************* + TEST(test_to_etl) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + std::string v4 = ""; + + std::tuple tp_std(v1, v2, v3); + + auto tp_etl = etl::to_etl(tp_std); + auto tp_etl_moved = etl::to_etl(etl::move(tp_std)); + + CHECK_EQUAL(v1, etl::get<0>(tp_etl)); + CHECK_EQUAL(v2, etl::get<1>(tp_etl)); + CHECK_EQUAL(v3, etl::get<2>(tp_etl)); + + CHECK_EQUAL(v1, etl::get<0>(tp_etl_moved)); + CHECK_EQUAL(v2, etl::get<1>(tp_etl_moved)); + CHECK_EQUAL(v3, etl::get<2>(tp_etl_moved)); + + CHECK_EQUAL(v4, std::get<2>(tp_std)); + } + + //************************************************************************* + TEST(test_to_std) + { + char v1 = 1; + int v2 = 2; + std::string v3 = "Hello"; + std::string v4 = ""; + + etl::tuple tp_etl(v1, v2, v3); + + auto tp_std = etl::to_std(tp_etl); + auto tp_std_moved = etl::to_std(etl::move(tp_etl)); + + CHECK_EQUAL(v1, std::get<0>(tp_std)); + CHECK_EQUAL(v2, std::get<1>(tp_std)); + CHECK_EQUAL(v3, std::get<2>(tp_std)); + + CHECK_EQUAL(v1, std::get<0>(tp_std_moved)); + CHECK_EQUAL(v2, std::get<1>(tp_std_moved)); + CHECK_EQUAL(v3, std::get<2>(tp_std_moved)); + + CHECK_EQUAL(v4, etl::get<2>(tp_etl)); + } +#endif + + //************************************************************************* + TEST(test_common_type) + { + using Tuple = etl::tuple; + using Type = etl::common_type::type; + + CHECK_TRUE((std::is_same::value)); + } + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_structured_bindings) + { + etl::tuple tp(1, 2, "Hello"); + + const auto &[c, i, s] = tp; + + CHECK_EQUAL(etl::get<0>(tp), c); + CHECK_EQUAL(etl::get<1>(tp), i); + CHECK_EQUAL(etl::get<2>(tp), s); + } +#endif + } +} From 2fd887ecc34e1e19f84dd23f0cbfbacf1345408b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 09:50:49 +0100 Subject: [PATCH 120/216] C++03 compatibility for etl::typed_storage --- include/etl/alignment.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/etl/alignment.h b/include/etl/alignment.h index 7ee760429..5c7e5ac85 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -350,7 +350,7 @@ namespace etl #endif //*************************************************************************** - /// Wrapper class that provides a memory area and lets the user emplace and + /// Wrapper class that provides a memory area and lets the user create and /// instance of T in this memory at runtime. This class also erases the /// destructor call of T, i.e. if typed_storage goes out of scope, the /// destructor if the wrapped type will not be called. This can be done @@ -362,11 +362,11 @@ namespace etl { public: - using value_type = T; - using reference = T&; - using const_reference = T const&; - using pointer = T*; - using const_pointer = T const*; + typedef T value_type; + typedef T& reference; + typedef const T& const_reference; + typedef T* pointer; + typedef const T* const_pointer; // Constructor typed_storage() @@ -376,7 +376,7 @@ namespace etl //*************************************************************************** /// Default destructor which will NOT call the destructor of the object which - /// was created by calling emplace(). + /// was created by calling create(). //*************************************************************************** ~typed_storage() = default; @@ -391,8 +391,8 @@ namespace etl } //*************************************************************************** - /// \returns true if object has been constructed using emplace(). - /// \returns false otherwise. + /// \returns true if object has been constructed using create(). + /// \returns false otherwise. //*************************************************************************** bool has_value() const { From d9af24f34b8c46448ebd6321c7078d623feea6ce Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 09:51:28 +0100 Subject: [PATCH 121/216] Sopporting changes for etl::tuple --- include/etl/functional.h | 35 ++++++++++++++++++++++++ include/etl/nth_type.h | 59 +++++++++++++++++----------------------- include/etl/utility.h | 46 +++++++++++++++++++++++++++---- test/data.h | 11 ++++++-- 4 files changed, 110 insertions(+), 41 deletions(-) diff --git a/include/etl/functional.h b/include/etl/functional.h index d762506c1..d1ce6d048 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -112,6 +112,39 @@ namespace etl return reference_wrapper(t.get()); } + //*************************************************************************** + /// unwrap_reference. + //*************************************************************************** + template + struct unwrap_reference + { + typedef T type; + }; + + template + struct unwrap_reference > + { + typedef U& type; + }; + +#if ETL_USING_CPP11 + template + using unwrap_reference_t = typename unwrap_reference::type; +#endif + + //*************************************************************************** + /// unwrap_ref_decay. + //*************************************************************************** + template + struct unwrap_ref_decay : etl::unwrap_reference::type> {}; + +#if ETL_USING_CPP11 + template + using unwrap_ref_decay_t = typename unwrap_ref_decay::type; +#endif + + //*************************************************************************** + /// unary_function //*************************************************************************** template struct unary_function @@ -120,6 +153,8 @@ namespace etl typedef TResultType result_type; }; + //*************************************************************************** + /// binary_function //*************************************************************************** template struct binary_function diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index ac8091669..7617dc685 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -32,50 +32,41 @@ SOFTWARE. #include "platform.h" #include "static_assert.h" +#if ETL_NOT_USING_CPP11 + #if !defined(ETL_IN_UNIT_TEST) + #error NOT SUPPORTED FOR C++03 OR BELOW + #endif +#else namespace etl { -#if ETL_USING_CPP11 - - //*************************************************************************** - /// Finds the nth type in a variadic type parameter. - //*************************************************************************** - template - struct nth_type; - - //*************************************************************************** - /// Finds the nth type in a variadic type parameter. - //*************************************************************************** - template - struct nth_type + namespace private_nth_type { - ETL_STATIC_ASSERT(N <= sizeof...(TRest), "etl::nth_type out of range for type list"); + //*********************************** + template + struct nth_type_helper + { + using type = typename nth_type_helper::type; + }; - using type = typename nth_type::type; - }; + template + struct nth_type_helper<0U, T1, TRest...> + { + using type = T1; + }; + } - //*************************************************************************** - /// Finds the 0thth type in a variadic type parameter. - //*************************************************************************** - template - struct nth_type<0U, T1, TRest...> + //*********************************** + template + struct nth_type { - using type = T1; - }; + ETL_STATIC_ASSERT(N < sizeof...(TTypes), "etl::nth_type index 'N' out of bounds"); - //*************************************************************************** - /// Handles a zero length type list. - //*************************************************************************** - template - struct nth_type - { + using type = typename private_nth_type::nth_type_helper::type; }; - //*************************************************************************** - /// Finds the nth type in a variadic type parameter. - //*************************************************************************** + //*********************************** template using nth_type_t = typename nth_type::type; -#endif } - +#endif #endif diff --git a/include/etl/utility.h b/include/etl/utility.h index 8ea7a4751..15b450e8b 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -34,6 +34,9 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" +#include "private/tuple_element.h" +#include "private/tuple_size.h" + #if defined(ETL_IN_UNIT_TEST) || ETL_USING_STL #if ETL_USING_CPP11 #include @@ -325,6 +328,33 @@ namespace etl } #endif +#if ETL_USING_CPP11 + //****************************************************************************** + template + struct tuple_element > + { + ETL_STATIC_ASSERT(Index < 2U, "pair has only 2 elements"); + }; + + template + struct tuple_element<0U, ETL_OR_STD::pair > + { + typedef T1 type; + }; + + template + struct tuple_element<1U, ETL_OR_STD::pair > + { + typedef T2 type; + }; + + //****************************************************************************** + template + struct tuple_size> : public etl::integral_constant + { + }; +#endif + //****************************************************************************** template inline void swap(pair& a, pair& b) @@ -332,7 +362,7 @@ namespace etl a.swap(b); } - /// Two pairs of the same type are equal iff their members are equal. + /// Two pairs of the same type are equal if their members are equal. template inline bool operator ==(const pair& a, const pair& b) { @@ -496,7 +526,7 @@ namespace etl ETL_STATIC_ASSERT(etl::is_integral::value, "Integral types only"); - using value_type = T; + typedef T value_type; static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT { @@ -504,7 +534,7 @@ namespace etl } }; - namespace private_index_sequence + namespace private_integer_sequence { template struct make_index_sequence; @@ -524,11 +554,17 @@ namespace etl //*********************************** template - using make_index_sequence = typename private_index_sequence::make_index_sequence>::type; + using make_index_sequence = typename private_integer_sequence::make_index_sequence>::type; + + template + using make_index_sequence_for = typename private_integer_sequence::make_index_sequence>::type; //*********************************** template using index_sequence = etl::integer_sequence; + + template + using index_sequence_for = typename etl::make_index_sequence_for; #endif //*************************************************************************** @@ -621,7 +657,7 @@ namespace etl //********************************* /// Const function operator. - //********************************* + //********************************* constexpr TReturn operator()(TParams... args) const { return ptr(etl::forward(args)...); diff --git a/test/data.h b/test/data.h index 9f5bf7f02..4e3524310 100644 --- a/test/data.h +++ b/test/data.h @@ -209,6 +209,13 @@ class TestDataM : public etl::instance_count> other.valid = false; } + TestDataM(const TestDataM&& other) noexcept + : value(std::move(other.value)) + , valid(true) + { + other.valid = false; + } + virtual ~TestDataM() { valid = false; @@ -249,8 +256,8 @@ class TestDataM : public etl::instance_count> return valid; } - T value; - bool valid; + T value; + mutable bool valid; private: From b6e21ca57d7c6aeee348eb16d1fcbf7e78b27d96 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 09:52:25 +0100 Subject: [PATCH 122/216] Refactored some traits to be implemented by etl::conjunction and etl::disjunction --- include/etl/type_traits.h | 175 +++++++++++++++++++------------------- test/test_type_traits.cpp | 34 +++++--- 2 files changed, 110 insertions(+), 99 deletions(-) diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index b75118edc..7e7c17c7a 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1322,6 +1322,56 @@ typedef integral_constant true_type; // ETL extended type traits. //*************************************************************************** +#if ETL_USING_CPP11 + //*************************************************************************** + /// conjunction +#if ETL_USING_CPP11 + template + struct conjunction : public etl::true_type + { + }; + + template + struct conjunction : public etl::conditional_t, T1> + { + }; + + template + struct conjunction : public T + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool conjunction_v = conjunction::value; +#endif + + //*************************************************************************** + /// disjunction +#if ETL_USING_CPP11 + template + struct disjunction : public etl::false_type + { + }; + + template + struct disjunction : public etl::conditional_t> + { + }; + + template struct disjunction : public T1 + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + +#endif + //*************************************************************************** /// conditional_integral_constant // /\ingroup type_traits @@ -1346,17 +1396,13 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is one of a specified list. ///\ingroup types - template - struct is_one_of - { - static const bool value = etl::is_same::value || - etl::is_one_of::value; - }; - template - struct is_one_of + //*************************************************************************** + /// Template to determine if a type is a base of all types in a specified list. + ///\ingroup types + template + struct is_one_of : etl::disjunction...> { - static const bool value = etl::is_same::value; }; #else //*************************************************************************** @@ -1399,41 +1445,25 @@ typedef integral_constant true_type; /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types template - struct is_base_of_all; - - template - struct is_base_of_all : etl::true_type - { - }; - - template - struct is_base_of_all : etl::integral_constant::value && - etl::is_base_of_all::value> + struct is_base_of_all : etl::conjunction...> { }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; + template + inline constexpr bool is_base_of_all_v = etl::is_base_of_all::value; #endif #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of any type in a specified list. ///\ingroup types - template - struct is_base_of_any + template + struct is_base_of_any : etl::disjunction...> { - static const bool value = etl::is_base_of::value || - etl::is_base_of_any::value; }; - template - struct is_base_of_any - { - static const bool value = etl::is_base_of::value; - }; #endif #if ETL_USING_CPP17 @@ -1441,6 +1471,28 @@ typedef integral_constant true_type; inline constexpr bool is_base_of_any_v = etl::is_base_of_any::value; #endif + //*************************************************************************** + /// Get the Nth base of a recursively inherited type. + /// Requires that the class has defined 'base_type'. + //*************************************************************************** + // Recursive definition of the type. + template + struct nth_base + { + typedef typename nth_base::type type; + }; + + template + struct nth_base<0, TType> + { + typedef TType type; + }; + +#if ETL_USING_CPP11 + template + using nth_base_t = typename nth_base::type; +#endif + //*************************************************************************** /// A set of templates to allow related types to be derived. ///\ingroup types @@ -1594,70 +1646,15 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** /// are_all_same - template - struct are_all_same - { - static const bool value = etl::is_same::value && - etl::are_all_same::value; - }; - - template - struct are_all_same - { - static const bool value = etl::is_same::value; - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool are_all_same_v = are_all_same::value; -#endif - - //*************************************************************************** - /// conjunction -#if ETL_USING_CPP11 - template - struct conjunction : public etl::true_type - { - }; - - template - struct conjunction : public etl::conditional_t, T1> - { - }; - - template - struct conjunction : public T - { - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool conjunction_v = conjunction::value; -#endif - - //*************************************************************************** - /// disjunction -#if ETL_USING_CPP11 - template - struct disjunction : public etl::false_type - { - }; - - template - struct disjunction : public etl::conditional_t> - { - }; - - template struct disjunction : public T1 + template + struct are_all_same : etl::conjunction...> { }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool disjunction_v = etl::disjunction::value; + template + inline constexpr bool are_all_same_v = are_all_same::value; #endif //*************************************************************************** diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 37d620cdd..6e2ce3c28 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1098,11 +1098,11 @@ namespace TEST(test_conjunction) { #if ETL_USING_CPP17 - CHECK((etl::conjunction_v)); - CHECK((!etl::conjunction_v)); + CHECK_TRUE((etl::conjunction_v)); + CHECK_FALSE((etl::conjunction_v)); #else - CHECK((etl::conjunction::value)); - CHECK((!etl::conjunction::value)); + CHECK_TRUE((etl::conjunction::value)); + CHECK_FALSE((etl::conjunction::value)); #endif } @@ -1110,11 +1110,11 @@ namespace TEST(test_disjunction) { #if ETL_USING_CPP17 - CHECK((etl::disjunction_v)); - CHECK((!etl::disjunction_v)); + CHECK_TRUE((etl::disjunction_v)); + CHECK_FALSE((etl::disjunction_v)); #else - CHECK((etl::disjunction::value)); - CHECK((!etl::disjunction::value)); + CHECK_TRUE((etl::disjunction::value)); + CHECK_FALSE((etl::disjunction::value)); #endif } @@ -1320,16 +1320,30 @@ namespace struct D4 {}; #if ETL_USING_CPP17 - CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_TRUE(bool(etl::is_base_of_all_v)); CHECK_FALSE(bool(etl::is_base_of_all_v)); #else - CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_TRUE(bool(etl::is_base_of_all::value)); CHECK_FALSE(bool(etl::is_base_of_all::value)); #endif } + //************************************************************************* + TEST(test_nth_base) + { + struct D0 { }; + struct D1 : D0 { using base_type = D0; }; + struct D2 : D1 { using base_type = D1; }; + struct D3 : D2 { using base_type = D2; }; + struct D4 : D3 { using base_type = D3; }; + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + //************************************************************************* TEST(test_type_identity) { From 7726faaf9703259694a28689b6de39a9466efd30 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 17:18:35 +0100 Subject: [PATCH 123/216] Synchronised type_traits.h with generator --- .../etl/generators/type_traits_generator.h | 219 ++++++++++-------- include/etl/type_traits.h | 51 ++-- 2 files changed, 151 insertions(+), 119 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index bc5edbeab..4208817c7 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -639,8 +639,8 @@ namespace etl struct is_base_of { private: - static TBase* check(TBase*) { return (TBase*)0; } + static TBase* check(TBase*) { return (TBase*)0; } static char check(...) { return 0; } public: @@ -1334,6 +1334,56 @@ typedef integral_constant true_type; // ETL extended type traits. //*************************************************************************** +#if ETL_USING_CPP11 + //*************************************************************************** + /// conjunction +#if ETL_USING_CPP11 + template + struct conjunction : public etl::true_type + { + }; + + template + struct conjunction : public etl::conditional_t, T1> + { + }; + + template + struct conjunction : public T + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool conjunction_v = conjunction::value; +#endif + + //*************************************************************************** + /// disjunction +#if ETL_USING_CPP11 + template + struct disjunction : public etl::false_type + { + }; + + template + struct disjunction : public etl::conditional_t> + { + }; + + template struct disjunction : public T1 + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool disjunction_v = etl::disjunction::value; +#endif + +#endif + //*************************************************************************** /// conditional_integral_constant // /\ingroup type_traits @@ -1356,19 +1406,11 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** - /// Template to determine if a type is one of a specified list. + /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types - template - struct is_one_of - { - static const bool value = etl::is_same::value || - etl::is_one_of::value; - }; - - template - struct is_one_of + template + struct is_one_of : etl::disjunction...> { - static const bool value = etl::is_same::value; }; #else /*[[[cog @@ -1402,22 +1444,47 @@ typedef integral_constant true_type; #endif #if ETL_USING_CPP11 - //*************************************************************************** - /// Template to determine if a type is a base of all types in a specified list. - ///\ingroup types - template - struct is_base_of_all; + namespace private_type_traits + { + //*************************************************************************** + // Helper to count occurrences of a type in a list of types + template + struct count_type; + + // Base case: zero occurrences + template + struct count_type : etl::integral_constant + { + }; - template - struct is_base_of_all : etl::true_type + // Recursive case: increment count if head is the same as T, otherwise continue with tail + template + struct count_type : etl::integral_constant::value ? 1 : 0) + count_type::value> + { + }; + } + + template + struct has_duplicates_of + : etl::integral_constant::value > 1)> { }; +#endif - template - struct is_base_of_all : etl::integral_constant::value && - etl::is_base_of_all::value> +#if ETL_USING_CPP17 + template + inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; +#endif + +#if ETL_USING_CPP11 + //*************************************************************************** + /// Template to determine if a type is a base of all types in a specified list. + ///\ingroup types + template + struct is_base_of_all : etl::conjunction...> { }; +#endif #if ETL_USING_CPP17 template @@ -1428,18 +1495,11 @@ typedef integral_constant true_type; //*************************************************************************** /// Template to determine if a type is a base of any type in a specified list. ///\ingroup types - template - struct is_base_of_any + template + struct is_base_of_any : etl::disjunction...> { - static const bool value = etl::is_base_of::value || - etl::is_base_of_any::value; }; - template - struct is_base_of_any - { - static const bool value = etl::is_base_of::value; - }; #endif #if ETL_USING_CPP17 @@ -1447,6 +1507,28 @@ typedef integral_constant true_type; inline constexpr bool is_base_of_any_v = etl::is_base_of_any::value; #endif + //*************************************************************************** + /// Get the Nth base of a recursively inherited type. + /// Requires that the class has defined 'base_type'. + //*************************************************************************** + // Recursive definition of the type. + template + struct nth_base + { + typedef typename nth_base::type type; + }; + + template + struct nth_base<0, TType> + { + typedef TType type; + }; + +#if ETL_USING_CPP11 + template + using nth_base_t = typename nth_base::type; +#endif + //*************************************************************************** /// A set of templates to allow related types to be derived. ///\ingroup types @@ -1600,70 +1682,15 @@ typedef integral_constant true_type; #if ETL_USING_CPP11 //*************************************************************************** /// are_all_same - template - struct are_all_same - { - static const bool value = etl::is_same::value && - etl::are_all_same::value; - }; - - template - struct are_all_same - { - static const bool value = etl::is_same::value; - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool are_all_same_v = are_all_same::value; -#endif - - //*************************************************************************** - /// conjunction -#if ETL_USING_CPP11 - template - struct conjunction : public etl::true_type - { - }; - - template - struct conjunction : public etl::conditional_t, T1> - { - }; - - template - struct conjunction : public T - { - }; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool conjunction_v = conjunction::value; -#endif - - //*************************************************************************** - /// disjunction -#if ETL_USING_CPP11 - template - struct disjunction : public etl::false_type - { - }; - - template - struct disjunction : public etl::conditional_t> - { - }; - - template struct disjunction : public T1 + template + struct are_all_same : etl::conjunction...> { }; #endif #if ETL_USING_CPP17 - template - inline constexpr bool disjunction_v = etl::disjunction::value; + template + inline constexpr bool are_all_same_v = are_all_same::value; #endif //*************************************************************************** @@ -2344,18 +2371,6 @@ typedef integral_constant true_type; template inline constexpr size_t count_of_v = etl::count_of::value; #endif - -#if ETL_USING_CPP11 - //********************************************* - // has_duplicates_of - template - struct has_duplicates_of : etl::bool_constant<(etl::count_of::value > 1U)> {}; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; -#endif } // Helper macros diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 7e7c17c7a..d063a335a 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -627,8 +627,8 @@ namespace etl struct is_base_of { private: - static TBase* check(TBase*) { return (TBase*)0; } + static TBase* check(TBase*) { return (TBase*)0; } static char check(...) { return 0; } public: @@ -1393,10 +1393,6 @@ typedef integral_constant true_type; }; #if ETL_USING_CPP11 - //*************************************************************************** - /// Template to determine if a type is one of a specified list. - ///\ingroup types - //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. ///\ingroup types @@ -1440,6 +1436,39 @@ typedef integral_constant true_type; inline constexpr bool is_one_of_v = etl::is_one_of::value; #endif +#if ETL_USING_CPP11 + namespace private_type_traits + { + //*************************************************************************** + // Helper to count occurrences of a type in a list of types + template + struct count_type; + + // Base case: zero occurrences + template + struct count_type : etl::integral_constant + { + }; + + // Recursive case: increment count if head is the same as T, otherwise continue with tail + template + struct count_type : etl::integral_constant::value ? 1 : 0) + count_type::value> + { + }; + } + + template + struct has_duplicates_of + : etl::integral_constant::value > 1)> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; +#endif + #if ETL_USING_CPP11 //*************************************************************************** /// Template to determine if a type is a base of all types in a specified list. @@ -2335,18 +2364,6 @@ typedef integral_constant true_type; template inline constexpr size_t count_of_v = etl::count_of::value; #endif - -#if ETL_USING_CPP11 - //********************************************* - // has_duplicates_of - template - struct has_duplicates_of : etl::bool_constant<(etl::count_of::value > 1U)> {}; -#endif - -#if ETL_USING_CPP17 - template - inline constexpr bool has_duplicates_of_v = etl::has_duplicates_of::value; -#endif } // Helper macros From 475674288c948e2f26b8650bb90d4eaba8f05aee Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 14 Apr 2025 17:34:27 +0100 Subject: [PATCH 124/216] Added etl::tuple to VS project Added tuple to CMakeLists.txt --- test/CMakeLists.txt | 1 + test/syntax_check/CMakeLists.txt | 1 + test/syntax_check/tuple.h.t.cpp | 29 +++++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 20 ++++++++++++++++++++ test/vs2022/etl.vcxproj.filters | 12 ++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 test/syntax_check/tuple.h.t.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 09d5e364e..8747bcb48 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -286,6 +286,7 @@ add_executable(etl_tests test_to_u32string.cpp test_to_u8string.cpp test_to_wstring.cpp + test_tuple.cpp test_type_def.cpp test_type_list.cpp test_type_lookup.cpp diff --git a/test/syntax_check/CMakeLists.txt b/test/syntax_check/CMakeLists.txt index 0dab0a415..5eeb8ee2c 100644 --- a/test/syntax_check/CMakeLists.txt +++ b/test/syntax_check/CMakeLists.txt @@ -303,6 +303,7 @@ target_sources(tests PRIVATE to_u32string.h.t.cpp to_u8string.h.t.cpp to_wstring.h.t.cpp + tuple.h.t.cpp type_def.h.t.cpp type_lookup.h.t.cpp type_select.h.t.cpp diff --git a/test/syntax_check/tuple.h.t.cpp b/test/syntax_check/tuple.h.t.cpp new file mode 100644 index 000000000..ed8e8d646 --- /dev/null +++ b/test/syntax_check/tuple.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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 diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index fde32d913..bfebb2b5d 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3186,6 +3186,8 @@ + + @@ -3336,6 +3338,7 @@ + @@ -7847,6 +7850,22 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -9457,6 +9476,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 322cefa3f..a0bc794b4 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1443,6 +1443,15 @@ ETL\Utilities + + ETL\Containers + + + ETL\Private + + + ETL\Private + @@ -3449,6 +3458,9 @@ Tests\Types + + Tests\Containers + From 2f7cab35207c693f0157d490c855e21258df66af Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 15 Apr 2025 07:54:22 +0100 Subject: [PATCH 125/216] C++11 compatibility updates --- include/etl/tuple.h | 87 +++++++++++++++++++++++++++------------------ test/test_tuple.cpp | 1 + 2 files changed, 53 insertions(+), 35 deletions(-) diff --git a/include/etl/tuple.h b/include/etl/tuple.h index 32b8686c2..f1bdf319d 100644 --- a/include/etl/tuple.h +++ b/include/etl/tuple.h @@ -76,8 +76,9 @@ namespace etl struct ignore_t { template - ETL_CONSTEXPR void operator =(T&&) const ETL_NOEXCEPT + ETL_CONSTEXPR ignore_t operator =(T&&) const ETL_NOEXCEPT { + return *this; } }; } @@ -158,36 +159,36 @@ namespace etl friend class tuple; template - ETL_CONSTEXPR14 - friend auto& get(tuple&); + ETL_CONSTEXPR14 + friend etl::tuple_element_t>& get(tuple&); template ETL_CONSTEXPR14 - friend auto&& get(tuple&&); + friend etl::tuple_element_t>&& get(tuple&&); template ETL_CONSTEXPR14 - friend const auto& get(const tuple&); + friend const etl::tuple_element_t>& get(const tuple&); template ETL_CONSTEXPR14 - friend const auto&& get(const tuple&&); + friend const etl::tuple_element_t>&& get(const tuple&&); template - ETL_CONSTEXPR14 - friend auto& get(tuple&); + ETL_CONSTEXPR14 + friend T& get(tuple&); template - ETL_CONSTEXPR14 - friend auto&& get(tuple&&); + ETL_CONSTEXPR14 + friend T&& get(tuple&&); template - ETL_CONSTEXPR14 - friend const auto& get(const tuple&); + ETL_CONSTEXPR14 + friend const T& get(const tuple&); template - ETL_CONSTEXPR14 - friend const auto&& get(const tuple&&); + ETL_CONSTEXPR14 + friend const T&& get(const tuple&&); //********************************* /// Types @@ -728,7 +729,7 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto& get(tuple& t) + etl::tuple_element_t>& get(tuple& t) { ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); @@ -747,7 +748,7 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - const auto& get(const tuple& t) + const etl::tuple_element_t>& get(const tuple& t) { ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); @@ -766,7 +767,7 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto&& get(tuple&& t) + etl::tuple_element_t>&& get(tuple&& t) { ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); @@ -774,7 +775,7 @@ namespace etl using tuple_type = etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return etl::forward>>(static_cast(t).get_value()); } //*************************************************************************** @@ -785,15 +786,15 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - const auto&& get(const tuple&& t) + const etl::tuple_element_t>&& get(const tuple&& t) { ETL_STATIC_ASSERT(Index < sizeof...(TTypes), "etl::get - Index out of range"); // Get the type at this index. - using tuple_type = const etl::nth_base_t>&&; + using tuple_type = const etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return etl::forward>>(static_cast(t).get_value()); } //*************************************************************************** @@ -804,10 +805,10 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto& get(tuple& t) + T& get(tuple& t) { ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); - ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T using tuple_type = etl::private_tuple::tuple_type_base_t>; @@ -824,10 +825,10 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - const auto& get(const tuple& t) + const T& get(const tuple& t) { ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); - ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T using tuple_type = etl::private_tuple::tuple_type_base_t>; @@ -844,16 +845,16 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto&& get(tuple&& t) + T&& get(tuple&& t) { ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); - ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T using tuple_type = etl::private_tuple::tuple_type_base_t>; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return etl::forward(static_cast(t).get_value()); } //*************************************************************************** @@ -864,16 +865,16 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - const auto&& get(const tuple&& t) + const T&& get(const tuple&& t) { ETL_STATIC_ASSERT(!(etl::has_duplicates_of::value), "etl::get - Tuple contains duplicate instances of T"); - ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); + ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T using tuple_type = etl::private_tuple::tuple_type_base_t>; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return etl::forward(static_cast(t).get_value()); } #if ETL_USING_CPP17 @@ -886,7 +887,8 @@ namespace etl /// Creates a tuple of references to the provided arguments. //*************************************************************************** template - ETL_CONSTEXPR etl::tuple tie(TTypes&... args) + ETL_CONSTEXPR + etl::tuple tie(TTypes&... args) { return { args... }; } @@ -910,6 +912,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto select_from_tuple(TTuple&& tuple, etl::index_sequence) + -> etl::tuple>...> { ETL_STATIC_ASSERT(sizeof...(Indices) <= etl::tuple_size>::value, "Number of indices is greater than the tuple size"); @@ -924,6 +927,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto select_from_tuple(TTuple&& tuple) + -> etl::tuple>...> { return select_from_tuple(etl::forward(tuple), etl::index_sequence{}); } @@ -947,6 +951,7 @@ namespace etl template ETL_CONSTEXPR14 auto tuple_cat_impl(Tuple1&& t1, etl::index_sequence, Tuple2&& t2, etl::index_sequence) + -> etl::tuple>..., etl::tuple_element_t>...> { return etl::tuple>..., etl::tuple_element_t>...> @@ -960,7 +965,7 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto tuple_cat(Tuple&& t) + auto tuple_cat(Tuple&& t) -> Tuple { return etl::forward(t); } @@ -972,6 +977,10 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto tuple_cat(Tuple1&& t1, Tuple2&& t2, Tuples&&... ts) + -> decltype(private_tuple::tuple_cat_impl(etl::forward(t1), + etl::make_index_sequence>::value>{}, + etl::forward(t2), + etl::make_index_sequence>::value>{})) { auto concatenated = private_tuple::tuple_cat_impl(etl::forward(t1), etl::make_index_sequence>::value>{}, @@ -993,6 +1002,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std_impl(const TEtl_Tuple& etl_tuple, etl::index_sequence) + -> std::tuple::type...> { return std::tuple::type...>(etl::get(etl_tuple)...); } @@ -1002,6 +1012,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std_impl(TEtl_Tuple&& etl_tuple, etl::index_sequence) + -> std::tuple::type...> { return std::tuple::type...>(etl::move(etl::get(etl_tuple))...); } @@ -1014,6 +1025,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std(const etl::tuple& etl_tuple) + -> std::tuple::type...> { return private_tuple::to_std_impl(etl_tuple, etl::make_index_sequence_for()); } @@ -1025,6 +1037,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std(etl::tuple&& etl_tuple) + -> std::tuple::type...> { return private_tuple::to_std_impl(etl::move(etl_tuple), etl::make_index_sequence_for()); } @@ -1040,6 +1053,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_etl_impl(const TStd_Tuple& std_tuple, etl::index_sequence) + -> etl::tuple::type...> { return etl::tuple::type...>(std::get(std_tuple)...); } @@ -1048,7 +1062,8 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - auto to_etl_impl(TStd_Tuple&& std_tuple, etl::index_sequence) + auto to_etl_impl(TStd_Tuple&& std_tuple, etl::index_sequence) + -> etl::tuple::type...> { return etl::tuple::type...>(std::move(std::get(std_tuple))...); } @@ -1061,6 +1076,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_etl(const std::tuple& std_tuple) + -> etl::tuple::type...> { return private_tuple::to_etl_impl(std_tuple, etl::make_index_sequence_for()); } @@ -1072,6 +1088,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_etl(std::tuple&& std_tuple) + -> etl::tuple::type...> { return private_tuple::to_etl_impl(etl::move(std_tuple), etl::make_index_sequence_for()); } @@ -1086,7 +1103,7 @@ namespace etl template ETL_NODISCARD ETL_CONSTEXPR14 - bool tuple_equality(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) + bool tuple_equality(const TTuple1& /*lhs*/, const TTuple2& /*rhs*/, etl::index_sequence<>) { return true; } diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index ed3ff2cdc..d1a003a59 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -44,6 +44,7 @@ namespace template auto to_array(etl::index_sequence) + -> std::array { return std::array{Indices...}; } From 192703be9f898216a8709db54f8f938cdd210dbd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 15 Apr 2025 08:23:09 +0100 Subject: [PATCH 126/216] C++11 compatibility updates --- include/etl/tuple.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/etl/tuple.h b/include/etl/tuple.h index f1bdf319d..bcc5bf519 100644 --- a/include/etl/tuple.h +++ b/include/etl/tuple.h @@ -1002,9 +1002,9 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std_impl(const TEtl_Tuple& etl_tuple, etl::index_sequence) - -> std::tuple::type...> + -> std::tuple...> { - return std::tuple::type...>(etl::get(etl_tuple)...); + return std::tuple...>(etl::get(etl_tuple)...); } ///********************************* @@ -1012,9 +1012,9 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std_impl(TEtl_Tuple&& etl_tuple, etl::index_sequence) - -> std::tuple::type...> + -> std::tuple...> { - return std::tuple::type...>(etl::move(etl::get(etl_tuple))...); + return std::tuple...>(etl::move(etl::get(etl_tuple))...); } } @@ -1025,7 +1025,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std(const etl::tuple& etl_tuple) - -> std::tuple::type...> + -> std::tuple...> { return private_tuple::to_std_impl(etl_tuple, etl::make_index_sequence_for()); } @@ -1037,7 +1037,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_std(etl::tuple&& etl_tuple) - -> std::tuple::type...> + -> std::tuple...> { return private_tuple::to_std_impl(etl::move(etl_tuple), etl::make_index_sequence_for()); } @@ -1076,7 +1076,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_etl(const std::tuple& std_tuple) - -> etl::tuple::type...> + -> etl::tuple...> { return private_tuple::to_etl_impl(std_tuple, etl::make_index_sequence_for()); } @@ -1088,7 +1088,7 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR14 auto to_etl(std::tuple&& std_tuple) - -> etl::tuple::type...> + -> etl::tuple...> { return private_tuple::to_etl_impl(etl::move(std_tuple), etl::make_index_sequence_for()); } From 01f7cf2b177ae6b98bc788a87de5f5cc242cea21 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 15 Apr 2025 19:50:31 +0100 Subject: [PATCH 127/216] C++11 compatibility updates --- include/etl/tuple.h | 20 ++++++++--------- test/test_tuple.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/include/etl/tuple.h b/include/etl/tuple.h index bcc5bf519..2b15e017e 100644 --- a/include/etl/tuple.h +++ b/include/etl/tuple.h @@ -775,7 +775,7 @@ namespace etl using tuple_type = etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward>>(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -794,7 +794,7 @@ namespace etl using tuple_type = const etl::nth_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward>>(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -811,10 +811,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = etl::private_tuple::tuple_type_base_t>&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return static_cast(t).get_value(); } //*************************************************************************** @@ -831,10 +831,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = const etl::private_tuple::tuple_type_base_t>&; // Cast the tuple to the selected type and get the value. - return static_cast(t).get_value(); + return static_cast(t).get_value(); } //*************************************************************************** @@ -851,10 +851,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = etl::private_tuple::tuple_type_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } //*************************************************************************** @@ -871,10 +871,10 @@ namespace etl ETL_STATIC_ASSERT((etl::is_one_of::value), "etl::get - Tuple does not contain the specified type"); // Get the tuple base type that contains a T - using tuple_type = etl::private_tuple::tuple_type_base_t>; + using tuple_type = const etl::private_tuple::tuple_type_base_t>&&; // Cast the tuple to the selected type and get the value. - return etl::forward(static_cast(t).get_value()); + return etl::move(static_cast(t).get_value()); } #if ETL_USING_CPP17 diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index d1a003a59..c794c1165 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -239,7 +239,7 @@ namespace } //************************************************************************* - TEST(test_get) + TEST(test_get_using_index_lvalue) { etl::tuple data(Data("1"), DataM("3")); const etl::tuple const_data(Data("2"), DataM("4")); @@ -255,6 +255,57 @@ namespace CHECK_EQUAL(std::string("4"), d3.value); } + //************************************************************************* + TEST(test_get_using_index_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get<0>(etl::move(data)); + const Data&& d1 = etl::get<0>(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get<1>(etl::move(data))); + const DataM&& d3 = etl::move(etl::get<1>(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_lvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data d0 = etl::get(data); + Data d1 = etl::get(const_data); + DataM d2 = etl::move(etl::get(data)); + DataM d3 = etl::move(etl::get(const_data)); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + + //************************************************************************* + TEST(test_get_using_type_rvalue) + { + etl::tuple data(Data("1"), DataM("3")); + const etl::tuple const_data(Data("2"), DataM("4")); + + Data&& d0 = etl::get(etl::move(data)); + const Data&& d1 = etl::get(etl::move(const_data)); + DataM&& d2 = etl::move(etl::get(etl::move(data))); + const DataM&& d3 = etl::move(etl::get(etl::move(const_data))); + + CHECK_EQUAL(std::string("1"), d0.value); + CHECK_EQUAL(std::string("2"), d1.value); + CHECK_EQUAL(std::string("3"), d2.value); + CHECK_EQUAL(std::string("4"), d3.value); + } + //************************************************************************* TEST(test_construct_from_pair) { From 459709bff5ba8947d984e9cd964e37d46055d9ef Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 16 Apr 2025 19:33:24 +0100 Subject: [PATCH 128/216] Minor style change --- include/etl/private/tuple_size.h | 4 ++-- test/vs2022/etl.vcxproj.filters | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/include/etl/private/tuple_size.h b/include/etl/private/tuple_size.h index 640677498..895a61f7e 100644 --- a/include/etl/private/tuple_size.h +++ b/include/etl/private/tuple_size.h @@ -34,11 +34,11 @@ SOFTWARE. namespace etl { //*************************************************************************** - template + template struct tuple_size; //*************************************************************************** - template + template struct tuple_size : etl::integral_constant::value> { }; diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index a0bc794b4..8b0716093 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1443,15 +1443,15 @@ ETL\Utilities - - ETL\Containers - ETL\Private ETL\Private + + ETL\Utilities + @@ -3461,6 +3461,9 @@ Tests\Containers + + Tests + From 3f3a8b06d97903a11c5ceb158c25c15951e69b05 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 16 Apr 2025 19:38:11 +0100 Subject: [PATCH 129/216] Fix misspelt header include --- test/test_tuple.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index c794c1165..f4af43f33 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -28,7 +28,7 @@ SOFTWARE. #include "unit_test_framework.h" -#include "Data.h" +#include "data.h" #include "etl/tuple.h" #include "etl/private/tuple_size.h" From b966e2aca7076a5323e255824794ab2a5ea1f5f9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 17 Apr 2025 10:15:12 +0100 Subject: [PATCH 130/216] Minor style change --- include/etl/functional.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/etl/functional.h b/include/etl/functional.h index d1ce6d048..7fb3e4153 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -121,10 +121,10 @@ namespace etl typedef T type; }; - template - struct unwrap_reference > + template + struct unwrap_reference > { - typedef U& type; + typedef T& type; }; #if ETL_USING_CPP11 From 88adbab3f47ecfcbf0b1baf0c6d0ce7634751ed6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 17 Apr 2025 10:16:09 +0100 Subject: [PATCH 131/216] Added exclusive_disjunction --- .../etl/generators/type_traits_generator.h | 23 +++++++++++++++++++ include/etl/type_traits.h | 23 +++++++++++++++++++ test/test_type_traits.cpp | 14 +++++++++++ 3 files changed, 60 insertions(+) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 4208817c7..ac421eb95 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1382,6 +1382,29 @@ typedef integral_constant true_type; inline constexpr bool disjunction_v = etl::disjunction::value; #endif +#endif + + //*************************************************************************** + /// exclusive_disjunction +#if ETL_USING_CPP11 + template + struct exclusive_disjunction; + + template + struct exclusive_disjunction : public etl::bool_constant + { + }; + + // Recursive case: XOR the first two values and recurse + template + struct exclusive_disjunction : public etl::exclusive_disjunction::value && !etl::conjunction::value>, TRest...> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool exclusive_disjunction_v = etl::exclusive_disjunction::value; #endif //*************************************************************************** diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index d063a335a..44b7805f3 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1370,6 +1370,29 @@ typedef integral_constant true_type; inline constexpr bool disjunction_v = etl::disjunction::value; #endif +#endif + + //*************************************************************************** + /// exclusive_disjunction +#if ETL_USING_CPP11 + template + struct exclusive_disjunction; + + template + struct exclusive_disjunction : public etl::bool_constant + { + }; + + // Recursive case: XOR the first two values and recurse + template + struct exclusive_disjunction : public etl::exclusive_disjunction::value && !etl::conjunction::value>, TRest...> + { + }; +#endif + +#if ETL_USING_CPP17 + template + inline constexpr bool exclusive_disjunction_v = etl::exclusive_disjunction::value; #endif //*************************************************************************** diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 6e2ce3c28..a01e1b0ae 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1118,6 +1118,20 @@ namespace #endif } + //************************************************************************* + TEST(test_exclusive_disjunction) + { +#if ETL_USING_CPP17 + CHECK_TRUE((etl::exclusive_disjunction_v)); + CHECK_FALSE((etl::exclusive_disjunction_v)); + CHECK_FALSE((etl::exclusive_disjunction_v)); +#else + CHECK_TRUE((etl::exclusive_disjunction::value)); + CHECK_FALSE((etl::exclusive_disjunction::value)); + CHECK_FALSE((etl::exclusive_disjunction::value)); +#endif + } + //************************************************************************* TEST(test_is_assignable) { From 38c9cab2f7381db470635af85c16384a2f715616 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 17 Apr 2025 14:06:34 +0100 Subject: [PATCH 132/216] Minor style change --- include/etl/alignment.h | 2 +- include/etl/intrusive_links.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/alignment.h b/include/etl/alignment.h index 5c7e5ac85..627517be3 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -350,7 +350,7 @@ namespace etl #endif //*************************************************************************** - /// Wrapper class that provides a memory area and lets the user create and + /// Wrapper class that provides a memory area and lets the user create an /// instance of T in this memory at runtime. This class also erases the /// destructor call of T, i.e. if typed_storage goes out of scope, the /// destructor if the wrapped type will not be called. This can be done diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 9c0e471c0..9f0e55149 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -375,7 +375,7 @@ namespace etl } //*************************************************************************** - // link_clear + // link_clear range //*************************************************************************** // Reference template From bc158cbcbc95e18e7374cdc3250c12bd7c9162a1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 18 Apr 2025 10:50:48 +0100 Subject: [PATCH 133/216] Updates to chrono classes --- .gitignore | 2 + include/etl/chrono.h | 4 +- include/etl/platform.h | 16 +- include/etl/private/chrono/day.h | 4 +- include/etl/private/chrono/duration.h | 30 +- include/etl/private/chrono/month.h | 4 +- include/etl/private/chrono/month_day.h | 156 ++++++ include/etl/private/chrono/operators.h | 189 +++++++ include/etl/private/chrono/weekday.h | 6 +- include/etl/private/chrono/year.h | 4 +- test/.gitattributes | 1 + test/CMakeLists.txt | 597 +++++++++++----------- test/cppcheck_macro_definitions.txt | 5 + test/test_chrono_day.cpp | 195 +++---- test/test_chrono_month_day.cpp | 384 ++++++++++++++ test/test_chrono_weekday.cpp | 3 + test/test_chrono_weekday_indexed.cpp | 1 + test/test_chrono_weekday_last.cpp | 1 + test/vs2022/etl.vcxproj | 4 + test/vs2022/etl.vcxproj.filters | 12 + test/vs2022/etl_solution_suppressions.cfg | 4 + 21 files changed, 1174 insertions(+), 448 deletions(-) create mode 100644 include/etl/private/chrono/month_day.h create mode 100644 include/etl/private/chrono/operators.h create mode 100644 test/.gitattributes create mode 100644 test/cppcheck_macro_definitions.txt create mode 100644 test/test_chrono_month_day.cpp create mode 100644 test/vs2022/etl_solution_suppressions.cfg diff --git a/.gitignore b/.gitignore index ab33079c2..420a66d30 100644 --- a/.gitignore +++ b/.gitignore @@ -389,3 +389,5 @@ test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt test/reflog.txt +test/etl_error_handler/assert_function/build-make +test/syntax_check/bgcc diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 51fd1fd8e..8789d6561 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -49,7 +49,9 @@ SOFTWARE. #include "private/chrono/weekday_indexed.h" #include "private/chrono/weekday_last.h" #include "private/chrono/month.h" -#include "private/chrono/year.h" +#include "private/chrono/month_day.h" +#include "private/chrono/year.h" +#include "private/chrono/operators.h" #endif #undef ETL_IN_CHRONO_H diff --git a/include/etl/platform.h b/include/etl/platform.h index 361fade29..1eaa13295 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -272,8 +272,8 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has weekdays (_day) -#if defined(ETL_DISABLE_CHRONO_LITERALS_WEEKDAY) +// Indicate if etl::literals::chrono_literals has days (_days) +#if defined(ETL_DISABLE_CHRONO_LITERALS_DAY) #define ETL_HAS_CHRONO_LITERALS_DAY 0 #else #define ETL_HAS_CHRONO_LITERALS_DAY 1 @@ -288,7 +288,7 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has month (_month) +// Indicate if etl::literals::chrono_literals has month (_months) #if defined(ETL_DISABLE_CHRONO_LITERALS_MONTH) #define ETL_HAS_CHRONO_LITERALS_MONTH 0 #else @@ -296,13 +296,21 @@ SOFTWARE. #endif //************************************* -// Indicate if etl::literals::chrono_literals has year (_year) +// Indicate if etl::literals::chrono_literals has year (_years) #if defined(ETL_DISABLE_CHRONO_LITERALS_YEAR) #define ETL_HAS_CHRONO_LITERALS_YEAR 0 #else #define ETL_HAS_CHRONO_LITERALS_YEAR 1 #endif +//************************************* +// Indicate if etl::literals::chrono_literals has year (_hours, _minutes, _seconds, _milliseconds, _microseconds, _nanoseconds) +#if defined(ETL_DISABLE_CHRONO_LITERALS_DURATION) +#define ETL_HAS_CHRONO_LITERALS_DURATION 0 +#else +#define ETL_HAS_CHRONO_LITERALS_DURATION 1 +#endif + //************************************* // The macros below are dependent on the profile. // C++11 diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index 91557a957..511ae0a9f 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -311,7 +311,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_DAY -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -321,7 +320,7 @@ namespace etl //*********************************************************************** /// Literal for days //*********************************************************************** - constexpr etl::chrono::day operator ""_day(unsigned long long d) noexcept + inline constexpr etl::chrono::day operator ""_day(unsigned long long d) noexcept { return etl::chrono::day(static_cast(d)); } @@ -329,4 +328,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 6d4a53340..10c794602 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -258,11 +258,17 @@ namespace etl { ETL_CONSTEXPR14 size_t operator()(const etl::chrono::duration& d) const { - TRep value = d.count(); - size_t num = TPeriod::num; - size_t den = TPeriod::den; + uint8_t buffer[sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t)]; - return 0; //etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + TRep value = d.count(); + intmax_t num = TPeriod::num; + intmax_t den = TPeriod::den; + + memcpy(buffer, &value, sizeof(TRep)); + memcpy(buffer + sizeof(TRep), &num, sizeof(intmax_t)); + memcpy(buffer + sizeof(TRep) + sizeof(intmax_t), &den, sizeof(intmax_t)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(TRep) + sizeof(intmax_t) + sizeof(intmax_t)); } }; #endif @@ -349,8 +355,7 @@ namespace etl } } -#if ETL_HAS_CHRONO_LITERALS_DAY -#if ETL_USING_CPP11 +#if ETL_HAS_CHRONO_LITERALS_DURATION namespace etl { namespace literals @@ -360,7 +365,7 @@ namespace etl //*********************************************************************** /// Literal for hours duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::hours operator ""_hours(unsigned long long h) noexcept + inline ETL_CONSTEXPR etl::chrono::hours operator ""_hours(unsigned long long h) noexcept { return etl::chrono::hours(static_cast(h)); } @@ -368,7 +373,7 @@ namespace etl //*********************************************************************** /// Literal for minutes duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::minutes operator ""_minutes(unsigned long long m) noexcept + inline ETL_CONSTEXPR etl::chrono::minutes operator ""_minutes(unsigned long long m) noexcept { return etl::chrono::minutes(static_cast(m)); } @@ -376,7 +381,7 @@ namespace etl //*********************************************************************** /// Literal for seconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::seconds operator ""_seconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::seconds operator ""_seconds(unsigned long long s) noexcept { return etl::chrono::seconds(static_cast(s)); } @@ -384,7 +389,7 @@ namespace etl //*********************************************************************** /// Literal for milliseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::milliseconds operator ""_milliseconds(unsigned long long s) noexcept { return etl::chrono::milliseconds(static_cast(s)); } @@ -392,7 +397,7 @@ namespace etl //*********************************************************************** /// Literal for microseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::microseconds operator ""_microseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::microseconds operator ""_microseconds(unsigned long long s) noexcept { return etl::chrono::microseconds(static_cast(s)); } @@ -400,7 +405,7 @@ namespace etl //*********************************************************************** /// Literal for nanoseconds duration //*********************************************************************** - ETL_IF_CONSTEXPR etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) noexcept + inline ETL_CONSTEXPR etl::chrono::nanoseconds operator ""_nanoseconds(unsigned long long s) noexcept { return etl::chrono::nanoseconds(static_cast(s)); } @@ -408,4 +413,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 30653a589..f9693c2cc 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -362,7 +362,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_MONTH -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -372,7 +371,7 @@ namespace etl //*********************************************************************** /// Literal for months //*********************************************************************** - constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept + inline constexpr etl::chrono::month operator ""_month(unsigned long long m) noexcept { return etl::chrono::month(static_cast(m)); } @@ -380,4 +379,3 @@ namespace etl } } #endif -#endif diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h new file mode 100644 index 000000000..fbcb03bc2 --- /dev/null +++ b/include/etl/private/chrono/month_day.h @@ -0,0 +1,156 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + namespace private_chrono + { + static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + } + + class month_day + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + month_day() = default; + + //************************************************************************* + /// Construct from month and day. + //************************************************************************* + ETL_CONSTEXPR month_day(const etl::chrono::month& m_, const etl::chrono::day& d_) ETL_NOEXCEPT + : m(m_) + , d(d_) + { + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the day. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT + { + return d; + } + + //************************************************************************* + /// Returns true if the month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + if (!m.ok() || !d.ok()) + { + return false; + } + + unsigned max_day = 0; + + unsigned m_v = static_cast(m); + max_day = private_chrono::days_in_month[m_v]; + + return (max_day > 0) && + (static_cast(d) >= 1) && + (static_cast(d) <= max_day); + } + + //************************************************************************* + /// Returns true if the two instances are equal. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return (lhs.d == rhs.d) && (lhs.m == rhs.m); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + friend [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) noexcept + { + auto cmp = lhs.m <=> rhs.m; + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.d <=> rhs.d; + } + } +#endif + + private: + + etl::chrono::month m; + etl::chrono::day d; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::month_day + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_day& md) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int m = md.month(); + unsigned int d = md.day(); + + memcpy(buffer, &m, sizeof(m)); + memcpy(buffer + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/include/etl/private/chrono/operators.h b/include/etl/private/chrono/operators.h new file mode 100644 index 000000000..169217e7f --- /dev/null +++ b/include/etl/private/chrono/operators.h @@ -0,0 +1,189 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //// year_month + //constexpr auto operator/(const etl::chrono::year& y, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::year_month; + + //constexpr auto operator/( const etl::chrono::year& y, int m ) noexcept + // -> etl::chrono::year_month; + + //// month_day + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::day& d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::month& m, int d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( int m, const etl::chrono::day& d ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::day& d, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_day; + + //constexpr auto operator/( const etl::chrono::day& d, int m ) noexcept + // -> etl::chrono::month_day; + + //// month_day_last + //constexpr auto operator/( const etl::chrono::month& m, + // etl::chrono::last_spec ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( int m, etl::chrono::last_spec ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( etl::chrono::last_spec, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_day_last; + + //constexpr auto operator/( etl::chrono::last_spec, int m ) noexcept + // -> etl::chrono::month_day_last; + + //// month_weekday + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/( int m, const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/(const etl::chrono::weekday_indexed& wdi, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_weekday; + + //constexpr auto operator/( const etl::chrono::weekday_indexed& wdi, int m ) noexcept + // -> etl::chrono::month_weekday; + + //// month_weekday_last + //constexpr auto operator/( const etl::chrono::month& m, + // const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( int m, const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( const etl::chrono::weekday_last& wdl, + // const etl::chrono::month& m ) noexcept + // -> etl::chrono::month_weekday_last; + + //constexpr auto operator/( const etl::chrono::weekday_last& wdl, int m ) noexcept + // -> etl::chrono::month_weekday_last; + + //// year_month_day + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::day& d ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::year_month& ym, int d ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_day& md ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( int y, const etl::chrono::month_day& md ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::month_day& md, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_day; + + //constexpr auto operator/( const etl::chrono::month_day& md, int y ) noexcept + // -> etl::chrono::year_month_day; + + //// year_month_day_last + //constexpr auto operator/( const etl::chrono::year_month& ym, + // etl::chrono::last_spec ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_day_last& mdl ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( int y, const etl::chrono::month_day_last& mdl ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::month_day_last& mdl, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_day_last; + + //constexpr auto operator/( const etl::chrono::month_day_last& mdl, int y ) noexcept + // -> etl::chrono::year_month_day_last; + + //// year_month_weekday + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::weekday_indexed& wdi ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_weekday& mwd ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( int y, const etl::chrono::month_weekday& mwd ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::month_weekday& mwd, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_weekday; + + //constexpr auto operator/( const etl::chrono::month_weekday& mwd, int y ) noexcept + // -> etl::chrono::year_month_weekday; + + //// year_month_weekday_last + //constexpr auto operator/( const etl::chrono::year_month& ym, + // const etl::chrono::weekday_last& wdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::year& y, + // const etl::chrono::month_weekday_last& mwdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( int y, const etl::chrono::month_weekday_last& mwdl ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, + // const etl::chrono::year& y ) noexcept + // -> etl::chrono::year_month_weekday_last; + + //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, int y ) noexcept + // -> etl::chrono::year_month_weekday_last; + } +} \ No newline at end of file diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index fc4df27fa..d294d9c8b 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -370,7 +370,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_WEEKDAY -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -380,12 +379,11 @@ namespace etl //*********************************************************************** /// Literal for weekdays //*********************************************************************** - constexpr etl::chrono::weekday operator ""_weekday(unsigned long long m) noexcept + inline constexpr etl::chrono::weekday operator ""_weekday(unsigned long long wd) noexcept { - return etl::chrono::weekday(static_cast(m)); + return etl::chrono::weekday(static_cast(wd)); } } } } #endif -#endif diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index ff873e37b..695d369ff 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -311,7 +311,6 @@ namespace etl } #if ETL_HAS_CHRONO_LITERALS_YEAR -#if ETL_USING_CPP11 namespace etl { namespace literals @@ -321,7 +320,7 @@ namespace etl //*********************************************************************** /// Literal for years //*********************************************************************** - constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept + inline constexpr etl::chrono::year operator ""_year(unsigned long long y) noexcept { return etl::chrono::year(static_cast(y)); } @@ -329,4 +328,3 @@ namespace etl } } #endif -#endif diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 000000000..5a97bcace --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1 @@ +*.tar filter=lfs diff=lfs merge=lfs -text diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 648d4c4f6..87fe5d393 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,307 +12,308 @@ project(etl_unit_tests LANGUAGES CXX) add_executable(etl_tests main.cpp - murmurhash3.cpp - test_algorithm.cpp - test_alignment.cpp - test_array.cpp - test_array_view.cpp - test_array_wrapper.cpp - test_atomic.cpp - test_base64_RFC2152_decoder.cpp - test_base64_RFC2152_encoder.cpp - test_base64_RFC3501_decoder.cpp - test_base64_RFC3501_encoder.cpp - test_base64_RFC4648_decoder_with_no_padding.cpp - test_base64_RFC4648_decoder_with_padding.cpp - test_base64_RFC4648_encoder_with_no_padding.cpp - test_base64_RFC4648_encoder_with_padding.cpp - test_base64_RFC4648_URL_decoder_with_no_padding.cpp - test_base64_RFC4648_URL_decoder_with_padding.cpp - test_base64_RFC4648_URL_encoder_with_no_padding.cpp - test_base64_RFC4648_URL_encoder_with_padding.cpp - test_binary.cpp - test_bip_buffer_spsc_atomic.cpp - test_bit.cpp - test_bitset_legacy.cpp - test_bitset_new_comparisons.cpp - test_bitset_new_default_element_type.cpp - test_bitset_new_explicit_single_element_type.cpp - test_bitset_new_ext_default_element_type.cpp - test_bitset_new_ext_explicit_single_element_type.cpp - test_bit_stream.cpp - test_bit_stream_reader_big_endian.cpp - test_bit_stream_reader_little_endian.cpp - test_bit_stream_writer_big_endian.cpp - test_bit_stream_writer_little_endian.cpp - test_bloom_filter.cpp - test_bresenham_line.cpp - test_bsd_checksum.cpp - test_buffer_descriptors.cpp - test_byte.cpp - test_byte_stream.cpp - test_callback_service.cpp - test_callback_timer.cpp - test_callback_timer_atomic.cpp - test_callback_timer_interrupt.cpp - test_callback_timer_locked.cpp - test_char_traits.cpp - test_checksum.cpp - +# murmurhash3.cpp +# test_algorithm.cpp +# test_alignment.cpp +# test_array.cpp +# test_array_view.cpp +# test_array_wrapper.cpp +# test_atomic.cpp +# test_base64_RFC2152_decoder.cpp +# test_base64_RFC2152_encoder.cpp +# test_base64_RFC3501_decoder.cpp +# test_base64_RFC3501_encoder.cpp +# test_base64_RFC4648_decoder_with_no_padding.cpp +# test_base64_RFC4648_decoder_with_padding.cpp +# test_base64_RFC4648_encoder_with_no_padding.cpp +# test_base64_RFC4648_encoder_with_padding.cpp +# test_base64_RFC4648_URL_decoder_with_no_padding.cpp +# test_base64_RFC4648_URL_decoder_with_padding.cpp +# test_base64_RFC4648_URL_encoder_with_no_padding.cpp +# test_base64_RFC4648_URL_encoder_with_padding.cpp +# test_binary.cpp +# test_bip_buffer_spsc_atomic.cpp +# test_bit.cpp +# test_bitset_legacy.cpp +# test_bitset_new_comparisons.cpp +# test_bitset_new_default_element_type.cpp +# test_bitset_new_explicit_single_element_type.cpp +# test_bitset_new_ext_default_element_type.cpp +# test_bitset_new_ext_explicit_single_element_type.cpp +# test_bit_stream.cpp +# test_bit_stream_reader_big_endian.cpp +# test_bit_stream_reader_little_endian.cpp +# test_bit_stream_writer_big_endian.cpp +# test_bit_stream_writer_little_endian.cpp +# test_bloom_filter.cpp +# test_bresenham_line.cpp +# test_bsd_checksum.cpp +# test_buffer_descriptors.cpp +# test_byte.cpp +# test_byte_stream.cpp +# test_callback_service.cpp +# test_callback_timer.cpp +# test_callback_timer_atomic.cpp +# test_callback_timer_interrupt.cpp +# test_callback_timer_locked.cpp +# test_char_traits.cpp +# test_checksum.cpp test_chrono_day.cpp - test_chrono_weekday.cpp + test_chrono_duration.cpp test_chrono_month.cpp + test_chrono_weekday.cpp + test_chrono_weekday_indexed.cpp + test_chrono_weekday_last.cpp test_chrono_year.cpp - - test_circular_buffer.cpp - test_circular_buffer_external_buffer.cpp - test_circular_iterator.cpp - test_compare.cpp - test_constant.cpp - test_container.cpp - test_correlation.cpp - test_covariance.cpp - test_crc1.cpp - test_crc16.cpp - test_crc16_a.cpp - test_crc16_arc.cpp - test_crc16_aug_ccitt.cpp - test_crc16_buypass.cpp - test_crc16_ccitt.cpp - test_crc16_cdma2000.cpp - test_crc16_dds110.cpp - test_crc16_dectr.cpp - test_crc16_dectx.cpp - test_crc16_dnp.cpp - test_crc16_en13757.cpp - test_crc16_genibus.cpp - test_crc16_kermit.cpp - test_crc16_m17.cpp - test_crc16_maxim.cpp - test_crc16_mcrf4xx.cpp - test_crc16_modbus.cpp - test_crc16_profibus.cpp - test_crc16_riello.cpp - test_crc16_t10dif.cpp - test_crc16_teledisk.cpp - test_crc16_tms37157.cpp - test_crc16_usb.cpp - test_crc16_x25.cpp - test_crc16_xmodem.cpp - test_crc32.cpp - test_crc32_bzip2.cpp - test_crc32_c.cpp - test_crc32_d.cpp - test_crc32_jamcrc.cpp - test_crc32_mpeg2.cpp - test_crc32_posix.cpp - test_crc32_q.cpp - test_crc32_xfer.cpp - test_crc64_ecma.cpp - test_crc8_ccitt.cpp - test_crc8_cdma2000.cpp - test_crc8_darc.cpp - test_crc8_dvbs2.cpp - test_crc8_ebu.cpp - test_crc8_icode.cpp - test_crc8_itu.cpp - test_crc8_j1850.cpp - test_crc8_j1850_zero.cpp - test_crc8_maxim.cpp - test_crc8_rohc.cpp - test_crc8_wcdma.cpp - test_cyclic_value.cpp - test_debounce.cpp - test_delegate.cpp - test_delegate_cpp03.cpp - test_delegate_service.cpp - test_delegate_service_compile_time.cpp - test_delegate_service_cpp03.cpp - test_deque.cpp - test_endian.cpp - test_enum_type.cpp - test_error_handler.cpp - test_etl_traits.cpp - test_exception.cpp - test_expected.cpp - test_fixed_iterator.cpp - test_fixed_sized_memory_block_allocator.cpp - test_flags.cpp - test_flat_map.cpp - test_flat_multimap.cpp - test_flat_multiset.cpp - test_flat_set.cpp - test_fnv_1.cpp - test_format_spec.cpp - test_forward_list.cpp - test_forward_list_shared_pool.cpp - test_fsm.cpp - test_function.cpp - test_functional.cpp - test_gamma.cpp - test_hash.cpp - test_hfsm.cpp - test_hfsm_recurse_to_inner_state_on_start.cpp - test_histogram.cpp - test_indirect_vector.cpp - test_indirect_vector_external_buffer.cpp - test_instance_count.cpp - test_integral_limits.cpp - test_intrusive_forward_list.cpp - test_intrusive_links.cpp - test_intrusive_list.cpp - test_intrusive_queue.cpp - test_intrusive_stack.cpp - test_invert.cpp - test_io_port.cpp - test_iterator.cpp - test_jenkins.cpp - test_largest.cpp - test_limiter.cpp - test_limits.cpp - test_list.cpp - test_list_shared_pool.cpp - test_macros.cpp - test_make_string.cpp - test_map.cpp - test_math.cpp - test_math_functions.cpp - test_mean.cpp - test_memory.cpp - test_mem_cast.cpp - test_mem_cast_ptr.cpp - test_message.cpp - test_message_broker.cpp - test_message_bus.cpp - test_message_packet.cpp - test_message_router.cpp - test_message_router_registry.cpp - test_message_timer.cpp - test_message_timer_atomic.cpp - test_message_timer_interrupt.cpp - test_message_timer_locked.cpp - test_multimap.cpp - test_multiset.cpp - test_multi_array.cpp - test_multi_range.cpp - test_multi_span.cpp - test_multi_vector.cpp - test_murmur3.cpp - test_nth_type.cpp - test_numeric.cpp - test_observer.cpp - test_optional.cpp - test_overload.cpp - test_packet.cpp - test_parameter_pack.cpp - test_parameter_type.cpp - test_parity_checksum.cpp - test_pearson.cpp - test_poly_span_dynamic_extent.cpp - test_poly_span_fixed_extent.cpp - test_pool.cpp - test_pool_external_buffer.cpp - test_priority_queue.cpp - test_pseudo_moving_average.cpp - test_quantize.cpp - test_queue.cpp - test_queue_lockable.cpp - test_queue_lockable_small.cpp - test_queue_memory_model_small.cpp - test_queue_mpmc_mutex.cpp - test_queue_mpmc_mutex_small.cpp - test_queue_spsc_atomic.cpp - test_queue_spsc_atomic_small.cpp - test_queue_spsc_isr.cpp - test_queue_spsc_isr_small.cpp - test_queue_spsc_locked.cpp - test_queue_spsc_locked_small.cpp - test_random.cpp - test_reference_flat_map.cpp - test_reference_flat_multimap.cpp - test_reference_flat_multiset.cpp - test_reference_flat_set.cpp - test_rescale.cpp - test_result.cpp - test_rms.cpp - test_scaled_rounding.cpp - test_set.cpp - test_shared_message.cpp - test_singleton.cpp - test_smallest.cpp - test_span_dynamic_extent.cpp - test_span_fixed_extent.cpp - test_stack.cpp - test_standard_deviation.cpp - test_state_chart.cpp - test_state_chart_compile_time.cpp - test_state_chart_compile_time_with_data_parameter.cpp - test_state_chart_with_data_parameter.cpp - test_state_chart_with_rvalue_data_parameter.cpp - test_string_char.cpp - test_string_char_external_buffer.cpp - test_string_stream.cpp - test_string_stream_u16.cpp - test_string_stream_u32.cpp - test_string_stream_u8.cpp - test_string_stream_wchar_t.cpp - test_string_u16.cpp - test_string_u16_external_buffer.cpp - test_string_u32.cpp - test_string_u32_external_buffer.cpp - test_string_u8.cpp - test_string_u8_external_buffer.cpp - test_string_utilities.cpp - test_string_utilities_std.cpp - test_string_utilities_std_u16.cpp - test_string_utilities_std_u32.cpp - test_string_utilities_std_u8.cpp - test_string_utilities_std_wchar_t.cpp - test_string_utilities_u16.cpp - test_string_utilities_u32.cpp - test_string_utilities_u8.cpp - test_string_utilities_wchar_t.cpp - test_string_view.cpp - test_string_wchar_t.cpp - test_string_wchar_t_external_buffer.cpp - test_successor.cpp - test_task_scheduler.cpp - test_threshold.cpp - test_to_arithmetic.cpp - test_to_arithmetic_u16.cpp - test_to_arithmetic_u32.cpp - test_to_arithmetic_u8.cpp - test_to_arithmetic_wchar_t.cpp - test_to_string.cpp - test_to_u16string.cpp - test_to_u32string.cpp - test_to_u8string.cpp - test_to_wstring.cpp - test_type_def.cpp - test_type_lookup.cpp - test_type_select.cpp - test_type_traits.cpp - test_unaligned_type.cpp - test_unaligned_type_constexpr.cpp - test_unordered_map.cpp - test_unordered_multimap.cpp - test_unordered_multiset.cpp - test_unordered_set.cpp - test_user_type.cpp - test_utility.cpp - test_variance.cpp - test_variant_legacy.cpp - test_variant_pool.cpp - test_variant_pool_external_buffer.cpp - test_variant_variadic.cpp - test_vector.cpp - test_vector_external_buffer.cpp - test_vector_non_trivial.cpp - test_vector_pointer.cpp - test_vector_pointer_external_buffer.cpp - test_visitor.cpp - test_xor_checksum.cpp - test_xor_rotate_checksum.cpp +# test_circular_buffer.cpp +# test_circular_buffer_external_buffer.cpp +# test_circular_iterator.cpp +# test_compare.cpp +# test_constant.cpp +# test_container.cpp +# test_correlation.cpp +# test_covariance.cpp +# test_crc1.cpp +# test_crc16.cpp +# test_crc16_a.cpp +# test_crc16_arc.cpp +# test_crc16_aug_ccitt.cpp +# test_crc16_buypass.cpp +# test_crc16_ccitt.cpp +# test_crc16_cdma2000.cpp +# test_crc16_dds110.cpp +# test_crc16_dectr.cpp +# test_crc16_dectx.cpp +# test_crc16_dnp.cpp +# test_crc16_en13757.cpp +# test_crc16_genibus.cpp +# test_crc16_kermit.cpp +# test_crc16_m17.cpp +# test_crc16_maxim.cpp +# test_crc16_mcrf4xx.cpp +# test_crc16_modbus.cpp +# test_crc16_profibus.cpp +# test_crc16_riello.cpp +# test_crc16_t10dif.cpp +# test_crc16_teledisk.cpp +# test_crc16_tms37157.cpp +# test_crc16_usb.cpp +# test_crc16_x25.cpp +# test_crc16_xmodem.cpp +# test_crc32.cpp +# test_crc32_bzip2.cpp +# test_crc32_c.cpp +# test_crc32_d.cpp +# test_crc32_jamcrc.cpp +# test_crc32_mpeg2.cpp +# test_crc32_posix.cpp +# test_crc32_q.cpp +# test_crc32_xfer.cpp +# test_crc64_ecma.cpp +# test_crc8_ccitt.cpp +# test_crc8_cdma2000.cpp +# test_crc8_darc.cpp +# test_crc8_dvbs2.cpp +# test_crc8_ebu.cpp +# test_crc8_icode.cpp +# test_crc8_itu.cpp +# test_crc8_j1850.cpp +# test_crc8_j1850_zero.cpp +# test_crc8_maxim.cpp +# test_crc8_rohc.cpp +# test_crc8_wcdma.cpp +# test_cyclic_value.cpp +# test_debounce.cpp +# test_delegate.cpp +# test_delegate_cpp03.cpp +# test_delegate_service.cpp +# test_delegate_service_compile_time.cpp +# test_delegate_service_cpp03.cpp +# test_deque.cpp +# test_endian.cpp +# test_enum_type.cpp +# test_error_handler.cpp +# test_etl_traits.cpp +# test_exception.cpp +# test_expected.cpp +# test_fixed_iterator.cpp +# test_fixed_sized_memory_block_allocator.cpp +# test_flags.cpp +# test_flat_map.cpp +# test_flat_multimap.cpp +# test_flat_multiset.cpp +# test_flat_set.cpp +# test_fnv_1.cpp +# test_format_spec.cpp +# test_forward_list.cpp +# test_forward_list_shared_pool.cpp +# test_fsm.cpp +# test_function.cpp +# test_functional.cpp +# test_gamma.cpp +# test_hash.cpp +# test_hfsm.cpp +# test_hfsm_recurse_to_inner_state_on_start.cpp +# test_histogram.cpp +# test_indirect_vector.cpp +# test_indirect_vector_external_buffer.cpp +# test_instance_count.cpp +# test_integral_limits.cpp +# test_intrusive_forward_list.cpp +# test_intrusive_links.cpp +# test_intrusive_list.cpp +# test_intrusive_queue.cpp +# test_intrusive_stack.cpp +# test_invert.cpp +# test_io_port.cpp +# test_iterator.cpp +# test_jenkins.cpp +# test_largest.cpp +# test_limiter.cpp +# test_limits.cpp +# test_list.cpp +# test_list_shared_pool.cpp +# test_macros.cpp +# test_make_string.cpp +# test_map.cpp +# test_math.cpp +# test_math_functions.cpp +# test_mean.cpp +# test_memory.cpp +# test_mem_cast.cpp +# test_mem_cast_ptr.cpp +# test_message.cpp +# test_message_broker.cpp +# test_message_bus.cpp +# test_message_packet.cpp +# test_message_router.cpp +# test_message_router_registry.cpp +# test_message_timer.cpp +# test_message_timer_atomic.cpp +# test_message_timer_interrupt.cpp +# test_message_timer_locked.cpp +# test_multimap.cpp +# test_multiset.cpp +# test_multi_array.cpp +# test_multi_range.cpp +# test_multi_span.cpp +# test_multi_vector.cpp +# test_murmur3.cpp +# test_nth_type.cpp +# test_numeric.cpp +# test_observer.cpp +# test_optional.cpp +# test_overload.cpp +# test_packet.cpp +# test_parameter_pack.cpp +# test_parameter_type.cpp +# test_parity_checksum.cpp +# test_pearson.cpp +# test_poly_span_dynamic_extent.cpp +# test_poly_span_fixed_extent.cpp +# test_pool.cpp +# test_pool_external_buffer.cpp +# test_priority_queue.cpp +# test_pseudo_moving_average.cpp +# test_quantize.cpp +# test_queue.cpp +# test_queue_lockable.cpp +# test_queue_lockable_small.cpp +# test_queue_memory_model_small.cpp +# test_queue_mpmc_mutex.cpp +# test_queue_mpmc_mutex_small.cpp +# test_queue_spsc_atomic.cpp +# test_queue_spsc_atomic_small.cpp +# test_queue_spsc_isr.cpp +# test_queue_spsc_isr_small.cpp +# test_queue_spsc_locked.cpp +# test_queue_spsc_locked_small.cpp +# test_random.cpp +# test_reference_flat_map.cpp +# test_reference_flat_multimap.cpp +# test_reference_flat_multiset.cpp +# test_reference_flat_set.cpp +# test_rescale.cpp +# test_result.cpp +# test_rms.cpp +# test_scaled_rounding.cpp +# test_set.cpp +# test_shared_message.cpp +# test_singleton.cpp +# test_smallest.cpp +# test_span_dynamic_extent.cpp +# test_span_fixed_extent.cpp +# test_stack.cpp +# test_standard_deviation.cpp +# test_state_chart.cpp +# test_state_chart_compile_time.cpp +# test_state_chart_compile_time_with_data_parameter.cpp +# test_state_chart_with_data_parameter.cpp +# test_state_chart_with_rvalue_data_parameter.cpp +# test_string_char.cpp +# test_string_char_external_buffer.cpp +# test_string_stream.cpp +# test_string_stream_u16.cpp +# test_string_stream_u32.cpp +# test_string_stream_u8.cpp +# test_string_stream_wchar_t.cpp +# test_string_u16.cpp +# test_string_u16_external_buffer.cpp +# test_string_u32.cpp +# test_string_u32_external_buffer.cpp +# test_string_u8.cpp +# test_string_u8_external_buffer.cpp +# test_string_utilities.cpp +# test_string_utilities_std.cpp +# test_string_utilities_std_u16.cpp +# test_string_utilities_std_u32.cpp +# test_string_utilities_std_u8.cpp +# test_string_utilities_std_wchar_t.cpp +# test_string_utilities_u16.cpp +# test_string_utilities_u32.cpp +# test_string_utilities_u8.cpp +# test_string_utilities_wchar_t.cpp +# test_string_view.cpp +# test_string_wchar_t.cpp +# test_string_wchar_t_external_buffer.cpp +# test_successor.cpp +# test_task_scheduler.cpp +# test_threshold.cpp +# test_to_arithmetic.cpp +# test_to_arithmetic_u16.cpp +# test_to_arithmetic_u32.cpp +# test_to_arithmetic_u8.cpp +# test_to_arithmetic_wchar_t.cpp +# test_to_string.cpp +# test_to_u16string.cpp +# test_to_u32string.cpp +# test_to_u8string.cpp +# test_to_wstring.cpp +# test_type_def.cpp +# test_type_lookup.cpp +# test_type_select.cpp +# test_type_traits.cpp +# test_unaligned_type.cpp +# test_unaligned_type_constexpr.cpp +# test_unordered_map.cpp +# test_unordered_multimap.cpp +# test_unordered_multiset.cpp +# test_unordered_set.cpp +# test_user_type.cpp +# test_utility.cpp +# test_variance.cpp +# test_variant_legacy.cpp +# test_variant_pool.cpp +# test_variant_pool_external_buffer.cpp +# test_variant_variadic.cpp +# test_vector.cpp +# test_vector_external_buffer.cpp +# test_vector_non_trivial.cpp +# test_vector_pointer.cpp +# test_vector_pointer_external_buffer.cpp +# test_visitor.cpp +# test_xor_checksum.cpp +# test_xor_rotate_checksum.cpp ) target_compile_definitions(etl_tests PRIVATE -DETL_DEBUG) diff --git a/test/cppcheck_macro_definitions.txt b/test/cppcheck_macro_definitions.txt new file mode 100644 index 000000000..3f2fb051f --- /dev/null +++ b/test/cppcheck_macro_definitions.txt @@ -0,0 +1,5 @@ +ETL_CONSTEXPR constexpr +ETL_CONSTEXPR14 +ETL_CONSTEXPR17 +ETL_CONSTEXPR20 +ETL_IF_CONSTEXPR20 \ No newline at end of file diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp index 815cb4f4a..7a9432a86 100644 --- a/test/test_chrono_day.cpp +++ b/test/test_chrono_day.cpp @@ -30,128 +30,112 @@ SOFTWARE. #include "etl/platform.h" -#if ETL_USING_CPP20 - #include "unit_test_framework.h" #include "etl/chrono.h" -#include -#include +#include #include namespace { + //************************************************************************* + bool is_day_ok(etl::chrono::day day) + { + unsigned d = unsigned(day); + + if ((d < 1) || (d > 31)) + { + return (day.ok() == false); + } + else + { + return (day.ok() == true); + } + } + SUITE(test_chrono_day) { //************************************************************************* TEST(test_default_constructor) { - std::chrono::day std_day; etl::chrono::day day; - CHECK_EQUAL(std_day.ok(), day.ok()); + CHECK_FALSE(day.ok()); } //************************************************************************* TEST(test_constructor_in_range) { - for (unsigned i = 0U; i < 256; ++i) + for (unsigned expected = 1U; expected < 31; ++expected) { - std::chrono::day std_day(i); - etl::chrono::day day(i); + etl::chrono::day day(expected); - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_pre_increment) { - std::chrono::day std_day(0); etl::chrono::day day(0); - for (int i = 0; i < 255; ++i) + for (int expected = 0; expected < 256; ++expected, ++day) { - ++std_day; - ++day; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_post_increment) { - std::chrono::day std_day(0); etl::chrono::day day(0); - for (int i = 0; i < 255; ++i) + for (int expected = 0; expected < 256; expected++, day++) { - std::chrono::day std_last_day = std_day++; - etl::chrono::day last_day = day++; - - CHECK_EQUAL(std_last_day.ok(), last_day.ok()); - CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::day std_day(256); - etl::chrono::day day(256); + etl::chrono::day day(255); - for (int i = 0; i < 255; ++i) + for (int expected = 255; expected > 0; --expected, --day) { - --std_day; - --day; - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::day std_day(256); - etl::chrono::day day(256); + etl::chrono::day day(255); - for (int i = 0; i < 255; ++i) + for (int expected = 255; expected > 0; expected--, day--) { - std::chrono::day std_last_day = std_day--; - etl::chrono::day last_day = day--; - - CHECK_EQUAL(std_last_day.ok(), last_day.ok()); - CHECK_EQUAL(unsigned(std_last_day), unsigned(last_day)); - - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_plus_equal_days) { - std::chrono::day std_day(0); etl::chrono::day day(0); - - std::chrono::days std_days(2); etl::chrono::days days(2); - for (int i = 0; i < 128; ++i) + for (int expected = 2; expected < 256; expected += 2) { - std_day += std_days; - day += days; + day += days; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } @@ -162,17 +146,15 @@ namespace { for (int ds = 0; ds < 256; ++ds) { - std::chrono::day std_day(d); etl::chrono::day day(d); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); - std_day = std_day + std_days; - day = day + days; + day = day + days; + + unsigned expected = (d + ds) % 256; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } } @@ -182,19 +164,17 @@ namespace { for (int d = 0; d < 256; ++d) { - for (int ds = 0; ds < 256; ++ds) + for (int ds = 0; ds < d; ++ds) { - std::chrono::day std_day(d); etl::chrono::day day(d); - - std::chrono::days std_days(ds); etl::chrono::days days(ds); - std_day = std_days + std_day; - day = days + day; + day = days + day; + + unsigned expected = (d + ds) % 256; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } } @@ -202,66 +182,47 @@ namespace //************************************************************************* TEST(test_minus_equal_days) { - for (int d = 0; d <= 256; ++d) - { - for (int ds = 0; ds <= 256; ++ds) - { - std::chrono::day std_day(d); - etl::chrono::day day(d); - - std::chrono::days std_days(ds); - etl::chrono::days days(ds); + etl::chrono::day day(255); + etl::chrono::days days(2); - std_day -= std_days; - day -= days; + for (int expected = 253; expected > 0; expected -= 2) + { + day -= days; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_day_minus_days) { - for (int d = 0; d <= 256; ++d) - { - for (int ds = 0; ds <= 256; ++ds) - { - std::chrono::day std_day(d); - etl::chrono::day day(d); - - std::chrono::days std_days(ds); - etl::chrono::days days(ds); + etl::chrono::day day(255); + etl::chrono::days days(2); - std_day = std_day - std_days; - day = day - days; + for (int expected = 253; expected > 0; expected -= 2) + { + day = day - days; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); - } + CHECK_TRUE(is_day_ok(day)); + CHECK_EQUAL(expected, unsigned(day)); } } //************************************************************************* TEST(test_day_minus_day) { - for (int d = 0; d < 256; ++d) + for (int d1 = 0; d1 < 256; ++d1) { - std::chrono::day std_day1(d); - std::chrono::day std_day2(255 - d); - - std::chrono::day day1(d); - std::chrono::day day2(255 - d); - - auto std_days12 = std_day1 - std_day2; - auto std_days21 = std_day2 - std_day1; - - auto days12 = day1 - day2; - auto days21 = day2 - day1; + for (int d2 = 0; d2 < 256; ++d2) + { + etl::chrono::day day1(d1); + etl::chrono::day day2(d2); - CHECK_EQUAL(std_days12.count(), days12.count()); - CHECK_EQUAL(std_days21.count(), days21.count()); + etl::chrono::days result_days = day1 - day2; + int expected_days = d1 - d2; + CHECK_EQUAL(expected_days, result_days.count()); + } } } @@ -275,14 +236,12 @@ namespace //************************************************************************* TEST(test_literal_day) { - using namespace std::literals::chrono_literals; using namespace etl::literals::chrono_literals; - std::chrono::day std_day = 25d; - etl::chrono::day day = 25_day; + etl::chrono::day day = 25_day; - CHECK_EQUAL(std_day.ok(), day.ok()); - CHECK_EQUAL(unsigned(std_day), unsigned(day)); + CHECK_TRUE(day.ok()); + CHECK_EQUAL(25, unsigned(day)); } //************************************************************************* @@ -329,5 +288,3 @@ namespace } }; } - -#endif \ No newline at end of file diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp new file mode 100644 index 000000000..e1e0a5d87 --- /dev/null +++ b/test/test_chrono_month_day.cpp @@ -0,0 +1,384 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include + +#if ETL_USING_CPP20 + +namespace +{ + SUITE(test_chrono_month_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + etl::chrono::month_day md; + + CHECK_FALSE(md.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::month std_month(i); + etl::chrono::month month(i); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 255; ++i) + { + ++std_month; + ++month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month++; + etl::chrono::month last_month = month++; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + --std_month; + --month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month--; + etl::chrono::month last_month = month--; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_plus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month += std_months; + month += months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_plus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month + std_months; + month = month + months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_months_plus_month) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_months + std_month; + month = months + month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_minus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month -= std_months; + month -= months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month - std_months; + month = month - months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_month) + { + for (int m = 0; m < 256; ++m) + { + std::chrono::month std_month1(m); + std::chrono::month std_month2(255 - m); + + std::chrono::month month1(m); + std::chrono::month month2(255 - m); + + auto std_months12 = std_month1 - std_month2; + auto std_months21 = std_month2 - std_month1; + + auto months12 = month1 - month2; + auto months21 = month2 - month1; + + CHECK_EQUAL(std_months12.count(), months12.count()); + CHECK_EQUAL(std_months21.count(), months21.count()); + } + } + + //************************************************************************* + TEST(test_min_max_month) + { + CHECK_EQUAL(1U, etl::chrono::month::min()); + CHECK_EQUAL(12U, etl::chrono::month::max()); + } + + //************************************************************************* + TEST(test_literal_month) + { + using namespace etl::literals::chrono_literals; + + etl::chrono::month month1 = 1_month; + etl::chrono::month month2 = 2_month; + etl::chrono::month month3 = 3_month; + etl::chrono::month month4 = 4_month; + etl::chrono::month month5 = 5_month; + etl::chrono::month month6 = 6_month; + etl::chrono::month month7 = 7_month; + etl::chrono::month month8 = 8_month; + etl::chrono::month month9 = 9_month; + etl::chrono::month month10 = 10_month; + etl::chrono::month month11 = 11_month; + etl::chrono::month month12 = 12_month; + + CHECK_TRUE(month1.ok()); + CHECK_TRUE(month2.ok()); + CHECK_TRUE(month3.ok()); + CHECK_TRUE(month4.ok()); + CHECK_TRUE(month5.ok()); + CHECK_TRUE(month6.ok()); + CHECK_TRUE(month7.ok()); + CHECK_TRUE(month8.ok()); + CHECK_TRUE(month9.ok()); + CHECK_TRUE(month10.ok()); + CHECK_TRUE(month11.ok()); + CHECK_TRUE(month12.ok()); + + CHECK_EQUAL(1U, unsigned(month1)); + CHECK_EQUAL(2U, unsigned(month2)); + CHECK_EQUAL(3U, unsigned(month3)); + CHECK_EQUAL(4U, unsigned(month4)); + CHECK_EQUAL(5U, unsigned(month5)); + CHECK_EQUAL(6U, unsigned(month6)); + CHECK_EQUAL(7U, unsigned(month7)); + CHECK_EQUAL(8U, unsigned(month8)); + CHECK_EQUAL(9U, unsigned(month9)); + CHECK_EQUAL(10U, unsigned(month10)); + CHECK_EQUAL(11U, unsigned(month11)); + CHECK_EQUAL(12U, unsigned(month12)); + } + + //************************************************************************* + TEST(test_month_comparison_operators) + { + etl::chrono::month month1(1); + etl::chrono::month month2(2); + + CHECK_TRUE(month1 == month1); + CHECK_FALSE(month1 != month1); + CHECK_TRUE(month1 < month2); + CHECK_FALSE(month1 < month1); + CHECK_FALSE(month2 < month1); + CHECK_TRUE(month1 <= month2); + CHECK_TRUE(month1 <= month1); + CHECK_FALSE(month2 <= month1); + CHECK_FALSE(month1 > month2); + CHECK_FALSE(month1 > month1); + CHECK_TRUE(month2 > month1); + CHECK_FALSE(month1 >= month2); + CHECK_TRUE(month1 >= month1); + CHECK_TRUE(month2 >= month1); + +#if ETL_USING_CPP20 + CHECK_TRUE((month1 <=> month1) == 0); + CHECK_TRUE((month1 <=> month2) < 0); + CHECK_TRUE((month2 <=> month1) > 0); +#endif + } + + //************************************************************************* + TEST(test_month_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::month(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } + + //************************************************************************* + TEST(test_month_types) + { + CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); + CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); + CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); + CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); + CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); + CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); + CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); + CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); + CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); + CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); + CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); + CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); + } + }; +} + +#endif \ No newline at end of file diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index c4cbe05d8..132160ecc 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include @@ -262,6 +263,7 @@ namespace } } +#if ETL_USING_CPP20 //************************************************************************* TEST(test_weekday_minus_weekday) { @@ -283,6 +285,7 @@ namespace CHECK_EQUAL(std_days21.count(), days21.count()); } } +#endif //************************************************************************* TEST(test_min_max_weekday) diff --git a/test/test_chrono_weekday_indexed.cpp b/test/test_chrono_weekday_indexed.cpp index faa555969..e690fc966 100644 --- a/test/test_chrono_weekday_indexed.cpp +++ b/test/test_chrono_weekday_indexed.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include diff --git a/test/test_chrono_weekday_last.cpp b/test/test_chrono_weekday_last.cpp index 09c8f8d61..e2787a2ec 100644 --- a/test/test_chrono_weekday_last.cpp +++ b/test/test_chrono_weekday_last.cpp @@ -36,6 +36,7 @@ SOFTWARE. #include +#include #include #include diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 1ce125eb5..8c2758685 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3096,6 +3096,8 @@ + + @@ -7959,6 +7961,7 @@ + @@ -9084,6 +9087,7 @@ + true true diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 69327b6f1..1fb6e5fc0 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1449,6 +1449,12 @@ ETL\Private + + ETL\Private\chrono + + + ETL\Private\chrono + @@ -3446,6 +3452,9 @@ Tests\Misc + + Tests\Chrono + @@ -3648,6 +3657,9 @@ Tests\Syntax Checks\Source + + Tests\Test Support + diff --git a/test/vs2022/etl_solution_suppressions.cfg b/test/vs2022/etl_solution_suppressions.cfg new file mode 100644 index 000000000..f76caa4c0 --- /dev/null +++ b/test/vs2022/etl_solution_suppressions.cfg @@ -0,0 +1,4 @@ +[cppcheck] +-i*.cpp +[cppcheck_files] +[cppcheck_includes] From 5a02c061e9d4f1d3390987945385536678740690 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 18 Apr 2025 11:30:43 +0100 Subject: [PATCH 134/216] Changes merged from chrono updates --- include/etl/queue_spsc_isr.h | 4 +- include/etl/string.h | 2 +- include/etl/string_view.h | 2 +- include/etl/u16string.h | 2 +- include/etl/u32string.h | 2 +- include/etl/u8string.h | 2 +- include/etl/wstring.h | 2 +- test/.gitattributes | 1 + .../log_errors/CMakeLists.txt | 2 + test/test_chrono_month_day.cpp | 384 ++++++++++++++++++ 10 files changed, 395 insertions(+), 8 deletions(-) create mode 100644 test/.gitattributes create mode 100644 test/test_chrono_month_day.cpp diff --git a/include/etl/queue_spsc_isr.h b/include/etl/queue_spsc_isr.h index 0e9be3f19..ed1d7542d 100644 --- a/include/etl/queue_spsc_isr.h +++ b/include/etl/queue_spsc_isr.h @@ -822,8 +822,8 @@ namespace etl private: - queue_spsc_isr(const queue_spsc_isr&); - queue_spsc_isr& operator = (const queue_spsc_isr&); + queue_spsc_isr(const queue_spsc_isr&) ETL_DELETE; + queue_spsc_isr& operator = (const queue_spsc_isr&) ETL_DELETE; #if ETL_USING_CPP11 queue_spsc_isr(queue_spsc_isr&&) = delete; diff --git a/include/etl/string.h b/include/etl/string.h index 891815adf..3c74ef461 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -48,7 +48,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept + inline constexpr etl::string_view operator ""_sv(const char* str, size_t length) noexcept { return etl::string_view{ str, length }; } diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 69cbe8366..8421068e8 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -374,7 +374,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 basic_string_view substr(size_type position = 0, size_type count = npos) const { - basic_string_view view; + basic_string_view view = basic_string_view(); if (position < size()) { diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 69eb25bcd..e886a4ec7 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u16string_view operator ""_sv(const char16_t* str, size_t length) noexcept + inline constexpr etl::u16string_view operator ""_sv(const char16_t* str, size_t length) noexcept { return etl::u16string_view{ str, length }; } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 029748aa5..2ca6717c1 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u32string_view operator ""_sv(const char32_t* str, size_t length) noexcept + inline constexpr etl::u32string_view operator ""_sv(const char32_t* str, size_t length) noexcept { return etl::u32string_view{ str, length }; } diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 7510c4f67..595c45bbf 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -49,7 +49,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::u8string_view operator ""_sv(const char8_t* str, size_t length) noexcept + inline constexpr etl::u8string_view operator ""_sv(const char8_t* str, size_t length) noexcept { return etl::u8string_view{ str, length }; } diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 7107c7d8a..90325b713 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -46,7 +46,7 @@ namespace etl { inline namespace string_literals { - constexpr etl::wstring_view operator ""_sv(const wchar_t* str, size_t length) noexcept + inline constexpr etl::wstring_view operator ""_sv(const wchar_t* str, size_t length) noexcept { return etl::wstring_view{ str, length }; } diff --git a/test/.gitattributes b/test/.gitattributes new file mode 100644 index 000000000..5a97bcace --- /dev/null +++ b/test/.gitattributes @@ -0,0 +1 @@ +*.tar filter=lfs diff=lfs merge=lfs -text diff --git a/test/etl_error_handler/log_errors/CMakeLists.txt b/test/etl_error_handler/log_errors/CMakeLists.txt index 4019cf25d..b76f17bb4 100644 --- a/test/etl_error_handler/log_errors/CMakeLists.txt +++ b/test/etl_error_handler/log_errors/CMakeLists.txt @@ -67,6 +67,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") PRIVATE -fno-omit-frame-pointer -fno-common + -fno-exceptions -Wall -Wextra -Werror @@ -82,6 +83,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") PRIVATE -fno-omit-frame-pointer -fno-common + -fno-exceptions -Wall -Wextra -Werror diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp new file mode 100644 index 000000000..e1e0a5d87 --- /dev/null +++ b/test/test_chrono_month_day.cpp @@ -0,0 +1,384 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include + +#if ETL_USING_CPP20 + +namespace +{ + SUITE(test_chrono_month_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + etl::chrono::month_day md; + + CHECK_FALSE(md.ok()); + } + + //************************************************************************* + TEST(test_constructor_in_range) + { + for (unsigned i = 0U; i < 256; ++i) + { + std::chrono::month std_month(i); + etl::chrono::month month(i); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 255; ++i) + { + ++std_month; + ++month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_increment) + { + std::chrono::month std_month(0); + etl::chrono::month month(0); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month++; + etl::chrono::month last_month = month++; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_pre_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + --std_month; + --month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_post_decrement) + { + std::chrono::month std_month(255); + etl::chrono::month month(255); + + for (int i = 0; i < 256; ++i) + { + std::chrono::month std_last_month = std_month--; + etl::chrono::month last_month = month--; + + CHECK_EQUAL(std_last_month.ok(), last_month.ok()); + CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + + //************************************************************************* + TEST(test_plus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month += std_months; + month += months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_plus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month + std_months; + month = month + months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_months_plus_month) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_months + std_month; + month = months + month; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_minus_equal_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month -= std_months; + month -= months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_months) + { + for (int m = 0; m <= 12; ++m) + { + for (int ms = 0; ms <= 24; ++ms) + { + std::chrono::month std_month(m); + etl::chrono::month month(m); + + std::chrono::months std_months(ms); + etl::chrono::months months(ms); + + std_month = std_month - std_months; + month = month - months; + + CHECK_EQUAL(std_month.ok(), month.ok()); + CHECK_EQUAL(unsigned(std_month), unsigned(month)); + } + } + } + + //************************************************************************* + TEST(test_month_minus_month) + { + for (int m = 0; m < 256; ++m) + { + std::chrono::month std_month1(m); + std::chrono::month std_month2(255 - m); + + std::chrono::month month1(m); + std::chrono::month month2(255 - m); + + auto std_months12 = std_month1 - std_month2; + auto std_months21 = std_month2 - std_month1; + + auto months12 = month1 - month2; + auto months21 = month2 - month1; + + CHECK_EQUAL(std_months12.count(), months12.count()); + CHECK_EQUAL(std_months21.count(), months21.count()); + } + } + + //************************************************************************* + TEST(test_min_max_month) + { + CHECK_EQUAL(1U, etl::chrono::month::min()); + CHECK_EQUAL(12U, etl::chrono::month::max()); + } + + //************************************************************************* + TEST(test_literal_month) + { + using namespace etl::literals::chrono_literals; + + etl::chrono::month month1 = 1_month; + etl::chrono::month month2 = 2_month; + etl::chrono::month month3 = 3_month; + etl::chrono::month month4 = 4_month; + etl::chrono::month month5 = 5_month; + etl::chrono::month month6 = 6_month; + etl::chrono::month month7 = 7_month; + etl::chrono::month month8 = 8_month; + etl::chrono::month month9 = 9_month; + etl::chrono::month month10 = 10_month; + etl::chrono::month month11 = 11_month; + etl::chrono::month month12 = 12_month; + + CHECK_TRUE(month1.ok()); + CHECK_TRUE(month2.ok()); + CHECK_TRUE(month3.ok()); + CHECK_TRUE(month4.ok()); + CHECK_TRUE(month5.ok()); + CHECK_TRUE(month6.ok()); + CHECK_TRUE(month7.ok()); + CHECK_TRUE(month8.ok()); + CHECK_TRUE(month9.ok()); + CHECK_TRUE(month10.ok()); + CHECK_TRUE(month11.ok()); + CHECK_TRUE(month12.ok()); + + CHECK_EQUAL(1U, unsigned(month1)); + CHECK_EQUAL(2U, unsigned(month2)); + CHECK_EQUAL(3U, unsigned(month3)); + CHECK_EQUAL(4U, unsigned(month4)); + CHECK_EQUAL(5U, unsigned(month5)); + CHECK_EQUAL(6U, unsigned(month6)); + CHECK_EQUAL(7U, unsigned(month7)); + CHECK_EQUAL(8U, unsigned(month8)); + CHECK_EQUAL(9U, unsigned(month9)); + CHECK_EQUAL(10U, unsigned(month10)); + CHECK_EQUAL(11U, unsigned(month11)); + CHECK_EQUAL(12U, unsigned(month12)); + } + + //************************************************************************* + TEST(test_month_comparison_operators) + { + etl::chrono::month month1(1); + etl::chrono::month month2(2); + + CHECK_TRUE(month1 == month1); + CHECK_FALSE(month1 != month1); + CHECK_TRUE(month1 < month2); + CHECK_FALSE(month1 < month1); + CHECK_FALSE(month2 < month1); + CHECK_TRUE(month1 <= month2); + CHECK_TRUE(month1 <= month1); + CHECK_FALSE(month2 <= month1); + CHECK_FALSE(month1 > month2); + CHECK_FALSE(month1 > month1); + CHECK_TRUE(month2 > month1); + CHECK_FALSE(month1 >= month2); + CHECK_TRUE(month1 >= month1); + CHECK_TRUE(month2 >= month1); + +#if ETL_USING_CPP20 + CHECK_TRUE((month1 <=> month1) == 0); + CHECK_TRUE((month1 <=> month2) < 0); + CHECK_TRUE((month2 <=> month1) > 0); +#endif + } + + //************************************************************************* + TEST(test_month_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(etl::chrono::month(i))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } + + //************************************************************************* + TEST(test_month_types) + { + CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); + CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); + CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); + CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); + CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); + CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); + CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); + CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); + CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); + CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); + CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); + CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); + } + }; +} + +#endif \ No newline at end of file From a27aa2a556fc94eb7d5e122feccea01b6c45a9ab Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 20 Apr 2025 13:33:30 +0100 Subject: [PATCH 135/216] Full etl:chrono::duration implementation and unit tests --- include/etl/private/chrono/duration.h | 158 ++++++ test/test_chrono_duration.cpp | 684 ++++++++++++++++++++++++-- 2 files changed, 794 insertions(+), 48 deletions(-) diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 10c794602..3160ab181 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -185,6 +185,40 @@ namespace etl return etl::chrono::duration(etl::chrono::duration_values::max()); } + //*********************************************************************** + ETL_CONSTEXPR duration& operator ++() + { + ++value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration operator ++(int) + { + duration temp(*this); + ++value; + + return temp; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator --() + { + --value; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration operator --(int) + { + duration temp(*this); + --value; + + return temp; + } + private: TRep value; @@ -353,6 +387,130 @@ namespace etl { return !(lhs < rhs); } + + //*********************************************************************** + /// Operator + + //*********************************************************************** + template + ETL_CONSTEXPR14 typename etl::common_type, etl::chrono::duration >::type + operator +(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + // Determine the common type of the two durations. + using common_duration = typename etl::common_type, etl::chrono::duration>::type; + + // Convert both durations to the common type. + common_duration lhs_converted = etl::chrono::duration_cast(lhs); + common_duration rhs_converted = etl::chrono::duration_cast(rhs); + + // Return the sum of the two converted durations. + return common_duration(lhs_converted.count() + rhs_converted.count()); + } + + //*********************************************************************** + /// Operator - + //*********************************************************************** + template + ETL_CONSTEXPR14 typename etl::common_type, etl::chrono::duration >::type + operator -(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + // Determine the common type of the two durations. + using common_duration = typename etl::common_type, etl::chrono::duration>::type; + + // Convert both durations to the common type. + common_duration lhs_converted = etl::chrono::duration_cast(lhs); + common_duration rhs_converted = etl::chrono::duration_cast(rhs); + + // Return the sum of the two converted durations. + return common_duration(lhs_converted.count() - rhs_converted.count()); + } + + //*********************************************************************** + /// Operator * + //*********************************************************************** + template + ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> + operator *(const etl::chrono::duration& lhs, const TRep2& rhs) + { + using common_rep = typename etl::common_type::type; + using result_duration = etl::chrono::duration; + + // Multiply the count of the duration by the scalar value + return result_duration(static_cast(lhs.count()) * static_cast(rhs)); + } + + //*********************************************************************** + /// Operator * + //*********************************************************************** + template + ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod2> + operator *(const TRep1& lhs, const etl::chrono::duration& rhs) + { + using common_rep = typename etl::common_type::type; + using result_duration = etl::chrono::duration; + + // Multiply the count of the duration by the scalar value + return result_duration(static_cast(rhs.count()) * static_cast(lhs)); + } + + //*********************************************************************** + /// Operator / + //*********************************************************************** + template + ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> + operator /(const etl::chrono::duration& lhs, const TRep2& rhs) + { + using common_rep = typename etl::common_type::type; + using result_duration = etl::chrono::duration; + + // Multiply the count of the duration by the scalar value + return result_duration(static_cast(lhs.count()) / static_cast(rhs)); + } + + //*********************************************************************** + /// Operator / + //*********************************************************************** + template + ETL_CONSTEXPR14 typename etl::common_type::type + operator /(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + // Determine the common type of the two durations. + using common_duration = typename etl::common_type, etl::chrono::duration>::type; + + common_duration lhs_converted = etl::chrono::duration_cast(lhs); + common_duration rhs_converted = etl::chrono::duration_cast(rhs); + + return typename etl::common_type::type(lhs_converted.count() / rhs_converted.count()); + } + + //*********************************************************************** + /// Operator % + //*********************************************************************** + template + ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> + operator %(const etl::chrono::duration& lhs, const TRep2& rhs) + { + using common_rep = typename etl::common_type::type; + using result_duration = etl::chrono::duration; + + // Mod the count of the duration by the scalar value + return result_duration(static_cast(lhs.count()) % static_cast(rhs)); + } + + //*********************************************************************** + /// Operator % + //*********************************************************************** + template + ETL_CONSTEXPR14 typename etl::common_type::type + operator %(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + { + // Determine the common type of the two durations. + using common_duration = typename etl::common_type, etl::chrono::duration>::type; + + common_duration lhs_converted = etl::chrono::duration_cast(lhs); + common_duration rhs_converted = etl::chrono::duration_cast(rhs); + + return typename etl::common_type::type(lhs_converted.count() % rhs_converted.count()); + } } #if ETL_HAS_CHRONO_LITERALS_DURATION diff --git a/test/test_chrono_duration.cpp b/test/test_chrono_duration.cpp index f20ed3fc2..f97a606a2 100644 --- a/test/test_chrono_duration.cpp +++ b/test/test_chrono_duration.cpp @@ -38,7 +38,20 @@ SOFTWARE. #include #include #include -#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif namespace { @@ -47,7 +60,7 @@ namespace //************************************************************************* TEST(test_default_constructor) { - using duration_type = etl::chrono::duration; + using duration_type = Chrono::duration; duration_type duration; @@ -59,7 +72,7 @@ namespace //************************************************************************* TEST(test_duration_values_zero_min_max) { - using duration_values_type = etl::chrono::duration_values; + using duration_values_type = Chrono::duration_values; CHECK_EQUAL(size_t(0), duration_values_type::zero()); CHECK_EQUAL(std::numeric_limits::min(), duration_values_type::min()); @@ -69,7 +82,7 @@ namespace //************************************************************************* TEST(test_duration_zero_min_max) { - using duration_type = etl::chrono::duration; + using duration_type = Chrono::duration; CHECK_EQUAL(duration_type(0).count(), duration_type::zero().count()); CHECK_EQUAL(duration_type(std::numeric_limits::min()).count(), duration_type::min().count()); @@ -79,45 +92,45 @@ namespace //************************************************************************* TEST(test_predefined_duration_periods) { - CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::num), etl::chrono::nanoseconds::period::num); - CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::den), etl::chrono::nanoseconds::period::den); + CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::num), Chrono::nanoseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000000000U>::type::den), Chrono::nanoseconds::period::den); - CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::num), etl::chrono::microseconds::period::num); - CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::den), etl::chrono::microseconds::period::den); + CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::num), Chrono::microseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000000U>::type::den), Chrono::microseconds::period::den); - CHECK_EQUAL((etl::ratio<1U, 1000U>::type::num), etl::chrono::milliseconds::period::num); - CHECK_EQUAL((etl::ratio<1U, 1000U>::type::den), etl::chrono::milliseconds::period::den); + CHECK_EQUAL((etl::ratio<1U, 1000U>::type::num), Chrono::milliseconds::period::num); + CHECK_EQUAL((etl::ratio<1U, 1000U>::type::den), Chrono::milliseconds::period::den); - CHECK_EQUAL(etl::ratio<1U>::type::num, etl::chrono::seconds::period::num); - CHECK_EQUAL(etl::ratio<1U>::type::den, etl::chrono::seconds::period::den); + CHECK_EQUAL(etl::ratio<1U>::type::num, Chrono::seconds::period::num); + CHECK_EQUAL(etl::ratio<1U>::type::den, Chrono::seconds::period::den); - CHECK_EQUAL(etl::ratio<60U>::type::num, etl::chrono::minutes::period::num); - CHECK_EQUAL(etl::ratio<60U>::type::den, etl::chrono::minutes::period::den); + CHECK_EQUAL(etl::ratio<60U>::type::num, Chrono::minutes::period::num); + CHECK_EQUAL(etl::ratio<60U>::type::den, Chrono::minutes::period::den); - CHECK_EQUAL(etl::ratio<3600U>::type::num, etl::chrono::hours::period::num); - CHECK_EQUAL(etl::ratio<3600U>::type::den, etl::chrono::hours::period::den); + CHECK_EQUAL(etl::ratio<3600U>::type::num, Chrono::hours::period::num); + CHECK_EQUAL(etl::ratio<3600U>::type::den, Chrono::hours::period::den); - CHECK_EQUAL(etl::ratio<86400U>::type::num, etl::chrono::days::period::num); - CHECK_EQUAL(etl::ratio<86400U>::type::den, etl::chrono::days::period::den); + CHECK_EQUAL(etl::ratio<86400U>::type::num, Chrono::days::period::num); + CHECK_EQUAL(etl::ratio<86400U>::type::den, Chrono::days::period::den); - CHECK_EQUAL(etl::ratio<604800U>::type::num, etl::chrono::weeks::period::num); - CHECK_EQUAL(etl::ratio<604800U>::type::den, etl::chrono::weeks::period::den); + CHECK_EQUAL(etl::ratio<604800U>::type::num, Chrono::weeks::period::num); + CHECK_EQUAL(etl::ratio<604800U>::type::den, Chrono::weeks::period::den); - CHECK_EQUAL(etl::ratio<604800U>::type::num, etl::chrono::weeks::period::num); - CHECK_EQUAL(etl::ratio<604800U>::type::den, etl::chrono::weeks::period::den); + CHECK_EQUAL(etl::ratio<604800U>::type::num, Chrono::weeks::period::num); + CHECK_EQUAL(etl::ratio<604800U>::type::den, Chrono::weeks::period::den); - CHECK_EQUAL(etl::ratio<2629746U>::type::num, etl::chrono::months::period::num); - CHECK_EQUAL(etl::ratio<2629746U>::type::den, etl::chrono::months::period::den); + CHECK_EQUAL(etl::ratio<2629746U>::type::num, Chrono::months::period::num); + CHECK_EQUAL(etl::ratio<2629746U>::type::den, Chrono::months::period::den); - CHECK_EQUAL(etl::ratio<31556952U>::type::num, etl::chrono::years::period::num); - CHECK_EQUAL(etl::ratio<31556952U>::type::den, etl::chrono::years::period::den); + CHECK_EQUAL(etl::ratio<31556952U>::type::num, Chrono::years::period::num); + CHECK_EQUAL(etl::ratio<31556952U>::type::den, Chrono::years::period::den); } //************************************************************************* TEST(test_duration_common_type) { - using duration_type1 = etl::chrono::duration; - using duration_type2 = etl::chrono::duration; + using duration_type1 = Chrono::duration; + using duration_type2 = Chrono::duration; using duration_type = etl::common_type::type; @@ -128,11 +141,11 @@ namespace //************************************************************************* TEST(test_duration_cast_with_same_rep_and_period_for_duration_type1_and_duration_type2) { - using duration_type1 = etl::chrono::duration; - using duration_type2 = etl::chrono::duration>; + using duration_type1 = Chrono::duration; + using duration_type2 = Chrono::duration>; duration_type1 dur1(245); - duration_type2 dur2 = etl::chrono::duration_cast(dur1); + duration_type2 dur2 = Chrono::duration_cast(dur1); CHECK_EQUAL(duration_type1::period::num, duration_type2::period::num); CHECK_EQUAL(duration_type1::period::den, duration_type2::period::den); @@ -142,11 +155,11 @@ namespace //************************************************************************* TEST(test_duration_cast_where_ratio_divide_of_periods_num_is_1) { - using duration_type1 = etl::chrono::duration; - using duration_type2 = etl::chrono::duration; + using duration_type1 = Chrono::duration; + using duration_type2 = Chrono::duration; duration_type1 dur1(245000); - duration_type2 dur2 = etl::chrono::duration_cast(dur1); + duration_type2 dur2 = Chrono::duration_cast(dur1); typedef typename etl::ratio_divide::type ratio_divide_t; @@ -159,11 +172,11 @@ namespace //************************************************************************* TEST(test_duration_cast_where_ratio_divide_of_periods_den_is_1) { - using duration_type1 = etl::chrono::duration; - using duration_type2 = etl::chrono::duration; + using duration_type1 = Chrono::duration; + using duration_type2 = Chrono::duration; duration_type1 dur1(245); - duration_type2 dur2 = etl::chrono::duration_cast(dur1); + duration_type2 dur2 = Chrono::duration_cast(dur1); typedef typename etl::ratio_divide::type ratio_divide_t; @@ -176,11 +189,11 @@ namespace //************************************************************************* TEST(test_duration_cast_when_rep_and_period_are_not_equal_and_ratio_divide_of_periods_num_and_den_are_not_1) { - using duration_type1 = etl::chrono::duration>; - using duration_type2 = etl::chrono::duration>; + using duration_type1 = Chrono::duration>; + using duration_type2 = Chrono::duration>; duration_type1 dur1(245); - duration_type2 dur2 = etl::chrono::duration_cast(dur1); + duration_type2 dur2 = Chrono::duration_cast(dur1); typedef typename etl::ratio_divide::type ratio_divide_t; @@ -196,12 +209,12 @@ namespace int Two_Hours = 2; int Four_Hours = 4; - etl::chrono::hours hours1(Two_Hours); - etl::chrono::hours hours2(Four_Hours); - etl::chrono::seconds seconds(0); + Chrono::hours hours1(Two_Hours); + Chrono::hours hours2(Four_Hours); + Chrono::seconds seconds(0); seconds = hours1; - int seconds_per_hour = etl::chrono::hours::period::num / etl::chrono::seconds::period::num; + int seconds_per_hour = Chrono::hours::period::num / Chrono::seconds::period::num; CHECK_EQUAL(seconds.count(), hours1.count() * seconds_per_hour); CHECK_EQUAL(Two_Hours, hours1.count()); @@ -213,8 +226,8 @@ namespace //************************************************************************* TEST(test_duration_comparison_operators) { - using duration_type1 = etl::chrono::duration; - using duration_type2 = etl::chrono::duration; + using duration_type1 = Chrono::duration; + using duration_type2 = Chrono::duration; duration_type1 dur1a(245); duration_type1 dur1b(245); @@ -267,7 +280,7 @@ namespace //************************************************************************* TEST(test_duration_unary_operators) { - using duration_type = etl::chrono::duration; + using duration_type = Chrono::duration; duration_type dur(245); @@ -281,7 +294,7 @@ namespace //************************************************************************* TEST(test_duration_hashes_are_unique) { - using duration_type = etl::chrono::duration; + using duration_type = Chrono::duration; std::vector hashes; @@ -294,5 +307,580 @@ namespace (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } + + //************************************************************************* + TEST(test_duration_pre_increment) + { + Chrono::hours hours(0); + Chrono::minutes minutes(0); + Chrono::seconds seconds(0); + + for (int i = 1; i < 100; ++i) + { + ++hours; + ++minutes; + ++seconds; + + CHECK_EQUAL(i, hours.count()); + CHECK_EQUAL(i, minutes.count()); + CHECK_EQUAL(i, seconds.count()); + } + } + + //************************************************************************* + TEST(test_duration_post_increment) + { + Chrono::hours hours(0); + Chrono::minutes minutes(0); + Chrono::seconds seconds(0); + + for (int i = 1; i < 100; ++i) + { + Chrono::hours last_hours = hours++; + Chrono::minutes last_minutes = minutes++; + Chrono::seconds last_seconds = seconds++; + + CHECK_EQUAL(i - 1, last_hours.count()); + CHECK_EQUAL(i - 1, last_minutes.count()); + CHECK_EQUAL(i - 1, last_seconds.count()); + + CHECK_EQUAL(i, hours.count()); + CHECK_EQUAL(i, minutes.count()); + CHECK_EQUAL(i, seconds.count()); + } + } + + //************************************************************************* + TEST(test_duration_pre_decrement) + { + Chrono::hours hours(101); + Chrono::minutes minutes(101); + Chrono::seconds seconds(101); + + for (int i = 100; i > 0; --i) + { + --hours; + --minutes; + --seconds; + + CHECK_EQUAL(i, hours.count()); + CHECK_EQUAL(i, minutes.count()); + CHECK_EQUAL(i, seconds.count()); + } + } + + //************************************************************************* + TEST(test_duration_post_decrement) + { + Chrono::hours hours(101); + Chrono::minutes minutes(101); + Chrono::seconds seconds(101); + + for (int i = 100; i > 0; --i) + { + Chrono::hours last_hours = hours--; + Chrono::minutes last_minutes = minutes--; + Chrono::seconds last_seconds = seconds--; + + CHECK_EQUAL(i + 1, last_hours.count()); + CHECK_EQUAL(i + 1, last_minutes.count()); + CHECK_EQUAL(i + 1, last_seconds.count()); + + CHECK_EQUAL(i, hours.count()); + CHECK_EQUAL(i, minutes.count()); + CHECK_EQUAL(i, seconds.count()); + } + } + + //************************************************************************* + TEST(test_addition_same_type) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(20); // 20 seconds + + auto result = s1 + s2; + + CHECK_EQUAL(30, result.count()); // 10 + 20 = 30 seconds + } + + //************************************************************************* + TEST(test_addition_different_types) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::milliseconds ms1(500); // 500 milliseconds + + auto result = s1 + ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(10500, result.count()); // 10 seconds + 500 milliseconds = 10500 milliseconds + } + + //************************************************************************* + TEST(test_addition_with_zero) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(0); // 0 seconds + + auto result = s1 + s2; + + CHECK_EQUAL(10, result.count()); // 10 + 0 = 10 seconds + } + + //************************************************************************* + TEST(test_addition_negative_duration) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(-5); // -5 seconds + + auto result = s1 + s2; + + CHECK_EQUAL(5, result.count()); // 10 + (-5) = 5 seconds + } + + //************************************************************************* + TEST(test_addition_large_values) + { + Chrono::seconds s1(1000000); // 1,000,000 seconds + Chrono::milliseconds ms1(500000); // 500,000 milliseconds + + auto result = s1 + ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(1000500000, result.count()); // 1,000,000 seconds + 500,000 milliseconds = 1,000,500,000 milliseconds + } + + //************************************************************************* + TEST(test_subtraction_same_type) + { + Chrono::seconds s1(20); // 20 seconds + Chrono::seconds s2(10); // 10 seconds + + auto result = s1 - s2; + + CHECK_EQUAL(10, result.count()); // 20 - 10 = 10 seconds + } + + //************************************************************************* + TEST(test_subtraction_different_types) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::milliseconds ms1(500); // 500 milliseconds + + auto result = s1 - ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(9500, result.count()); // 10 seconds - 500 milliseconds = 9500 milliseconds + } + + //************************************************************************* + TEST(test_subtraction_with_zero) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(0); // 0 seconds + + auto result = s1 - s2; + + CHECK_EQUAL(10, result.count()); // 10 - 0 = 10 seconds + } + + //************************************************************************* + TEST(test_subtraction_negative_duration) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(-5); // -5 seconds + + auto result = s1 - s2; + + CHECK_EQUAL(15, result.count()); // 10 - (-5) = 15 seconds + } + + //************************************************************************* + TEST(test_subtraction_large_values) + { + Chrono::seconds s1(1000000); // 1,000,000 seconds + Chrono::milliseconds ms1(500000); // 500,000 milliseconds + + auto result = s1 - ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(999500000, result.count()); // 1,000,000 seconds - 500,000 milliseconds = 999,500,000 milliseconds + } + + //************************************************************************* + TEST(test_subtraction_resulting_in_negative) + { + Chrono::seconds s1(5); // 5 seconds + Chrono::seconds s2(10); // 10 seconds + + auto result = s1 - s2; + + CHECK_EQUAL(-5, result.count()); // 5 - 10 = -5 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_positive_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 5; // Scalar value + + auto result = s1 * scalar; + + CHECK_EQUAL(50, result.count()); // 10 * 5 = 50 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_negative_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = -3; // Negative scalar value + + auto result = s1 * scalar; + + CHECK_EQUAL(-30, result.count()); // 10 * (-3) = -30 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_zero_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 0; // Scalar value + + auto result = s1 * scalar; + + CHECK_EQUAL(0, result.count()); // 10 * 0 = 0 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_large_scalar_duration_scalar) + { + etl::chrono::seconds s1(1000); // 1,000 seconds + int scalar = 1000000; // Large scalar value + + auto result = s1 * scalar; + + CHECK_EQUAL(1000000000, result.count()); // 1,000 * 1,000,000 = 1,000,000,000 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_floating_point_scalar_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + double scalar = 2.5; // Floating-point scalar value + + auto result = s1 * scalar; + + CHECK_EQUAL(25, result.count()); // 10 * 2.5 = 25 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_different_representation_duration_scalar) + { + etl::chrono::milliseconds ms1(500); // 500 milliseconds + int scalar = 3; // Scalar value + + auto result = ms1 * scalar; + + CHECK_EQUAL(1500, result.count()); // 500 * 3 = 1,500 milliseconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_positive_scalar_duration) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 5; // Scalar value + + auto result = scalar * s1; + + CHECK_EQUAL(50, result.count()); // 10 * 5 = 50 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_negative_scalar_duration) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = -3; // Negative scalar value + + auto result = scalar * s1; + + CHECK_EQUAL(-30, result.count()); // 10 * (-3) = -30 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_scalar_zero_scalar_duration) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 0; // Scalar value + + auto result = scalar * s1; + + CHECK_EQUAL(0, result.count()); // 10 * 0 = 0 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_large_scalar_scalar_duration) + { + etl::chrono::seconds s1(1000); // 1,000 seconds + int scalar = 1000000; // Large scalar value + + auto result = scalar * s1; + + CHECK_EQUAL(1000000000, result.count()); // 1,000 * 1,000,000 = 1,000,000,000 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_floating_point_scalar_scalar_duration) + { + etl::chrono::seconds s1(10); // 10 seconds + double scalar = 2.5; // Floating-point scalar value + + auto result = scalar * s1; + + CHECK_EQUAL(25, result.count()); // 10 * 2.5 = 25 seconds + } + + //************************************************************************* + TEST(test_multiplication_with_different_representation_scalar_duration) + { + etl::chrono::milliseconds ms1(500); // 500 milliseconds + int scalar = 3; // Scalar value + + auto result = scalar * ms1; + + CHECK_EQUAL(1500, result.count()); // 500 * 3 = 1,500 milliseconds + } + + //************************************************************************* + TEST(test_division_with_scalar_positive_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 5; // Scalar value + + auto result = s1 / scalar; + + CHECK_EQUAL(2, result.count()); // 10 / 5 = 2 seconds + } + + //************************************************************************* + TEST(test_division_with_scalar_negative_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = -2; // Negative scalar value + + auto result = s1 / scalar; + + CHECK_EQUAL(-5, result.count()); // 10 / (-2) = -5 seconds + } + + //************************************************************************* + TEST(test_division_with_large_scalar_duration_scalar) + { + etl::chrono::seconds s1(10000000); // 10,000,000 seconds + int scalar = 1000000; // Large scalar value + + auto result = s1 / scalar; + + CHECK_EQUAL(10, result.count()); // 10,000,000 / 1,000,000 = 10 seconds + } + + //************************************************************************* + TEST(test_division_with_floating_point_scalar_duration_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + double scalar = 2.5; // Floating-point scalar value + + auto result = s1 / scalar; + + CHECK_EQUAL(4, result.count()); // 10 / 2.5 = 4 seconds + } + + //************************************************************************* + TEST(test_division_with_different_representation_duration_scalar) + { + etl::chrono::milliseconds ms1(500); // 500 milliseconds + int scalar = 2; // Scalar value + + auto result = ms1 / scalar; + + CHECK_EQUAL(250, result.count()); // 500 / 2 = 250 milliseconds + } + + //************************************************************************* + TEST(test_division_same_type) + { + etl::chrono::seconds s1(20); // 20 seconds + etl::chrono::seconds s2(10); // 10 seconds + + auto result = s1 / s2; + + CHECK_EQUAL(2, result); // 20 / 10 = 2 + } + + //************************************************************************* + TEST(test_division_different_types) + { + etl::chrono::seconds s1(10); // 10 seconds + etl::chrono::milliseconds ms1(500); // 500 milliseconds + + auto result = s1 / ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(20, result); // 10 seconds / 500 milliseconds = 20 + } + + //************************************************************************* + TEST(test_division_with_large_values) + { + etl::chrono::seconds s1(1000000); // 1,000,000 seconds + etl::chrono::milliseconds ms1(500000); // 500,000 milliseconds + + auto result = s1 / ms1; + + CHECK_EQUAL(2000, result); // 1,000,000 seconds / 500,000 milliseconds = 2000 + } + + //************************************************************************* + TEST(test_division_resulting_in_fraction) + { + etl::chrono::seconds s1(7); // 7 seconds + etl::chrono::seconds s2(3); // 3 seconds + + auto result = s1 / s2; + + CHECK_EQUAL(2, result); // 7 / 3 = 2 (integer division) + } + + //************************************************************************* + TEST(test_division_by_larger_duration) + { + etl::chrono::seconds s1(5); // 5 seconds + etl::chrono::seconds s2(10); // 10 seconds + + auto result = s1 / s2; + + CHECK_EQUAL(0, result); // 5 / 10 = 0 (integer division) + } + + //************************************************************************* + TEST(test_division_by_one) + { + etl::chrono::seconds s1(10); // 10 seconds + etl::chrono::seconds s2(1); // 1 second + + auto result = s1 / s2; + + CHECK_EQUAL(10, result); // 10 / 1 = 10 + } + + //************************************************************************* + TEST(test_modulus_with_positive_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 3; // Scalar value + + auto result = s1 % scalar; + + CHECK_EQUAL(1, result.count()); // 10 % 3 = 1 second + } + + //************************************************************************* + TEST(test_modulus_with_negative_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = -3; // Negative scalar value + + auto result = s1 % scalar; + + CHECK_EQUAL(1, result.count()); // 10 % -3 = 1 second (modulus result is positive) + } + + //************************************************************************* + TEST(test_modulus_with_large_scalar) + { + etl::chrono::seconds s1(10); // 10 seconds + int scalar = 100; // Scalar value larger than duration + + auto result = s1 % scalar; + + CHECK_EQUAL(10, result.count()); // 10 % 100 = 10 seconds + } + + //************************************************************************* + TEST(test_modulus_with_different_representation) + { + etl::chrono::milliseconds ms1(1050); // 1050 milliseconds + int scalar = 500; // Scalar value + + auto result = ms1 % scalar; + + CHECK_EQUAL(50, result.count()); // 1050 % 500 = 50 milliseconds + } + + //************************************************************************* + TEST(test_modulus_same_type) + { + etl::chrono::seconds s1(10); // 10 seconds + etl::chrono::seconds s2(3); // 3 seconds + + auto result = s1 % s2; + + CHECK_EQUAL(1, result); // 10 % 3 = 1 second + } + + //************************************************************************* + TEST(test_modulus_different_types) + { + etl::chrono::seconds s1(10); // 10 seconds + etl::chrono::milliseconds ms1(3000); // 3000 milliseconds + + auto result = s1 % ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(1000, result); // 10 seconds % 3000 milliseconds = 1000 milliseconds + } + + //************************************************************************* + TEST(test_modulus_with_large_values) + { + etl::chrono::seconds s1(1000000); // 1,000,000 seconds + etl::chrono::milliseconds ms1(500000); // 500,000 milliseconds + + auto result = s1 % ms1; + + CHECK_EQUAL(0, result); // 1,000,000 seconds % 500,000 milliseconds = 0 + } + + //************************************************************************* + TEST(test_modulus_resulting_in_fraction) + { + etl::chrono::seconds s1(7); // 7 seconds + etl::chrono::seconds s2(3); // 3 seconds + + auto result = s1 % s2; + + CHECK_EQUAL(1, result); // 7 % 3 = 1 second + } + + //************************************************************************* + TEST(test_modulus_by_larger_duration) + { + etl::chrono::seconds s1(5); // 5 seconds + etl::chrono::seconds s2(10); // 10 seconds + + auto result = s1 % s2; + + CHECK_EQUAL(5, result); // 5 % 10 = 5 seconds + } + + //************************************************************************* + TEST(test_modulus_with_different_periods) + { + etl::chrono::seconds s1(10); // 10 seconds + etl::chrono::milliseconds ms1(2500); // 2500 milliseconds + + auto result = s1 % ms1; + + // Result should be in the common type (milliseconds) + CHECK_EQUAL(0, result); // 10 seconds % 2500 milliseconds = 0 milliseconds + } }; } From ee748eb6cb3f602f9fb8f8253fc7131f925618bc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Apr 2025 20:16:52 +0100 Subject: [PATCH 136/216] Updates to chrono classes --- include/etl/chrono.h | 3 +- include/etl/private/chrono/day.h | 14 + include/etl/private/chrono/duration.h | 85 ++++ include/etl/private/chrono/month.h | 93 ++++ include/etl/private/chrono/month_day.h | 84 +++- include/etl/private/chrono/month_weekday.h | 211 ++++++++ include/etl/private/chrono/weekday.h | 261 +++++++--- include/etl/private/chrono/weekday_indexed.h | 153 ------ include/etl/private/chrono/weekday_last.h | 115 ----- include/etl/private/chrono/year.h | 15 +- test/test_chrono_day.cpp | 15 +- test/test_chrono_duration.cpp | 246 ++++++++-- test/test_chrono_month.cpp | 13 + test/test_chrono_month_day.cpp | 492 +++++++------------ test/test_chrono_month_day_last.cpp | 130 +++++ test/test_chrono_month_weekday.cpp | 126 +++++ test/test_chrono_month_weekday_last.cpp | 125 +++++ test/test_chrono_weekday.cpp | 154 +++--- test/test_chrono_weekday_indexed.cpp | 87 ++-- test/test_chrono_weekday_last.cpp | 68 +-- test/test_chrono_year.cpp | 162 +++--- test/vs2022/etl.vcxproj | 6 +- test/vs2022/etl.vcxproj.filters | 18 +- 23 files changed, 1754 insertions(+), 922 deletions(-) create mode 100644 include/etl/private/chrono/month_weekday.h delete mode 100644 include/etl/private/chrono/weekday_indexed.h delete mode 100644 include/etl/private/chrono/weekday_last.h create mode 100644 test/test_chrono_month_day_last.cpp create mode 100644 test/test_chrono_month_weekday.cpp create mode 100644 test/test_chrono_month_weekday_last.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 8789d6561..0c35a8878 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -46,10 +46,9 @@ SOFTWARE. #include "private/chrono/duration.h" #include "private/chrono/day.h" #include "private/chrono/weekday.h" -#include "private/chrono/weekday_indexed.h" -#include "private/chrono/weekday_last.h" #include "private/chrono/month.h" #include "private/chrono/month_day.h" +#include "private/chrono/month_weekday.h" #include "private/chrono/year.h" #include "private/chrono/operators.h" #endif diff --git a/include/etl/private/chrono/day.h b/include/etl/private/chrono/day.h index a3459658b..192a5ccce 100644 --- a/include/etl/private/chrono/day.h +++ b/include/etl/private/chrono/day.h @@ -163,6 +163,20 @@ namespace etl return static_cast(value); } + //*********************************************************************** + /// Compare day with another. + /// if day < other, returns -1; + /// else if day > other, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const day& other) const ETL_NOEXCEPT + { + if (value < other.value) return -1; + if (value > other.value) return 1; + + return 0; + } + //*********************************************************************** /// The minimum day value for which ok() will return true //*********************************************************************** diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 3160ab181..df6ee9839 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -219,6 +219,75 @@ namespace etl return temp; } + //*********************************************************************** + ETL_CONSTEXPR duration& operator +=(const duration& d) + { + value += d.count(); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator -=(const duration& d) + { + value -= d.count(); + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator *=(const TRep& r) + { + value *= r; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator /=(const TRep& r) + { + value /= r; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator %=(const TRep& r) + { + value %= r; + + return *this; + } + + //*********************************************************************** + ETL_CONSTEXPR duration& operator %=(const duration& d) + { + value %= d.count(); + + return *this; + } + + //*********************************************************************** + /// Compare duration with another. + /// if duration < other, returns -1; + /// else if duration > other, returns 1; + /// else returns 0; + //*********************************************************************** + template + ETL_CONSTEXPR14 int compare(const duration& other) const ETL_NOEXCEPT + { + // Determine the common type of the two durations. + using common_duration = typename etl::common_type, etl::chrono::duration>::type; + + common_duration lhs_converted = etl::chrono::duration_cast(*this); + common_duration rhs_converted = etl::chrono::duration_cast(other); + + if (lhs_converted.count() < rhs_converted.count()) return -1; + if (lhs_converted.count() > rhs_converted.count()) return 1; + + return 0; + } + private: TRep value; @@ -388,6 +457,22 @@ namespace etl return !(lhs < rhs); } + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + template + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) noexcept + { + typedef typename etl::common_type, etl::chrono::duration >::type common_t; + + common_t l = etl::chrono::duration_cast(lhs); + common_t r = etl::chrono::duration_cast(rhs); + + return (l.count() <=> r.count()); + } +#endif + //*********************************************************************** /// Operator + //*********************************************************************** diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 6c3d05cc9..1359c5557 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -155,6 +155,20 @@ namespace etl return (value >= 1U) && (value <= 12U); } + //*********************************************************************** + /// Compare month with another. + /// if month < other, returns -1; + /// else if month > other, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const month& other) const ETL_NOEXCEPT + { + if (value < other.value) return -1; + if (value > other.value) return 1; + + return 0; + } + //*********************************************************************** /// The minimum month value for which ok() will return true //*********************************************************************** @@ -342,6 +356,68 @@ namespace etl static ETL_CONSTANT etl::chrono::month November{ 11 }; static ETL_CONSTANT etl::chrono::month December{ 12 }; #endif + + //************************************************************************* + /// month_day_last + //************************************************************************* + class month_day_last + { + public: + + //************************************************************************* + /// Construct from month. + //************************************************************************* + ETL_CONSTEXPR explicit month_day_last(const etl::chrono::month& m_) ETL_NOEXCEPT + : m(m_) + { + } + + //************************************************************************* + /// Get the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Is the contained month OK? + //************************************************************************* + bool ok() const ETL_NOEXCEPT + { + return m.ok(); + } + + private: + + etl::chrono::month m; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT + { + return (static_cast(mdl1.month()) == static_cast(mdl2.month())); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) ETL_NOEXCEPT + { + return !(mdl1 == mdl2); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month_day_last& mdl1, const etl::chrono::month_day_last& mdl2) noexcept + { + return (static_cast(mdl1.month()) <=> static_cast(mdl2.month())); + } +#endif } //************************************************************************* @@ -360,6 +436,23 @@ namespace etl } }; #endif + + //************************************************************************* + /// Hash function for etl::chrono::month_day_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_day_last& mdl) const + { + unsigned value = (unsigned)mdl.month(); + const uint8_t* p = reinterpret_cast(&value); + + return etl::private_hash::generic_hash(p, p + sizeof(unsigned)); + } + }; +#endif } #if ETL_HAS_CHRONO_LITERALS_MONTH diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h index fbcb03bc2..e58f62f0a 100644 --- a/include/etl/private/chrono/month_day.h +++ b/include/etl/private/chrono/month_day.h @@ -96,7 +96,7 @@ namespace etl } //************************************************************************* - /// Returns true if the two instances are equal. + /// Equality operator. //************************************************************************* friend ETL_CONSTEXPR bool operator ==(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT @@ -104,6 +104,66 @@ namespace etl return (lhs.d == rhs.d) && (lhs.m == rhs.m); } + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// Less-than operator. + //************************************************************************* + friend ETL_NODISCARD ETL_CONSTEXPR + bool operator <(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + if (lhs.month() < rhs.month()) + { + return true; + } + else if (lhs.month() == rhs.month()) + { + return lhs.day() < rhs.day(); + } + else + { + return false; + } + } + + //************************************************************************* + /// Less-than-equal operator. + //************************************************************************* + friend ETL_NODISCARD ETL_CONSTEXPR + bool operator <=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(rhs < lhs); + } + + //************************************************************************* + /// Greater-than operator. + //************************************************************************* + friend ETL_NODISCARD ETL_CONSTEXPR + bool operator >(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return rhs < lhs; + } + + //************************************************************************* + /// Greater-than-equal operator. + //************************************************************************* + friend ETL_NODISCARD ETL_CONSTEXPR + bool operator >=(const etl::chrono::month_day& lhs, + const etl::chrono::month_day& rhs) ETL_NOEXCEPT + { + return !(lhs < rhs); + } + //*********************************************************************** /// Spaceship operator //*********************************************************************** @@ -111,7 +171,7 @@ namespace etl friend [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) noexcept { - auto cmp = lhs.m <=> rhs.m; + auto cmp = lhs.month() <=> rhs.month(); if (cmp != 0) { @@ -119,11 +179,29 @@ namespace etl } else { - return lhs.d <=> rhs.d; + return lhs.day() <=> rhs.day(); } } #endif + //*********************************************************************** + /// Compare month_day with another. + /// if month < other.month, returns -1; + /// else if month > other.month, returns 1; + /// else if day < other.day, returns -1; + /// else if day > other.day, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const month_day& other) const ETL_NOEXCEPT + { + if (m < other.m) return -1; + if (m > other.m) return 1; + if (d < other.d) return -1; + if (d > other.d) return 1; + + return 0; + } + private: etl::chrono::month m; diff --git a/include/etl/private/chrono/month_weekday.h b/include/etl/private/chrono/month_weekday.h new file mode 100644 index 000000000..e1f99d95f --- /dev/null +++ b/include/etl/private/chrono/month_weekday.h @@ -0,0 +1,211 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + class month_weekday + { + public: + + //************************************************************************* + /// Construct from month and weekday_indexed. + //************************************************************************* + ETL_CONSTEXPR month_weekday(const etl::chrono::month& m_, const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT + : m(m_) + , wdi(wdi_) + { + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the weekday_indexed. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT + { + return wdi; + } + + //************************************************************************* + /// Returns true if the month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + return m.ok() && wdi.ok(); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::month_weekday& lhs, + const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT + { + return (lhs.m == rhs.m) && (lhs.wdi == rhs.wdi); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::month_weekday& lhs, + const etl::chrono::month_weekday& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + private: + + etl::chrono::month m; + etl::chrono::weekday_indexed wdi; + }; + + //************************************************************************* + /// Construct from month and weekday_last. + //************************************************************************* + class month_weekday_last + { + public: + + //************************************************************************* + /// Construct from month and weekday_indexed. + //************************************************************************* + ETL_CONSTEXPR month_weekday_last(const etl::chrono::month& m_, const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT + : m(m_) + , wdl(wdl_) + { + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the weekday_indexed. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT + { + return wdl; + } + + //************************************************************************* + /// Returns true if the month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + return m.ok() && wdl.ok(); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::month_weekday_last& lhs, + const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT + { + return (lhs.m == rhs.m) && (lhs.wdl == rhs.wdl); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::month_weekday_last& lhs, + const etl::chrono::month_weekday_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + private: + + etl::chrono::month m; + etl::chrono::weekday_last wdl; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::month_weekday + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_weekday& mw) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int a = mw.month(); + unsigned int b = mw.weekday_indexed().weekday().c_encoding(); + unsigned int c = mw.weekday_indexed().index(); + + memcpy(buffer, &a, sizeof(a)); + memcpy(buffer + sizeof(a), &b, sizeof(b)); + memcpy(buffer + sizeof(b), &b, sizeof(c)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif + + //************************************************************************* + /// Hash function for etl::chrono::month_weekday_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::month_weekday_last& mw) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int a = mw.month(); + unsigned int b = mw.weekday_last().weekday().c_encoding(); + + memcpy(buffer, &a, sizeof(a)); + memcpy(buffer + sizeof(a), &b, sizeof(b)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index d294d9c8b..e434ef565 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -160,18 +160,20 @@ namespace etl //*********************************************************************** /// The minimum weekday value for which ok() will return true + /// C encoding. //*********************************************************************** - static ETL_CONSTEXPR etl::chrono::weekday min() ETL_NOEXCEPT + static ETL_CONSTEXPR unsigned min() ETL_NOEXCEPT { - return etl::chrono::weekday(0); + return 0; } //*********************************************************************** /// The maximum weekday value for which ok() will return true + /// C encoding. //*********************************************************************** - static ETL_CONSTEXPR etl::chrono::weekday max() ETL_NOEXCEPT + static ETL_CONSTEXPR unsigned max() ETL_NOEXCEPT { - return etl::chrono::weekday(6); + return 6; } //*********************************************************************** @@ -198,7 +200,7 @@ namespace etl //*********************************************************************** /// Index operator from etl::chrono::last_spec //*********************************************************************** - ETL_CONSTEXPR etl::chrono::weekday_last operator[](etl::chrono::last_spec) const ETL_NOEXCEPT; + ETL_CONSTEXPR etl::chrono::weekday_last operator[](etl::chrono::last_spec last) const ETL_NOEXCEPT; //*********************************************************************** /// Returns true if the day is a weekend. @@ -210,14 +212,7 @@ namespace etl private: - //*********************************************************************** - /// Normalise to a in-range weekday - //*********************************************************************** - ETL_CONSTEXPR void normalise() ETL_NOEXCEPT - { - value %= 7U; - } - + // The weekday value in C encoding. unsigned char value; }; @@ -237,48 +232,6 @@ namespace etl return !(wd1 == wd2); } - //*********************************************************************** - /// Less-than operator - //*********************************************************************** - ETL_CONSTEXPR bool operator <(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT - { - return (wd1.c_encoding() < wd2.c_encoding()); - } - - //*********************************************************************** - /// Less-than-or-equal operator - //*********************************************************************** - ETL_CONSTEXPR bool operator <=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT - { - return (wd1.c_encoding() <= wd2.c_encoding()); - } - - //*********************************************************************** - /// Greater-than operator - //*********************************************************************** - ETL_CONSTEXPR bool operator >(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT - { - return (wd1.c_encoding() > wd2.c_encoding()); - } - - //*********************************************************************** - /// Greater-than-or-equal operator - //*********************************************************************** - ETL_CONSTEXPR bool operator >=(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) ETL_NOEXCEPT - { - return (wd1.c_encoding() >= wd2.c_encoding()); - } - - //*********************************************************************** - /// Spaceship operator - //*********************************************************************** -#if ETL_USING_CPP20 - [[nodiscard]] constexpr auto operator <=>(const etl::chrono::weekday& wd1, const etl::chrono::weekday& wd2) noexcept - { - return (wd1.c_encoding() <=> wd2.c_encoding()); - } -#endif - //*********************************************************************** /// Add etl::chrono::days to etl::chrono::weekday ///\return etl::chrono::weekday @@ -349,6 +302,176 @@ namespace etl static ETL_CONSTANT etl::chrono::weekday Friday{ 5U }; static ETL_CONSTANT etl::chrono::weekday Saturday{ 6U }; #endif + + //*********************************************************************** + /// weekday_indexed + //*********************************************************************** + class weekday_indexed + { + public: + + //*********************************************************************** + /// Default constructor + //*********************************************************************** + ETL_CONSTEXPR weekday_indexed() ETL_NOEXCEPT + : wd() + , i() + { + } + + //*********************************************************************** + /// Construct from weekday and index + //*********************************************************************** + ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday& wd_, unsigned index_) ETL_NOEXCEPT + : wd(wd_) + , i(static_cast(index_)) + { + } + + //*********************************************************************** + /// Copy constructor + //*********************************************************************** + ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday_indexed& other) ETL_NOEXCEPT + : wd(other.wd) + , i(other.i) + { + } + + //*********************************************************************** + /// Assignment operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::weekday_indexed& operator =(const etl::chrono::weekday_indexed& rhs) ETL_NOEXCEPT + { + wd = rhs.wd; + i = rhs.i; + + return *this; + } + + //*********************************************************************** + /// Get weekday + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT + { + return wd; + } + + //*********************************************************************** + /// Get index + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR unsigned index() const ETL_NOEXCEPT + { + return i; + } + + //*********************************************************************** + /// Returns true if the weekday and index are valid + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return wd.ok() && (i >= 1U) && (i <= 5U); + } + + private: + + etl::chrono::weekday wd; + uint_least8_t i; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT + { + return (wd1.weekday() == wd2.weekday()) && + (wd1.index() == wd2.index()); + } + + //*********************************************************************** + /// Inequality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT + { + return !(wd1 == wd2); + } + + //*********************************************************************** + /// weekday_last + //*********************************************************************** + class weekday_last + { + public: + + //*********************************************************************** + /// Construct from unsigned + //*********************************************************************** + ETL_CONSTEXPR explicit weekday_last(const etl::chrono::weekday& wd_) ETL_NOEXCEPT + : wd(wd_) + { + } + + //*********************************************************************** + /// Copy constructor + //*********************************************************************** + ETL_CONSTEXPR weekday_last(const etl::chrono::weekday_last& other) ETL_NOEXCEPT + : wd(other.wd) + { + } + + //*********************************************************************** + /// Assignment operator + //*********************************************************************** + ETL_CONSTEXPR14 etl::chrono::weekday_last& operator =(const etl::chrono::weekday_last& rhs) ETL_NOEXCEPT + { + wd = rhs.wd; + + return *this; + } + + //*********************************************************************** + /// Get weekday + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT + { + return wd; + } + + //*********************************************************************** + /// Returns true if the weekday is valid + //*********************************************************************** + ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT + { + return wd.ok(); + } + + private: + + etl::chrono::weekday wd; + }; + + //*********************************************************************** + /// Equality operator + //*********************************************************************** + ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_last& wd1, const etl::chrono::weekday_last& wd2) ETL_NOEXCEPT + { + return (wd1.weekday() == wd2.weekday()); + } + + //*********************************************************************** + /// weekday index operator from index + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday_indexed etl::chrono::weekday::operator[](unsigned index) const ETL_NOEXCEPT + { + return etl::chrono::weekday_indexed(*this, index); + } + + //*********************************************************************** + /// Index operator from etl::chrono::last_spec + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::weekday_last etl::chrono::weekday::operator[](etl::chrono::last_spec last) const ETL_NOEXCEPT + { + return etl::chrono::weekday_last(*this); + } } //************************************************************************* @@ -367,6 +490,34 @@ namespace etl } }; #endif + + //************************************************************************* + /// Hash function for etl::chrono::weekday_indexed + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::weekday_indexed& wdi) const + { + return etl::hash()(wdi.weekday()) ^ etl::hash()(wdi.index()); + } + }; +#endif + + //************************************************************************* + /// Hash function for etl::chrono::weekday_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::weekday_last& wdl) const + { + return etl::hash()(wdl.weekday()); + } + }; +#endif } #if ETL_HAS_CHRONO_LITERALS_WEEKDAY diff --git a/include/etl/private/chrono/weekday_indexed.h b/include/etl/private/chrono/weekday_indexed.h deleted file mode 100644 index 46bc2354e..000000000 --- a/include/etl/private/chrono/weekday_indexed.h +++ /dev/null @@ -1,153 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2023 John Wellbelove - -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_IN_CHRONO_H - #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H -#endif - -namespace etl -{ - namespace chrono - { - //*********************************************************************** - /// weekday_indexed - //*********************************************************************** - class weekday_indexed - { - public: - - //*********************************************************************** - /// Default constructor - //*********************************************************************** - ETL_CONSTEXPR weekday_indexed() ETL_NOEXCEPT - : wd() - , i() - { - } - - //*********************************************************************** - /// Construct from weekday and index - //*********************************************************************** - ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday& wd_, unsigned index_) ETL_NOEXCEPT - : wd(wd_) - , i(index_) - { - } - - //*********************************************************************** - /// Copy constructor - //*********************************************************************** - ETL_CONSTEXPR weekday_indexed(const etl::chrono::weekday_indexed& other) ETL_NOEXCEPT - : wd(other.wd) - , i(other.i) - { - } - - //*********************************************************************** - /// Assignment operator - //*********************************************************************** - ETL_CONSTEXPR14 etl::chrono::weekday_indexed& operator =(const etl::chrono::weekday_indexed& rhs) ETL_NOEXCEPT - { - wd = rhs.wd; - i = rhs.i; - - return *this; - } - - //*********************************************************************** - /// Get weekday - //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT - { - return wd; - } - - //*********************************************************************** - /// Get index - //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR unsigned index() const ETL_NOEXCEPT - { - return i; - } - - //*********************************************************************** - /// Returns true if the weekday and index are valid - //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT - { - return wd.ok() && (i >= 1U) && (i <= 5U); - } - - private: - - etl::chrono::weekday wd; - unsigned i; - }; - - //*********************************************************************** - /// Equality operator - //*********************************************************************** - ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT - { - return (wd1.weekday() == wd2.weekday()) && - (wd1.index() == wd2.index()); - } - - //*********************************************************************** - /// Inequality operator - //*********************************************************************** - ETL_CONSTEXPR bool operator !=(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT - { - return !(wd1 == wd2); - } - - //*********************************************************************** - /// weekday index operator from index - //*********************************************************************** - ETL_CONSTEXPR etl::chrono::weekday_indexed etl::chrono::weekday::operator[](unsigned index) const ETL_NOEXCEPT - { - return etl::chrono::weekday_indexed(*this, index); - } - } - - //************************************************************************* - /// Hash function for etl::chrono::weekday_indexed - //************************************************************************* -#if ETL_USING_8BIT_TYPES - template <> - struct hash - { - size_t operator()(const etl::chrono::weekday_indexed& wdi) const - { - return etl::hash()(wdi.weekday()) ^ etl::hash()(wdi.index()); - } - }; -#endif -} diff --git a/include/etl/private/chrono/weekday_last.h b/include/etl/private/chrono/weekday_last.h deleted file mode 100644 index 62dc337a2..000000000 --- a/include/etl/private/chrono/weekday_last.h +++ /dev/null @@ -1,115 +0,0 @@ -///\file - -/****************************************************************************** -The MIT License(MIT) - -Embedded Template Library. -https://github.com/ETLCPP/etl -https://www.etlcpp.com - -Copyright(c) 2023 John Wellbelove - -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_IN_CHRONO_H - #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H -#endif - -namespace etl -{ - namespace chrono - { - //*********************************************************************** - /// weekday_last - //*********************************************************************** - class weekday_last - { - public: - - //*********************************************************************** - /// Construct from unsigned - //*********************************************************************** - ETL_CONSTEXPR explicit weekday_last(const etl::chrono::weekday& wd_) ETL_NOEXCEPT - : wd(wd_) - { - } - - //*********************************************************************** - /// Copy constructor - //*********************************************************************** - ETL_CONSTEXPR weekday_last(const etl::chrono::weekday_last& other) ETL_NOEXCEPT - : wd(other.wd) - { - } - - //*********************************************************************** - /// Assignment operator - //*********************************************************************** - ETL_CONSTEXPR14 etl::chrono::weekday_last& operator =(const etl::chrono::weekday_last& rhs) ETL_NOEXCEPT - { - wd = rhs.wd; - - return *this; - } - - //*********************************************************************** - /// Get weekday - //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT - { - return wd; - } - - //*********************************************************************** - /// Returns true if the weekday is valid - //*********************************************************************** - ETL_NODISCARD ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT - { - return wd.ok(); - } - - private: - - etl::chrono::weekday wd; - }; - - //*********************************************************************** - /// Equality operator - //*********************************************************************** - ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_last& wd1, const etl::chrono::weekday_last& wd2) ETL_NOEXCEPT - { - return (wd1.weekday() == wd2.weekday()); - } - } - - //************************************************************************* - /// Hash function for etl::chrono::weekday_last - //************************************************************************* -#if ETL_USING_8BIT_TYPES - template <> - struct hash - { - size_t operator()(const etl::chrono::weekday_last& wdl) const - { - return etl::hash()(wdl.weekday()); - } - }; -#endif -} diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index 695d369ff..84306f784 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -281,6 +281,19 @@ namespace etl return result; } + //*********************************************************************** + /// Subtract etl::chrono::year from etl::chrono::years + ///\return etl::chrono::years + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::year operator -(const etl::chrono::years& ys, const etl::chrono::year& y) ETL_NOEXCEPT + { + etl::chrono::year result(y); + + result -= ys; + + return result; + } + //*********************************************************************** /// Subtract etl::chrono::year from etl::chrono::year ///\return etl::chrono::years @@ -288,7 +301,7 @@ namespace etl ETL_CONSTEXPR etl::chrono::years operator -(const etl::chrono::year& y1, const etl::chrono::year& y2) ETL_NOEXCEPT { return etl::chrono::years(static_cast(static_cast(y1)) - - static_cast(static_cast(y2))); + static_cast(static_cast(y2))); } } diff --git a/test/test_chrono_day.cpp b/test/test_chrono_day.cpp index a801f6076..74245e726 100644 --- a/test/test_chrono_day.cpp +++ b/test/test_chrono_day.cpp @@ -38,7 +38,7 @@ SOFTWARE. #include // Set to 0 to reference against std::chrono -#define ETL_USING_ETL_CHRONO 0 +#define ETL_USING_ETL_CHRONO 1 #if ETL_USING_ETL_CHRONO #define Chrono etl::chrono @@ -290,6 +290,19 @@ namespace #endif } +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_day_compare) + { + Chrono::day day10(10); + Chrono::day day20(20); + + CHECK_EQUAL(0, day10.compare(day10)); + CHECK_EQUAL(-1, day10.compare(day20)); + CHECK_EQUAL(1, day20.compare(day10)); + } +#endif + #if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_day_hashes_are_unique) diff --git a/test/test_chrono_duration.cpp b/test/test_chrono_duration.cpp index f97a606a2..90bca5358 100644 --- a/test/test_chrono_duration.cpp +++ b/test/test_chrono_duration.cpp @@ -520,7 +520,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_positive_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 5; // Scalar value auto result = s1 * scalar; @@ -531,7 +531,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_negative_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = -3; // Negative scalar value auto result = s1 * scalar; @@ -542,7 +542,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_zero_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 0; // Scalar value auto result = s1 * scalar; @@ -553,7 +553,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_large_scalar_duration_scalar) { - etl::chrono::seconds s1(1000); // 1,000 seconds + Chrono::seconds s1(1000); // 1,000 seconds int scalar = 1000000; // Large scalar value auto result = s1 * scalar; @@ -564,7 +564,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_floating_point_scalar_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds double scalar = 2.5; // Floating-point scalar value auto result = s1 * scalar; @@ -575,7 +575,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_different_representation_duration_scalar) { - etl::chrono::milliseconds ms1(500); // 500 milliseconds + Chrono::milliseconds ms1(500); // 500 milliseconds int scalar = 3; // Scalar value auto result = ms1 * scalar; @@ -586,7 +586,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_positive_scalar_duration) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 5; // Scalar value auto result = scalar * s1; @@ -597,7 +597,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_negative_scalar_duration) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = -3; // Negative scalar value auto result = scalar * s1; @@ -608,7 +608,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_scalar_zero_scalar_duration) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 0; // Scalar value auto result = scalar * s1; @@ -619,7 +619,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_large_scalar_scalar_duration) { - etl::chrono::seconds s1(1000); // 1,000 seconds + Chrono::seconds s1(1000); // 1,000 seconds int scalar = 1000000; // Large scalar value auto result = scalar * s1; @@ -630,7 +630,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_floating_point_scalar_scalar_duration) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds double scalar = 2.5; // Floating-point scalar value auto result = scalar * s1; @@ -641,7 +641,7 @@ namespace //************************************************************************* TEST(test_multiplication_with_different_representation_scalar_duration) { - etl::chrono::milliseconds ms1(500); // 500 milliseconds + Chrono::milliseconds ms1(500); // 500 milliseconds int scalar = 3; // Scalar value auto result = scalar * ms1; @@ -652,7 +652,7 @@ namespace //************************************************************************* TEST(test_division_with_scalar_positive_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 5; // Scalar value auto result = s1 / scalar; @@ -663,7 +663,7 @@ namespace //************************************************************************* TEST(test_division_with_scalar_negative_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = -2; // Negative scalar value auto result = s1 / scalar; @@ -674,7 +674,7 @@ namespace //************************************************************************* TEST(test_division_with_large_scalar_duration_scalar) { - etl::chrono::seconds s1(10000000); // 10,000,000 seconds + Chrono::seconds s1(10000000); // 10,000,000 seconds int scalar = 1000000; // Large scalar value auto result = s1 / scalar; @@ -685,7 +685,7 @@ namespace //************************************************************************* TEST(test_division_with_floating_point_scalar_duration_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds double scalar = 2.5; // Floating-point scalar value auto result = s1 / scalar; @@ -696,7 +696,7 @@ namespace //************************************************************************* TEST(test_division_with_different_representation_duration_scalar) { - etl::chrono::milliseconds ms1(500); // 500 milliseconds + Chrono::milliseconds ms1(500); // 500 milliseconds int scalar = 2; // Scalar value auto result = ms1 / scalar; @@ -707,8 +707,8 @@ namespace //************************************************************************* TEST(test_division_same_type) { - etl::chrono::seconds s1(20); // 20 seconds - etl::chrono::seconds s2(10); // 10 seconds + Chrono::seconds s1(20); // 20 seconds + Chrono::seconds s2(10); // 10 seconds auto result = s1 / s2; @@ -718,8 +718,8 @@ namespace //************************************************************************* TEST(test_division_different_types) { - etl::chrono::seconds s1(10); // 10 seconds - etl::chrono::milliseconds ms1(500); // 500 milliseconds + Chrono::seconds s1(10); // 10 seconds + Chrono::milliseconds ms1(500); // 500 milliseconds auto result = s1 / ms1; @@ -730,8 +730,8 @@ namespace //************************************************************************* TEST(test_division_with_large_values) { - etl::chrono::seconds s1(1000000); // 1,000,000 seconds - etl::chrono::milliseconds ms1(500000); // 500,000 milliseconds + Chrono::seconds s1(1000000); // 1,000,000 seconds + Chrono::milliseconds ms1(500000); // 500,000 milliseconds auto result = s1 / ms1; @@ -741,8 +741,8 @@ namespace //************************************************************************* TEST(test_division_resulting_in_fraction) { - etl::chrono::seconds s1(7); // 7 seconds - etl::chrono::seconds s2(3); // 3 seconds + Chrono::seconds s1(7); // 7 seconds + Chrono::seconds s2(3); // 3 seconds auto result = s1 / s2; @@ -752,8 +752,8 @@ namespace //************************************************************************* TEST(test_division_by_larger_duration) { - etl::chrono::seconds s1(5); // 5 seconds - etl::chrono::seconds s2(10); // 10 seconds + Chrono::seconds s1(5); // 5 seconds + Chrono::seconds s2(10); // 10 seconds auto result = s1 / s2; @@ -763,8 +763,8 @@ namespace //************************************************************************* TEST(test_division_by_one) { - etl::chrono::seconds s1(10); // 10 seconds - etl::chrono::seconds s2(1); // 1 second + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(1); // 1 second auto result = s1 / s2; @@ -774,7 +774,7 @@ namespace //************************************************************************* TEST(test_modulus_with_positive_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 3; // Scalar value auto result = s1 % scalar; @@ -785,7 +785,7 @@ namespace //************************************************************************* TEST(test_modulus_with_negative_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = -3; // Negative scalar value auto result = s1 % scalar; @@ -796,7 +796,7 @@ namespace //************************************************************************* TEST(test_modulus_with_large_scalar) { - etl::chrono::seconds s1(10); // 10 seconds + Chrono::seconds s1(10); // 10 seconds int scalar = 100; // Scalar value larger than duration auto result = s1 % scalar; @@ -807,7 +807,7 @@ namespace //************************************************************************* TEST(test_modulus_with_different_representation) { - etl::chrono::milliseconds ms1(1050); // 1050 milliseconds + Chrono::milliseconds ms1(1050); // 1050 milliseconds int scalar = 500; // Scalar value auto result = ms1 % scalar; @@ -818,8 +818,8 @@ namespace //************************************************************************* TEST(test_modulus_same_type) { - etl::chrono::seconds s1(10); // 10 seconds - etl::chrono::seconds s2(3); // 3 seconds + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(3); // 3 seconds auto result = s1 % s2; @@ -829,8 +829,8 @@ namespace //************************************************************************* TEST(test_modulus_different_types) { - etl::chrono::seconds s1(10); // 10 seconds - etl::chrono::milliseconds ms1(3000); // 3000 milliseconds + Chrono::seconds s1(10); // 10 seconds + Chrono::milliseconds ms1(3000); // 3000 milliseconds auto result = s1 % ms1; @@ -841,8 +841,8 @@ namespace //************************************************************************* TEST(test_modulus_with_large_values) { - etl::chrono::seconds s1(1000000); // 1,000,000 seconds - etl::chrono::milliseconds ms1(500000); // 500,000 milliseconds + Chrono::seconds s1(1000000); // 1,000,000 seconds + Chrono::milliseconds ms1(500000); // 500,000 milliseconds auto result = s1 % ms1; @@ -852,8 +852,8 @@ namespace //************************************************************************* TEST(test_modulus_resulting_in_fraction) { - etl::chrono::seconds s1(7); // 7 seconds - etl::chrono::seconds s2(3); // 3 seconds + Chrono::seconds s1(7); // 7 seconds + Chrono::seconds s2(3); // 3 seconds auto result = s1 % s2; @@ -863,8 +863,8 @@ namespace //************************************************************************* TEST(test_modulus_by_larger_duration) { - etl::chrono::seconds s1(5); // 5 seconds - etl::chrono::seconds s2(10); // 10 seconds + Chrono::seconds s1(5); // 5 seconds + Chrono::seconds s2(10); // 10 seconds auto result = s1 % s2; @@ -874,13 +874,169 @@ namespace //************************************************************************* TEST(test_modulus_with_different_periods) { - etl::chrono::seconds s1(10); // 10 seconds - etl::chrono::milliseconds ms1(2500); // 2500 milliseconds + Chrono::seconds s1(10); // 10 seconds + Chrono::milliseconds ms1(2500); // 2500 milliseconds auto result = s1 % ms1; // Result should be in the common type (milliseconds) CHECK_EQUAL(0, result); // 10 seconds % 2500 milliseconds = 0 milliseconds } + + //************************************************************************* + TEST(test_operator_plus_equals_positive_value) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(5); // 5 seconds + + s1 += s2; + + CHECK_EQUAL(15, s1.count()); // 10 + 5 = 15 seconds + } + + //************************************************************************* + TEST(test_operator_plus_equals_negative_value) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(-5); // -5 seconds + + s1 += s2; + + CHECK_EQUAL(5, s1.count()); // 10 + (-5) = 5 seconds + } + + //************************************************************************* + TEST(test_operator_minus_equals_positive_value) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(5); // 5 seconds + + s1 -= s2; + + CHECK_EQUAL(5, s1.count()); // 10 - 5 = 5 seconds + } + + //************************************************************************* + TEST(test_operator_minus_equals_negative_value) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(-5); // -5 seconds + + s1 -= s2; + + CHECK_EQUAL(15, s1.count()); // 10 - (-5) = 15 seconds + } + + //************************************************************************* + TEST(test_operator_times_equals_positive_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = 5; + + s1 *= scalar; + + CHECK_EQUAL(50, s1.count()); // 10 * 5 = 50 seconds + } + + //************************************************************************* + TEST(test_operator_times_equals_negative_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = -5; + + s1 *= scalar; + + CHECK_EQUAL(-50, s1.count()); // 10 * (-5) = -50 seconds + } + + //************************************************************************* + TEST(test_operator_divide_equals_positive_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = 5; + + s1 /= scalar; + + CHECK_EQUAL(2, s1.count()); // 10 / 5 = 2 seconds + } + + //************************************************************************* + TEST(test_operator_divide_equals_negative_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = -5; + + s1 /= scalar; + + CHECK_EQUAL(-2, s1.count()); // 10 / (-5) = -2 seconds + } + + //************************************************************************* + TEST(test_operator_mod_equals_positive_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = 4; + + s1 %= scalar; + + CHECK_EQUAL(2, s1.count()); // 10 % 4 = 2 seconds + } + + //************************************************************************* + TEST(test_operator_mod_equals_negative_value) + { + Chrono::seconds s1(10); // 10 seconds + int scalar = -4; + + s1 %= scalar; + + CHECK_EQUAL(2, s1.count()); // 10 % (-4) = 2 seconds + } + + //************************************************************************* + TEST(test_operator_mod_equals_positive_duration) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(3); // 3 seconds + + s1 %= s2; + + CHECK_EQUAL(1, s1.count()); // 10 seconds % 3 seconds = 1 second + } + + //************************************************************************* + TEST(test_operator_mod_equals_negative_duration) + { + Chrono::seconds s1(10); // 10 seconds + Chrono::seconds s2(-3); // 3 seconds + + s1 %= s2; + + CHECK_EQUAL(1, s1.count()); // 10 seconds % (-3) seconds = 1 second + } + +#if ETL_USING_CPP20 + //************************************************************************* + TEST(test_duration_spaceship_operator) + { + Chrono::seconds s1(2); // 2 seconds + Chrono::milliseconds ms1(1500); // 1500 milliseconds + + CHECK_TRUE(s1 <=> s1 == std::strong_ordering::equal); + CHECK_TRUE(ms1 <=> s1 == std::strong_ordering::less); + CHECK_TRUE(s1 <=> ms1 == std::strong_ordering::greater); + } +#endif + + //************************************************************************* + TEST(test_duration_compare) + { + Chrono::seconds s1(2); // 2 seconds + Chrono::milliseconds ms1(1500); // 1500 milliseconds + + CHECK_EQUAL(0, s1.compare(s1)); + CHECK_EQUAL(-1, ms1.compare(s1)); + CHECK_EQUAL(1, s1.compare(ms1)); + } }; } diff --git a/test/test_chrono_month.cpp b/test/test_chrono_month.cpp index 3c0ffac83..058f260a0 100644 --- a/test/test_chrono_month.cpp +++ b/test/test_chrono_month.cpp @@ -281,6 +281,19 @@ namespace } #endif +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_month_compare) + { + Chrono::month month1(Chrono::January); + Chrono::month month2(Chrono::February); + + CHECK_EQUAL(0, month1.compare(month1)); + CHECK_EQUAL(-1, month1.compare(month2)); + CHECK_EQUAL(1, month2.compare(month1)); + } +#endif + #if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_literal_month) diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp index 9a7c66b25..af5d00fc0 100644 --- a/test/test_chrono_month_day.cpp +++ b/test/test_chrono_month_day.cpp @@ -37,6 +37,20 @@ SOFTWARE. #include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { SUITE(test_chrono_month_day) @@ -44,336 +58,158 @@ namespace //************************************************************************* TEST(test_default_constructor) { - etl::chrono::month_day md; + Chrono::month_day md; + + CHECK_FALSE(md.ok()); // Default-constructed month_day is not valid + } + + //************************************************************************* + TEST(test_constructor_with_month_and_day) + { + Chrono::month_day md{Chrono::January, Chrono::day{15}}; + + CHECK_TRUE(md.ok()); // Valid month_day + CHECK_EQUAL(Chrono::January, md.month()); + CHECK_EQUAL(Chrono::day{15}, md.day()); + } + + //************************************************************************* + TEST(test_invalid_month_day) + { + Chrono::month_day md{Chrono::month{13}, Chrono::day{15}}; // Invalid month (13) + + CHECK_FALSE(md.ok()); // Invalid month_day + } + + //************************************************************************* + TEST(test_invalid_day_in_month_day) + { + Chrono::month_day md{Chrono::January, Chrono::day{32}}; // Invalid day (32) + + CHECK_FALSE(md.ok()); // Invalid month_day + } + +#if ETL_USING_CPP20 + //************************************************************************* + TEST(test_month_day_spaceship_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{15}}; + + CHECK_TRUE((md1 <=> md3) == std::strong_ordering::equal); // Same month and day + CHECK_TRUE((md1 <=> md2) == std::strong_ordering::less); // Different month and day + CHECK_TRUE((md2 <=> md1) == std::strong_ordering::greater); // Same month and day + } +#endif + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_month_day_compare) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{15}}; + + CHECK_TRUE(md1.compare(md3) == 0); // Same month and day + CHECK_TRUE(md1.compare(md2) == -1); // Different month and day + CHECK_TRUE(md2.compare(md1) == 1); // Same month and day + } +#endif + + //************************************************************************* + TEST(test_month_day_equality_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_TRUE(md1 == md1); // January == January + CHECK_FALSE(md1 == md2); // January != February + CHECK_FALSE(md1 == md2); // 20th != 15th in the same month + } + + //************************************************************************* + TEST(test_month_day_not_equality_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_FALSE(md1 != md1); // January == January + CHECK_TRUE(md1 != md2); // January != February + CHECK_TRUE(md1 != md2); // 20th != 15th in the same month + } + + //************************************************************************* + TEST(test_month_day_less_than_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_TRUE(md1 < md2); // January < February + CHECK_TRUE(md1 < md3); // 15th < 20th in the same month + CHECK_FALSE(md2 < md1); // February !< January + CHECK_FALSE(md3 < md1); // 20th !< 15th in the same month + } + + //************************************************************************* + TEST(test_month_day_less_than_equal_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_TRUE(md1 <= md1); // January <= January + CHECK_TRUE(md1 <= md2); // January <= February + CHECK_TRUE(md1 <= md3); // 15th <= 20th in the same month + CHECK_FALSE(md2 <= md1); // February !<= January + CHECK_FALSE(md3 <= md1); // 20th !<= 15th in the same month + } + + //************************************************************************* + TEST(test_month_day_greater_than_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_TRUE(md2 > md1); // February > January + CHECK_TRUE(md3 > md1); // 20th > 15th in the same month + CHECK_FALSE(md1 > md2); // January !> February + CHECK_FALSE(md1 > md3); // 15th !> 20th in the same month + } + + //************************************************************************* + TEST(test_month_day_greater_than_equal_operator) + { + Chrono::month_day md1{Chrono::January, Chrono::day{15}}; + Chrono::month_day md2{Chrono::February, Chrono::day{10}}; + Chrono::month_day md3{Chrono::January, Chrono::day{20}}; + + CHECK_TRUE(md1 >= md1); // January >= January + CHECK_TRUE(md2 >= md1); // February >= January + CHECK_TRUE(md3 >= md1); // 20th >= 15th in the same month + CHECK_FALSE(md1 >= md2); // January !>= February + CHECK_FALSE(md1 >= md3); // 15th !>= 20th in the same month + } + + //************************************************************************* + TEST(test_month_day_min_max) + { + Chrono::month_day md_min{Chrono::January, Chrono::day{1}}; + Chrono::month_day md_max{Chrono::December, Chrono::day{31}}; + + CHECK_TRUE(md_min.ok()); + CHECK_TRUE(md_max.ok()); + + CHECK_EQUAL(Chrono::January, md_min.month()); + CHECK_EQUAL(Chrono::day{1}, md_min.day()); - CHECK_FALSE(md.ok()); + CHECK_EQUAL(Chrono::December, md_max.month()); + CHECK_EQUAL(Chrono::day{31}, md_max.day()); } -// //************************************************************************* -// TEST(test_constructor_in_range) -// { -// for (unsigned i = 0U; i < 256; ++i) -// { -// std::chrono::month std_month(i); -// etl::chrono::month month(i); -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// -// //************************************************************************* -// TEST(test_pre_increment) -// { -// std::chrono::month std_month(0); -// etl::chrono::month month(0); -// -// for (int i = 0; i < 255; ++i) -// { -// ++std_month; -// ++month; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// -// //************************************************************************* -// TEST(test_post_increment) -// { -// std::chrono::month std_month(0); -// etl::chrono::month month(0); -// -// for (int i = 0; i < 256; ++i) -// { -// std::chrono::month std_last_month = std_month++; -// etl::chrono::month last_month = month++; -// -// CHECK_EQUAL(std_last_month.ok(), last_month.ok()); -// CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// -// //************************************************************************* -// TEST(test_pre_decrement) -// { -// std::chrono::month std_month(255); -// etl::chrono::month month(255); -// -// for (int i = 0; i < 256; ++i) -// { -// --std_month; -// --month; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// -// //************************************************************************* -// TEST(test_post_decrement) -// { -// std::chrono::month std_month(255); -// etl::chrono::month month(255); -// -// for (int i = 0; i < 256; ++i) -// { -// std::chrono::month std_last_month = std_month--; -// etl::chrono::month last_month = month--; -// -// CHECK_EQUAL(std_last_month.ok(), last_month.ok()); -// CHECK_EQUAL(unsigned(std_last_month), unsigned(last_month)); -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// -// //************************************************************************* -// TEST(test_plus_equal_months) -// { -// for (int m = 0; m <= 12; ++m) -// { -// for (int ms = 0; ms <= 24; ++ms) -// { -// std::chrono::month std_month(m); -// etl::chrono::month month(m); -// -// std::chrono::months std_months(ms); -// etl::chrono::months months(ms); -// -// std_month += std_months; -// month += months; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// } -// -// //************************************************************************* -// TEST(test_month_plus_months) -// { -// for (int m = 0; m <= 12; ++m) -// { -// for (int ms = 0; ms <= 24; ++ms) -// { -// std::chrono::month std_month(m); -// etl::chrono::month month(m); -// -// std::chrono::months std_months(ms); -// etl::chrono::months months(ms); -// -// std_month = std_month + std_months; -// month = month + months; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// } -// -// //************************************************************************* -// TEST(test_months_plus_month) -// { -// for (int m = 0; m <= 12; ++m) -// { -// for (int ms = 0; ms <= 24; ++ms) -// { -// std::chrono::month std_month(m); -// etl::chrono::month month(m); -// -// std::chrono::months std_months(ms); -// etl::chrono::months months(ms); -// -// std_month = std_months + std_month; -// month = months + month; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// } -// -// //************************************************************************* -// TEST(test_minus_equal_months) -// { -// for (int m = 0; m <= 12; ++m) -// { -// for (int ms = 0; ms <= 24; ++ms) -// { -// std::chrono::month std_month(m); -// etl::chrono::month month(m); -// -// std::chrono::months std_months(ms); -// etl::chrono::months months(ms); -// -// std_month -= std_months; -// month -= months; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// } -// -// //************************************************************************* -// TEST(test_month_minus_months) -// { -// for (int m = 0; m <= 12; ++m) -// { -// for (int ms = 0; ms <= 24; ++ms) -// { -// std::chrono::month std_month(m); -// etl::chrono::month month(m); -// -// std::chrono::months std_months(ms); -// etl::chrono::months months(ms); -// -// std_month = std_month - std_months; -// month = month - months; -// -// CHECK_EQUAL(std_month.ok(), month.ok()); -// CHECK_EQUAL(unsigned(std_month), unsigned(month)); -// } -// } -// } -// -// //************************************************************************* -// TEST(test_month_minus_month) -// { -// for (int m = 0; m < 256; ++m) -// { -// std::chrono::month std_month1(m); -// std::chrono::month std_month2(255 - m); -// -// std::chrono::month month1(m); -// std::chrono::month month2(255 - m); -// -// auto std_months12 = std_month1 - std_month2; -// auto std_months21 = std_month2 - std_month1; -// -// auto months12 = month1 - month2; -// auto months21 = month2 - month1; -// -// CHECK_EQUAL(std_months12.count(), months12.count()); -// CHECK_EQUAL(std_months21.count(), months21.count()); -// } -// } -// -// //************************************************************************* -// TEST(test_min_max_month) -// { -// CHECK_EQUAL(1U, etl::chrono::month::min()); -// CHECK_EQUAL(12U, etl::chrono::month::max()); -// } -// -// //************************************************************************* -// TEST(test_literal_month) -// { -// using namespace etl::literals::chrono_literals; -// -// etl::chrono::month month1 = 1_month; -// etl::chrono::month month2 = 2_month; -// etl::chrono::month month3 = 3_month; -// etl::chrono::month month4 = 4_month; -// etl::chrono::month month5 = 5_month; -// etl::chrono::month month6 = 6_month; -// etl::chrono::month month7 = 7_month; -// etl::chrono::month month8 = 8_month; -// etl::chrono::month month9 = 9_month; -// etl::chrono::month month10 = 10_month; -// etl::chrono::month month11 = 11_month; -// etl::chrono::month month12 = 12_month; -// -// CHECK_TRUE(month1.ok()); -// CHECK_TRUE(month2.ok()); -// CHECK_TRUE(month3.ok()); -// CHECK_TRUE(month4.ok()); -// CHECK_TRUE(month5.ok()); -// CHECK_TRUE(month6.ok()); -// CHECK_TRUE(month7.ok()); -// CHECK_TRUE(month8.ok()); -// CHECK_TRUE(month9.ok()); -// CHECK_TRUE(month10.ok()); -// CHECK_TRUE(month11.ok()); -// CHECK_TRUE(month12.ok()); -// -// CHECK_EQUAL(1U, unsigned(month1)); -// CHECK_EQUAL(2U, unsigned(month2)); -// CHECK_EQUAL(3U, unsigned(month3)); -// CHECK_EQUAL(4U, unsigned(month4)); -// CHECK_EQUAL(5U, unsigned(month5)); -// CHECK_EQUAL(6U, unsigned(month6)); -// CHECK_EQUAL(7U, unsigned(month7)); -// CHECK_EQUAL(8U, unsigned(month8)); -// CHECK_EQUAL(9U, unsigned(month9)); -// CHECK_EQUAL(10U, unsigned(month10)); -// CHECK_EQUAL(11U, unsigned(month11)); -// CHECK_EQUAL(12U, unsigned(month12)); -// } -// -// //************************************************************************* -// TEST(test_month_comparison_operators) -// { -// etl::chrono::month month1(1); -// etl::chrono::month month2(2); -// -// CHECK_TRUE(month1 == month1); -// CHECK_FALSE(month1 != month1); -// CHECK_TRUE(month1 < month2); -// CHECK_FALSE(month1 < month1); -// CHECK_FALSE(month2 < month1); -// CHECK_TRUE(month1 <= month2); -// CHECK_TRUE(month1 <= month1); -// CHECK_FALSE(month2 <= month1); -// CHECK_FALSE(month1 > month2); -// CHECK_FALSE(month1 > month1); -// CHECK_TRUE(month2 > month1); -// CHECK_FALSE(month1 >= month2); -// CHECK_TRUE(month1 >= month1); -// CHECK_TRUE(month2 >= month1); -// -//#if ETL_USING_CPP20 -// CHECK_TRUE((month1 <=> month1) == 0); -// CHECK_TRUE((month1 <=> month2) < 0); -// CHECK_TRUE((month2 <=> month1) > 0); -//#endif -// } -// -// //************************************************************************* -// TEST(test_month_hashes_are_unique) -// { -// std::vector hashes; -// -// for (int i = 0; i < 256; ++i) -// { -// hashes.push_back(etl::hash()(etl::chrono::month(i))); -// } -// -// std::sort(hashes.begin(), hashes.end()); -// (void)std::unique(hashes.begin(), hashes.end()); -// CHECK_EQUAL(256U, hashes.size()); -// } -// -// //************************************************************************* -// TEST(test_month_types) -// { -// CHECK_EQUAL(static_cast(std::chrono::January), static_cast(etl::chrono::January)); -// CHECK_EQUAL(static_cast(std::chrono::February), static_cast(etl::chrono::February)); -// CHECK_EQUAL(static_cast(std::chrono::March), static_cast(etl::chrono::March)); -// CHECK_EQUAL(static_cast(std::chrono::April), static_cast(etl::chrono::April)); -// CHECK_EQUAL(static_cast(std::chrono::May), static_cast(etl::chrono::May)); -// CHECK_EQUAL(static_cast(std::chrono::June), static_cast(etl::chrono::June)); -// CHECK_EQUAL(static_cast(std::chrono::July), static_cast(etl::chrono::July)); -// CHECK_EQUAL(static_cast(std::chrono::August), static_cast(etl::chrono::August)); -// CHECK_EQUAL(static_cast(std::chrono::September), static_cast(etl::chrono::September)); -// CHECK_EQUAL(static_cast(std::chrono::October), static_cast(etl::chrono::October)); -// CHECK_EQUAL(static_cast(std::chrono::November), static_cast(etl::chrono::November)); -// CHECK_EQUAL(static_cast(std::chrono::December), static_cast(etl::chrono::December)); -// } }; } diff --git a/test/test_chrono_month_day_last.cpp b/test/test_chrono_month_day_last.cpp new file mode 100644 index 000000000..ec9b6ae4f --- /dev/null +++ b/test/test_chrono_month_day_last.cpp @@ -0,0 +1,130 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2025 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_month_day_last) + { + //************************************************************************* + TEST(test_constructor_in_range) + { + Chrono::month_day_last month_day_last_january(Chrono::January); + Chrono::month_day_last month_day_last_february(Chrono::February); + Chrono::month_day_last month_day_last_march(Chrono::March); + Chrono::month_day_last month_day_last_april(Chrono::April); + Chrono::month_day_last month_day_last_may(Chrono::May); + Chrono::month_day_last month_day_last_june(Chrono::June); + Chrono::month_day_last month_day_last_july(Chrono::July); + Chrono::month_day_last month_day_last_august(Chrono::August); + Chrono::month_day_last month_day_last_september(Chrono::September); + Chrono::month_day_last month_day_last_october(Chrono::October); + Chrono::month_day_last month_day_last_november(Chrono::November); + Chrono::month_day_last month_day_last_december(Chrono::December); + + CHECK_TRUE(month_day_last_january.ok()); + CHECK_TRUE(month_day_last_february.ok()); + CHECK_TRUE(month_day_last_march.ok()); + CHECK_TRUE(month_day_last_april.ok()); + CHECK_TRUE(month_day_last_may.ok()); + CHECK_TRUE(month_day_last_june.ok()); + CHECK_TRUE(month_day_last_july.ok()); + CHECK_TRUE(month_day_last_august.ok()); + CHECK_TRUE(month_day_last_september.ok()); + CHECK_TRUE(month_day_last_october.ok()); + CHECK_TRUE(month_day_last_november.ok()); + CHECK_TRUE(month_day_last_december.ok()); + } + + //************************************************************************* + TEST(test_month_day_last_comparison_operators) + { + Chrono::month_day_last month_day_last1(Chrono::January); + Chrono::month_day_last month_day_last2(Chrono::January); + Chrono::month_day_last month_day_last3(Chrono::February); + + CHECK_TRUE(month_day_last1 == month_day_last2); + CHECK_FALSE(month_day_last1 == month_day_last3); + + CHECK_FALSE(month_day_last1 != month_day_last2); + CHECK_TRUE(month_day_last1 != month_day_last3); + } + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_month_day_last_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 6; ++i) + { + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::January))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::February))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::March))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::April))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::May))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::June))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::July))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::August))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::September))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::October))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::November))); + hashes.push_back(etl::hash()(Chrono::month_day_last(Chrono::December))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + } +#endif + }; +} diff --git a/test/test_chrono_month_weekday.cpp b/test/test_chrono_month_weekday.cpp new file mode 100644 index 000000000..2b21a88ca --- /dev/null +++ b/test/test_chrono_month_weekday.cpp @@ -0,0 +1,126 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_month_weekday) + { + //************************************************************************* + TEST(test_constructor_with_month_and_day) + { + Chrono::month_weekday mwd{ Chrono::January, Chrono::weekday_indexed(Chrono::Friday, 2) }; + + CHECK_TRUE(mwd.ok()); // Valid month_weekday + CHECK_EQUAL(Chrono::January, mwd.month()); + CHECK_EQUAL(Chrono::Friday.c_encoding(), mwd.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(2, mwd.weekday_indexed().index()); + } + + //************************************************************************* + TEST(test_invalid_month_weekday) + { + Chrono::month_weekday mwd{Chrono::month{13}, Chrono::weekday_indexed(Chrono::Friday, 2)}; // Invalid month (13) + + CHECK_FALSE(mwd.ok()); // Invalid month_weekday + } + + //************************************************************************* + TEST(test_invalid_day_in_month_weekday) + { + Chrono::month_weekday mwd{Chrono::January, Chrono::weekday_indexed(Chrono::weekday{8}, 2)}; // Invalid day (8) + + CHECK_FALSE(mwd.ok()); // Invalid month_weekday + } + + //************************************************************************* + TEST(test_month_weekday_equality_operator) + { + Chrono::month_weekday mwd1{Chrono::January, Chrono::weekday_indexed(Chrono::Friday, 2)}; + Chrono::month_weekday mwd2{Chrono::February, Chrono::weekday_indexed(Chrono::Friday, 2)}; + Chrono::month_weekday mwd3{Chrono::January, Chrono::weekday_indexed(Chrono::Saturday, 2)}; + + CHECK_TRUE(mwd1 == mwd1); // January == January + CHECK_FALSE(mwd1 == mwd2); // January != February + CHECK_FALSE(mwd1 == mwd2); // Friday != Saturday + } + + //************************************************************************* + TEST(test_month_weekday_not_equality_operator) + { + Chrono::month_weekday mwd1{Chrono::January, Chrono::weekday_indexed(Chrono::Friday, 2)}; + Chrono::month_weekday mwd2{Chrono::February, Chrono::weekday_indexed(Chrono::Friday, 2)}; + Chrono::month_weekday mwd3{Chrono::January, Chrono::weekday_indexed(Chrono::Saturday, 2)}; + + CHECK_FALSE(mwd1 != mwd1); // January == January + CHECK_TRUE(mwd1 != mwd2); // January != February + CHECK_TRUE(mwd1 != mwd2); // Friday != Saturday + } + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_month_weekday_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(Chrono::month_weekday(Chrono::month((i % 12) + 1), Chrono::weekday_indexed(Chrono::weekday(i % 7), i % 5)))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } +#endif + }; +} diff --git a/test/test_chrono_month_weekday_last.cpp b/test/test_chrono_month_weekday_last.cpp new file mode 100644 index 000000000..1a95d9176 --- /dev/null +++ b/test/test_chrono_month_weekday_last.cpp @@ -0,0 +1,125 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_month_weekday_last) + { + //************************************************************************* + TEST(test_constructor_with_month_and_day) + { + Chrono::month_weekday_last mwdl{ Chrono::January, Chrono::weekday_last(Chrono::Friday)}; + + CHECK_TRUE(mwdl.ok()); // Valid month_weekday_last + CHECK_EQUAL(Chrono::January, mwdl.month()); + CHECK_EQUAL(Chrono::Friday.c_encoding(), mwdl.weekday_last().weekday().c_encoding()); + } + + //************************************************************************* + TEST(test_invalid_month_weekday_last) + { + Chrono::month_weekday_last mwdl{Chrono::month{13}, Chrono::weekday_last(Chrono::Friday)}; // Invalid month (13) + + CHECK_FALSE(mwdl.ok()); // Invalid month_weekday_last + } + + //************************************************************************* + TEST(test_invalid_day_in_month_weekday_last) + { + Chrono::month_weekday_last mwdl{Chrono::January, Chrono::weekday_last(Chrono::weekday(8))}; // Invalid day (8) + + CHECK_FALSE(mwdl.ok()); // Invalid month_weekday_last + } + + //************************************************************************* + TEST(test_month_weekday_last_equality_operator) + { + Chrono::month_weekday_last mwd1{Chrono::January, Chrono::weekday_last(Chrono::Friday)}; + Chrono::month_weekday_last mwd2{Chrono::February, Chrono::weekday_last(Chrono::Friday)}; + Chrono::month_weekday_last mwd3{Chrono::January, Chrono::weekday_last(Chrono::Saturday)}; + + CHECK_TRUE(mwd1 == mwd1); // January == January + CHECK_FALSE(mwd1 == mwd2); // January != February + CHECK_FALSE(mwd1 == mwd2); // Friday != Saturday + } + + //************************************************************************* + TEST(test_month_weekday_last_not_equality_operator) + { + Chrono::month_weekday_last mwd1{Chrono::January, Chrono::weekday_last(Chrono::Friday)}; + Chrono::month_weekday_last mwd2{Chrono::February, Chrono::weekday_last(Chrono::Friday)}; + Chrono::month_weekday_last mwd3{Chrono::January, Chrono::weekday_last(Chrono::Saturday)}; + + CHECK_FALSE(mwd1 != mwd1); // January == January + CHECK_TRUE(mwd1 != mwd2); // January != February + CHECK_TRUE(mwd1 != mwd2); // Friday != Saturday + } + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_month_weekday_last_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 256; ++i) + { + hashes.push_back(etl::hash()(Chrono::month_weekday_last(Chrono::month((i % 12) + 1), Chrono::weekday_last(Chrono::weekday(i % 7))))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + CHECK_EQUAL(256U, hashes.size()); + } +#endif + }; +} diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index ca65b1ce2..ec6cedc8d 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -34,12 +34,25 @@ SOFTWARE. #include "etl/chrono.h" -#include - #include -#include #include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { SUITE(test_chrono_weekday) @@ -47,7 +60,7 @@ namespace //************************************************************************* TEST(test_default_constructor) { - etl::chrono::weekday weekday; + Chrono::weekday weekday; CHECK_FALSE(weekday.ok()); } @@ -57,7 +70,7 @@ namespace { for (unsigned i = 0U; i < 7U; ++i) { - etl::chrono::weekday weekday(i); + Chrono::weekday weekday(i); CHECK_TRUE(weekday.ok()); CHECK_EQUAL(i, weekday.c_encoding()); @@ -70,7 +83,7 @@ namespace { for (unsigned i = 8U; i < 256U; ++i) { - etl::chrono::weekday weekday(i); + Chrono::weekday weekday(i); CHECK_FALSE(weekday.ok()); CHECK_EQUAL(i, weekday.c_encoding()); @@ -81,7 +94,7 @@ namespace //************************************************************************* TEST(test_pre_increment) { - etl::chrono::weekday weekday(0); + Chrono::weekday weekday(0); unsigned count = 0; for (int i = 0; i < 255; ++i) @@ -98,12 +111,12 @@ namespace //************************************************************************* TEST(test_post_increment) { - etl::chrono::weekday weekday(0); + Chrono::weekday weekday(0); unsigned count = 0; for (int i = 0; i < 255; ++i) { - etl::chrono::weekday last_weekday = weekday++; + Chrono::weekday last_weekday = weekday++; unsigned last_count = count++; CHECK_TRUE(last_weekday.ok()); @@ -119,7 +132,7 @@ namespace //************************************************************************* TEST(test_pre_decrement) { - etl::chrono::weekday weekday(255U); + Chrono::weekday weekday(255U); unsigned count = 255U; for (int i = 0; i < 255; ++i) @@ -136,12 +149,12 @@ namespace //************************************************************************* TEST(test_post_decrement) { - etl::chrono::weekday weekday(255U); + Chrono::weekday weekday(255U); unsigned count = 255U; for (int i = 0; i < 255; ++i) { - etl::chrono::weekday last_weekday = weekday--; + Chrono::weekday last_weekday = weekday--; unsigned last_count = count--; if (last_count == 255U) @@ -170,8 +183,8 @@ namespace { for (unsigned ds = 0; ds <= 14; ++ds) { - etl::chrono::weekday weekday(wd); - etl::chrono::days days(ds); + Chrono::weekday weekday(wd); + Chrono::days days(ds); weekday += days; unsigned expected = (wd + ds) % 7; @@ -190,8 +203,8 @@ namespace { for (unsigned ds = 0; ds <= 14; ++ds) { - etl::chrono::weekday weekday(wd); - etl::chrono::days days(ds); + Chrono::weekday weekday(wd); + Chrono::days days(ds); weekday = weekday + days; unsigned expected = (wd + ds) % 7; @@ -210,8 +223,8 @@ namespace { for (unsigned ds = 0; ds <= 14; ++ds) { - etl::chrono::weekday weekday(wd); - etl::chrono::days days(ds); + Chrono::weekday weekday(wd); + Chrono::days days(ds); weekday = weekday + days; unsigned expected = (ds + wd) % 7; @@ -230,8 +243,8 @@ namespace { for (unsigned ds = 0; ds <= 14; ++ds) { - etl::chrono::weekday weekday(wd); - etl::chrono::days days(ds); + Chrono::weekday weekday(wd); + Chrono::days days(ds); weekday -= days; unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; @@ -250,8 +263,8 @@ namespace { for (unsigned ds = 0; ds <= 14; ++ds) { - etl::chrono::weekday weekday(wd); - etl::chrono::days days(ds); + Chrono::weekday weekday(wd); + Chrono::days days(ds); weekday = weekday - days; unsigned expected = ((wd + 7U) - (ds % 7U)) % 7U; @@ -268,11 +281,11 @@ namespace { for (int m = 0; m < 7; ++m) { - etl::chrono::weekday weekday1(m); - etl::chrono::weekday weekday2(7 - m); + Chrono::weekday weekday1(m); + Chrono::weekday weekday2(7 - m); - std::chrono::weekday std_weekday1(m); - std::chrono::weekday std_weekday2(7 - m); + Chrono::weekday std_weekday1(m); + Chrono::weekday std_weekday2(7 - m); auto days12 = weekday1 - weekday2; auto days21 = weekday2 - weekday1; @@ -285,37 +298,48 @@ namespace } } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_min_max_weekday) { - CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), etl::chrono::weekday::min().c_encoding()); - CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), etl::chrono::weekday::max().c_encoding()); + CHECK_EQUAL(Chrono::Sunday.c_encoding(), Chrono::weekday::min()); + CHECK_EQUAL(Chrono::Saturday.c_encoding(), Chrono::weekday::max()); } +#endif //************************************************************************* TEST(test_weekday_constants) { - CHECK_EQUAL(0U, etl::chrono::Sunday.c_encoding()); - CHECK_EQUAL(1U, etl::chrono::Monday.c_encoding()); - CHECK_EQUAL(2U, etl::chrono::Tuesday.c_encoding()); - CHECK_EQUAL(3U, etl::chrono::Wednesday.c_encoding()); - CHECK_EQUAL(4U, etl::chrono::Thursday.c_encoding()); - CHECK_EQUAL(5U, etl::chrono::Friday.c_encoding()); - CHECK_EQUAL(6U, etl::chrono::Saturday.c_encoding()); + CHECK_EQUAL(0U, Chrono::Sunday.c_encoding()); + CHECK_EQUAL(1U, Chrono::Monday.c_encoding()); + CHECK_EQUAL(2U, Chrono::Tuesday.c_encoding()); + CHECK_EQUAL(3U, Chrono::Wednesday.c_encoding()); + CHECK_EQUAL(4U, Chrono::Thursday.c_encoding()); + CHECK_EQUAL(5U, Chrono::Friday.c_encoding()); + CHECK_EQUAL(6U, Chrono::Saturday.c_encoding()); + + CHECK_EQUAL(7U, Chrono::Sunday.iso_encoding()); + CHECK_EQUAL(1U, Chrono::Monday.iso_encoding()); + CHECK_EQUAL(2U, Chrono::Tuesday.iso_encoding()); + CHECK_EQUAL(3U, Chrono::Wednesday.iso_encoding()); + CHECK_EQUAL(4U, Chrono::Thursday.iso_encoding()); + CHECK_EQUAL(5U, Chrono::Friday.iso_encoding()); + CHECK_EQUAL(6U, Chrono::Saturday.iso_encoding()); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_weekday_literals) { using namespace etl::literals::chrono_literals; - etl::chrono::weekday weekday0 = 0_weekday; - etl::chrono::weekday weekday1 = 1_weekday; - etl::chrono::weekday weekday2 = 2_weekday; - etl::chrono::weekday weekday3 = 3_weekday; - etl::chrono::weekday weekday4 = 4_weekday; - etl::chrono::weekday weekday5 = 5_weekday; - etl::chrono::weekday weekday6 = 6_weekday; + Chrono::weekday weekday0 = 0_weekday; + Chrono::weekday weekday1 = 1_weekday; + Chrono::weekday weekday2 = 2_weekday; + Chrono::weekday weekday3 = 3_weekday; + Chrono::weekday weekday4 = 4_weekday; + Chrono::weekday weekday5 = 5_weekday; + Chrono::weekday weekday6 = 6_weekday; CHECK_TRUE(weekday0.ok()); CHECK_TRUE(weekday1.ok()); @@ -333,35 +357,38 @@ namespace CHECK_EQUAL(5U, weekday5.c_encoding()); CHECK_EQUAL(6U, weekday6.c_encoding()); } +#endif //************************************************************************* TEST(test_weekday_comparison_operators) { - etl::chrono::weekday weekday1(1); - etl::chrono::weekday weekday2(2); + Chrono::weekday weekday1(1); + Chrono::weekday weekday2(2); CHECK_TRUE(weekday1 == weekday1); CHECK_FALSE(weekday1 != weekday1); - CHECK_TRUE(weekday1 < weekday2); - CHECK_FALSE(weekday1 < weekday1); - CHECK_FALSE(weekday2 < weekday1); - CHECK_TRUE(weekday1 <= weekday2); - CHECK_TRUE(weekday1 <= weekday1); - CHECK_FALSE(weekday2 <= weekday1); - CHECK_FALSE(weekday1 > weekday2); - CHECK_FALSE(weekday1 > weekday1); - CHECK_TRUE(weekday2 > weekday1); - CHECK_FALSE(weekday1 >= weekday2); - CHECK_TRUE(weekday1 >= weekday1); - CHECK_TRUE(weekday2 >= weekday1); - -#if ETL_USING_CPP20 - CHECK_TRUE((weekday1 <=> weekday1) == 0); - CHECK_TRUE((weekday1 <=> weekday2) < 0); - CHECK_TRUE((weekday2 <=> weekday1) > 0); -#endif } + //************************************************************************* + TEST(test_weekday_index_operator_returning_weekday_indexed) + { + Chrono::weekday wd(Chrono::Friday); + Chrono::weekday_indexed wi = wd[2]; + + CHECK_EQUAL(2, wi.index()); + CHECK_EQUAL(Chrono::Friday.c_encoding(), wi.weekday().c_encoding()); + } + + //************************************************************************* + TEST(test_weekday_index_operator_returning_weekday_last) + { + Chrono::weekday wd(Chrono::Friday); + Chrono::weekday_last wl = wd[Chrono::last]; + + CHECK_EQUAL(Chrono::Friday.c_encoding(), wl.weekday().c_encoding()); + } + +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_weekday_hashes_are_unique) { @@ -369,12 +396,13 @@ namespace for (int i = 0; i < 256; ++i) { - hashes.push_back(etl::hash()(etl::chrono::weekday(i))); + hashes.push_back(etl::hash()(Chrono::weekday(i))); } std::sort(hashes.begin(), hashes.end()); (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } +#endif }; } diff --git a/test/test_chrono_weekday_indexed.cpp b/test/test_chrono_weekday_indexed.cpp index e690fc966..abaa6aadd 100644 --- a/test/test_chrono_weekday_indexed.cpp +++ b/test/test_chrono_weekday_indexed.cpp @@ -34,12 +34,23 @@ SOFTWARE. #include "etl/chrono.h" -#include - #include -#include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { SUITE(test_chrono_weekday_indexed) @@ -47,7 +58,7 @@ namespace //************************************************************************* TEST(test_default_constructor) { - etl::chrono::weekday_indexed weekday_indexed; + Chrono::weekday_indexed weekday_indexed; CHECK_FALSE(weekday_indexed.ok()); } @@ -57,13 +68,13 @@ namespace { for (unsigned i = 1U; i < 5U; ++i) { - etl::chrono::weekday_indexed weekday_indexed_monday(etl::chrono::Monday, i); - etl::chrono::weekday_indexed weekday_indexed_tuesday(etl::chrono::Tuesday, i); - etl::chrono::weekday_indexed weekday_indexed_wednesday(etl::chrono::Wednesday, i); - etl::chrono::weekday_indexed weekday_indexed_thursday(etl::chrono::Thursday, i); - etl::chrono::weekday_indexed weekday_indexed_friday(etl::chrono::Friday, i); - etl::chrono::weekday_indexed weekday_indexed_saturday(etl::chrono::Saturday, i); - etl::chrono::weekday_indexed weekday_indexed_sunday(etl::chrono::Sunday, i); + Chrono::weekday_indexed weekday_indexed_monday(Chrono::Monday, i); + Chrono::weekday_indexed weekday_indexed_tuesday(Chrono::Tuesday, i); + Chrono::weekday_indexed weekday_indexed_wednesday(Chrono::Wednesday, i); + Chrono::weekday_indexed weekday_indexed_thursday(Chrono::Thursday, i); + Chrono::weekday_indexed weekday_indexed_friday(Chrono::Friday, i); + Chrono::weekday_indexed weekday_indexed_saturday(Chrono::Saturday, i); + Chrono::weekday_indexed weekday_indexed_sunday(Chrono::Sunday, i); CHECK_TRUE(weekday_indexed_monday.ok()); CHECK_TRUE(weekday_indexed_tuesday.ok()); @@ -73,13 +84,13 @@ namespace CHECK_TRUE(weekday_indexed_saturday.ok()); CHECK_TRUE(weekday_indexed_sunday.ok()); - CHECK_EQUAL(etl::chrono::Monday.c_encoding(), weekday_indexed_monday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), weekday_indexed_tuesday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), weekday_indexed_wednesday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), weekday_indexed_thursday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Friday.c_encoding(), weekday_indexed_friday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), weekday_indexed_saturday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), weekday_indexed_sunday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Monday.c_encoding(), weekday_indexed_monday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Tuesday.c_encoding(), weekday_indexed_tuesday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Wednesday.c_encoding(), weekday_indexed_wednesday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Thursday.c_encoding(), weekday_indexed_thursday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Friday.c_encoding(), weekday_indexed_friday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Saturday.c_encoding(), weekday_indexed_saturday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Sunday.c_encoding(), weekday_indexed_sunday.weekday().c_encoding()); CHECK_EQUAL(i, weekday_indexed_monday.index()); CHECK_EQUAL(i, weekday_indexed_tuesday.index()); @@ -96,13 +107,13 @@ namespace { for (unsigned i = 6U; i < 256U; ++i) { - etl::chrono::weekday_indexed weekday_indexed_monday(etl::chrono::Monday, i); - etl::chrono::weekday_indexed weekday_indexed_tuesday(etl::chrono::Tuesday, i); - etl::chrono::weekday_indexed weekday_indexed_wednesday(etl::chrono::Wednesday, i); - etl::chrono::weekday_indexed weekday_indexed_thursday(etl::chrono::Thursday, i); - etl::chrono::weekday_indexed weekday_indexed_friday(etl::chrono::Friday, i); - etl::chrono::weekday_indexed weekday_indexed_saturday(etl::chrono::Saturday, i); - etl::chrono::weekday_indexed weekday_indexed_sunday(etl::chrono::Sunday, i); + Chrono::weekday_indexed weekday_indexed_monday(Chrono::Monday, i); + Chrono::weekday_indexed weekday_indexed_tuesday(Chrono::Tuesday, i); + Chrono::weekday_indexed weekday_indexed_wednesday(Chrono::Wednesday, i); + Chrono::weekday_indexed weekday_indexed_thursday(Chrono::Thursday, i); + Chrono::weekday_indexed weekday_indexed_friday(Chrono::Friday, i); + Chrono::weekday_indexed weekday_indexed_saturday(Chrono::Saturday, i); + Chrono::weekday_indexed weekday_indexed_sunday(Chrono::Sunday, i); CHECK_FALSE(weekday_indexed_monday.ok()); CHECK_FALSE(weekday_indexed_tuesday.ok()); @@ -117,16 +128,17 @@ namespace //************************************************************************* TEST(test_weekday_indexed_comparison_operators) { - etl::chrono::weekday_indexed weekday_indexed1(etl::chrono::Monday, 1); - etl::chrono::weekday_indexed weekday_indexed2(etl::chrono::Monday, 1); - etl::chrono::weekday_indexed weekday_indexed3(etl::chrono::Monday, 2); - etl::chrono::weekday_indexed weekday_indexed4(etl::chrono::Tuesday, 1); + Chrono::weekday_indexed weekday_indexed1(Chrono::Monday, 1); + Chrono::weekday_indexed weekday_indexed2(Chrono::Monday, 1); + Chrono::weekday_indexed weekday_indexed3(Chrono::Monday, 2); + Chrono::weekday_indexed weekday_indexed4(Chrono::Tuesday, 1); - CHECK_TRUE(weekday_indexed1 == weekday_indexed2); + CHECK_TRUE(weekday_indexed1 == weekday_indexed2); CHECK_FALSE(weekday_indexed1 == weekday_indexed3); CHECK_FALSE(weekday_indexed1 == weekday_indexed4); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_weekday_indexed_hashes_are_unique) { @@ -134,17 +146,18 @@ namespace for (int i = 0; i < 6; ++i) { - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Monday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Tuesday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Wednesday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Thursday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Friday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Saturday, i))); - hashes.push_back(etl::hash()(etl::chrono::weekday_indexed(etl::chrono::Sunday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Monday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Tuesday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Wednesday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Thursday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Friday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Saturday, i))); + hashes.push_back(etl::hash()(Chrono::weekday_indexed(Chrono::Sunday, i))); } std::sort(hashes.begin(), hashes.end()); (void)std::unique(hashes.begin(), hashes.end()); } +#endif }; } diff --git a/test/test_chrono_weekday_last.cpp b/test/test_chrono_weekday_last.cpp index e2787a2ec..a3a2a0783 100644 --- a/test/test_chrono_weekday_last.cpp +++ b/test/test_chrono_weekday_last.cpp @@ -34,12 +34,24 @@ SOFTWARE. #include "etl/chrono.h" -#include - #include #include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { SUITE(test_chrono_weekday_last) @@ -49,13 +61,13 @@ namespace { for (unsigned i = 1U; i < 5U; ++i) { - etl::chrono::weekday_last weekday_last_monday(etl::chrono::Monday); - etl::chrono::weekday_last weekday_last_tuesday(etl::chrono::Tuesday); - etl::chrono::weekday_last weekday_last_wednesday(etl::chrono::Wednesday); - etl::chrono::weekday_last weekday_last_thursday(etl::chrono::Thursday); - etl::chrono::weekday_last weekday_last_friday(etl::chrono::Friday); - etl::chrono::weekday_last weekday_last_saturday(etl::chrono::Saturday); - etl::chrono::weekday_last weekday_last_sunday(etl::chrono::Sunday); + Chrono::weekday_last weekday_last_monday(Chrono::Monday); + Chrono::weekday_last weekday_last_tuesday(Chrono::Tuesday); + Chrono::weekday_last weekday_last_wednesday(Chrono::Wednesday); + Chrono::weekday_last weekday_last_thursday(Chrono::Thursday); + Chrono::weekday_last weekday_last_friday(Chrono::Friday); + Chrono::weekday_last weekday_last_saturday(Chrono::Saturday); + Chrono::weekday_last weekday_last_sunday(Chrono::Sunday); CHECK_TRUE(weekday_last_monday.ok()); CHECK_TRUE(weekday_last_tuesday.ok()); @@ -65,13 +77,13 @@ namespace CHECK_TRUE(weekday_last_saturday.ok()); CHECK_TRUE(weekday_last_sunday.ok()); - CHECK_EQUAL(etl::chrono::Monday.c_encoding(), weekday_last_monday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), weekday_last_tuesday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), weekday_last_wednesday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), weekday_last_thursday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Friday.c_encoding(), weekday_last_friday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Saturday.c_encoding(), weekday_last_saturday.weekday().c_encoding()); - CHECK_EQUAL(etl::chrono::Sunday.c_encoding(), weekday_last_sunday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Monday.c_encoding(), weekday_last_monday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Tuesday.c_encoding(), weekday_last_tuesday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Wednesday.c_encoding(), weekday_last_wednesday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Thursday.c_encoding(), weekday_last_thursday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Friday.c_encoding(), weekday_last_friday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Saturday.c_encoding(), weekday_last_saturday.weekday().c_encoding()); + CHECK_EQUAL(Chrono::Sunday.c_encoding(), weekday_last_sunday.weekday().c_encoding()); } } @@ -80,8 +92,8 @@ namespace { for (unsigned i = 8U; i < 256U; ++i) { - auto wd = etl::chrono::weekday(i); - etl::chrono::weekday_last weekday_last(wd); + auto wd = Chrono::weekday(i); + Chrono::weekday_last weekday_last(wd); CHECK_FALSE(weekday_last.ok()); } @@ -90,9 +102,9 @@ namespace //************************************************************************* TEST(test_weekday_last_comparison_operators) { - etl::chrono::weekday_last weekday_last1(etl::chrono::Monday); - etl::chrono::weekday_last weekday_last2(etl::chrono::Monday); - etl::chrono::weekday_last weekday_last3(etl::chrono::Tuesday); + Chrono::weekday_last weekday_last1(Chrono::Monday); + Chrono::weekday_last weekday_last2(Chrono::Monday); + Chrono::weekday_last weekday_last3(Chrono::Tuesday); CHECK_TRUE(weekday_last1 == weekday_last2); CHECK_FALSE(weekday_last1 == weekday_last3); @@ -105,13 +117,13 @@ namespace for (int i = 0; i < 6; ++i) { - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Monday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Tuesday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Wednesday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Thursday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Friday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Saturday))); - hashes.push_back(etl::hash()(etl::chrono::weekday_last(etl::chrono::Sunday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Monday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Tuesday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Wednesday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Thursday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Friday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Saturday))); + hashes.push_back(etl::hash()(Chrono::weekday_last(Chrono::Sunday))); } std::sort(hashes.begin(), hashes.end()); diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index a3b59450a..47de4f708 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -34,9 +34,22 @@ SOFTWARE. #include "etl/chrono.h" -#include #include +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + namespace { SUITE(test_chrono_year) @@ -44,10 +57,9 @@ namespace //************************************************************************* TEST(test_default_constructor) { - std::chrono::year std_year; etl::chrono::year year; - CHECK_EQUAL(std_year.ok(), year.ok()); + CHECK_TRUE(year.ok()); } //************************************************************************* @@ -55,7 +67,6 @@ namespace { for (int32_t i = -32767; i <= 32767; ++i) { - std::chrono::year std_year(i); etl::chrono::year year(i); CHECK_TRUE(year.ok()); @@ -83,189 +94,184 @@ namespace //************************************************************************* TEST(test_post_increment) { - std::chrono::year std_year(-32767); etl::chrono::year year(-32767); + int count = -32767; - for (int32_t i = 0; i < 65536; ++i) + for (int32_t i = 0; i < 65534; ++i) { - std::chrono::year std_last_year = std_year++; - etl::chrono::year last_year = year++; + etl::chrono::year last_year = year++; - CHECK_EQUAL(std_last_year.ok(), last_year.ok()); - CHECK_EQUAL(int(std_last_year), int(last_year)); + CHECK_TRUE(last_year.ok()); + CHECK_EQUAL(count, int(last_year)); + + ++count; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, int(year)); } } //************************************************************************* TEST(test_pre_decrement) { - std::chrono::year std_year(256); etl::chrono::year year(256); + int count = 256; for (int i = 0; i < 255; ++i) { - --std_year; --year; + --count; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, int(year)); } } //************************************************************************* TEST(test_post_decrement) { - std::chrono::year std_year(256); etl::chrono::year year(256); + int count = (int)year; for (int i = 0; i < 255; ++i) { - std::chrono::year std_last_year = std_year--; etl::chrono::year last_year = year--; - CHECK_EQUAL(std_last_year.ok(), last_year.ok()); - CHECK_EQUAL(int(std_last_year), int(last_year)); + CHECK_TRUE(last_year.ok()); + CHECK_EQUAL(count, int(last_year)); + + --count; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(count, int(year)); } } //************************************************************************* TEST(test_plus_equal_years) { - std::chrono::year std_year(0); etl::chrono::year year(0); - - std::chrono::years std_years(2); etl::chrono::years years(2); for (int i = 0; i < 128; ++i) { - std_year += std_years; - year += years; + year += years; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL((2 * i) + 2, int(year)); } } //************************************************************************* TEST(test_year_plus_years) { - std::chrono::year std_year(0); etl::chrono::year year(0); - - std::chrono::years std_years(2); etl::chrono::years years(2); for (int i = 0; i < 128; ++i) { - std_year = std_year + std_years; - year = year + years; + year = year + years; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL((2 * i) + 2, int(year)); } } //************************************************************************* TEST(test_years_plus_year) { - std::chrono::year std_year(0); etl::chrono::year year(0); - - std::chrono::years std_years(2); etl::chrono::years years(2); for (int i = 0; i < 128; ++i) { - std_year = std_years + std_year; - year = years + year; + year = years + year; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL((2 * i) + 2, int(year)); } } //************************************************************************* TEST(test_minus_equal_years) { - std::chrono::year std_year(256); etl::chrono::year year(256); - - std::chrono::years std_years(2); etl::chrono::years years(2); for (int i = 0; i < 128; ++i) { - std_year -= std_years; - year -= years; + year -= years; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL((256 - (2 * i)) - 2, int(year)); } } //************************************************************************* TEST(test_year_minus_years) { - std::chrono::year std_year(0); - etl::chrono::year year(0); - - std::chrono::years std_years(2); + etl::chrono::year year(256); etl::chrono::years years(2); for (int i = 0; i < 128; ++i) { - std_year = std_year - std_years; - year = year - years; + year = year - years; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL((256 - (2 * i)) - 2, int(year)); } } //************************************************************************* TEST(test_year_minus_year) { - for (int i = 1; i < 31; ++i) + etl::chrono::year year(256); + etl::chrono::years years(2); + + for (int i = 0; i < 128; ++i) { - std::chrono::year std_year1(i); - std::chrono::year std_year2(31 - i); + year = years - year; + + CHECK_TRUE(year.ok()); + CHECK_EQUAL((256 - (2 * i)) - 2, int(year)); + } + } - etl::chrono::year year1(i); - etl::chrono::year year2(31 - i); + //************************************************************************* + TEST(test_is_leap) + { + for (int i = -32767; i <= 32767; ++i) + { + bool is_leap = ((i % 4) == 0) && ((i % 400) != 0); - std::chrono::years std_years = std_year1 - std_year2; - etl::chrono::years years = year1 - year2; + etl::chrono::year year(i); - CHECK_EQUAL(std_years.count(), years.count()); + CHECK_EQUAL(is_leap, year.is_leap()); } } + +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_min_max_year) { CHECK_EQUAL(-32767, etl::chrono::year::min()); CHECK_EQUAL(32767, etl::chrono::year::max()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_literal_year) { - using namespace std::literals::chrono_literals; using namespace etl::literals::chrono_literals; - std::chrono::year std_year = 25y; - etl::chrono::year year = 25_year; + etl::chrono::year year = 25_year; - CHECK_EQUAL(std_year.ok(), year.ok()); - CHECK_EQUAL(int(std_year), int(year)); + CHECK_TRUE(year.ok()); + CHECK_EQUAL(25, int(year)); } +#endif //************************************************************************* TEST(test_year_comparison_operators) @@ -275,18 +281,6 @@ namespace CHECK_TRUE(year10 == year10); CHECK_FALSE(year10 != year10); - CHECK_TRUE(year10 < year20); - CHECK_FALSE(year10 < year10); - CHECK_FALSE(year20 < year10); - CHECK_TRUE(year10 <= year20); - CHECK_TRUE(year10 <= year10); - CHECK_FALSE(year20 <= year10); - CHECK_FALSE(year10 > year20); - CHECK_FALSE(year10 > year10); - CHECK_TRUE(year20 > year10); - CHECK_FALSE(year10 >= year20); - CHECK_TRUE(year10 >= year10); - CHECK_TRUE(year20 >= year10); #if ETL_USING_CPP20 CHECK_TRUE((year10 <=> year10) == 0); @@ -295,6 +289,7 @@ namespace #endif } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_year_hashes_are_unique) { @@ -309,5 +304,6 @@ namespace (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(65535U, hashes.size()); } +#endif }; } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 65b50b510..8a7a4374c 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3183,10 +3183,9 @@ + - - @@ -8458,6 +8457,9 @@ + + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index ff4fbc6fb..f868361e2 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1398,12 +1398,6 @@ ETL\Private\chrono - - ETL\Private\chrono - - - ETL\Private\chrono - ETL\Private\chrono @@ -1494,6 +1488,9 @@ ETL\Private\chrono + + ETL\Private\chrono + @@ -3533,6 +3530,15 @@ Tests\Chrono + + Tests\Chrono + + + Tests\Chrono + + + Tests\Chrono + From d604d40648c9cadd5631bd76d111df49d71d2999 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Apr 2025 18:07:43 +0100 Subject: [PATCH 137/216] Added etl::chrono::hh_mm_ss --- include/etl/chrono.h | 18 ++ include/etl/private/chrono/duration.h | 27 ++- include/etl/private/chrono/hh_mm_ss.h | 186 +++++++++++++++ include/etl/private/chrono/month_day.h | 10 +- include/etl/private/chrono/weekday.h | 2 +- test/CMakeLists.txt | 5 + test/test_chrono_hh_mm_ss.cpp | 289 ++++++++++++++++++++++++ test/test_chrono_month.cpp | 3 - test/test_chrono_month_day.cpp | 4 +- test/test_chrono_month_weekday.cpp | 2 - test/test_chrono_month_weekday_last.cpp | 4 +- test/test_chrono_weekday.cpp | 2 + test/test_chrono_year.cpp | 1 + test/vs2022/etl.vcxproj | 13 +- test/vs2022/etl.vcxproj.filters | 12 +- 15 files changed, 553 insertions(+), 25 deletions(-) create mode 100644 include/etl/private/chrono/hh_mm_ss.h create mode 100644 test/test_chrono_hh_mm_ss.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 0c35a8878..84674ea53 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -34,6 +34,7 @@ SOFTWARE. #define ETL_IN_CHRONO_H #include "platform.h" +#include "type_traits.h" #if ETL_NOT_USING_CPP11 #error NOT SUPPORTED FOR C++03 OR BELOW @@ -42,6 +43,22 @@ SOFTWARE. #include +namespace etl +{ + namespace chrono + { + template + struct treat_as_floating_point : etl::is_floating_point + { + }; + +#if ETL_USING_CPP17 + template + constexpr bool treat_as_floating_point_v = treat_as_floating_point::value; +#endif + } +} + #include "private/chrono/last_spec.h" #include "private/chrono/duration.h" #include "private/chrono/day.h" @@ -50,6 +67,7 @@ SOFTWARE. #include "private/chrono/month_day.h" #include "private/chrono/month_weekday.h" #include "private/chrono/year.h" +#include "private/chrono/hh_mm_ss.h" #include "private/chrono/operators.h" #endif diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index df6ee9839..1b9297094 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -130,20 +130,23 @@ namespace etl ETL_CONSTEXPR duration(const etl::chrono::duration& other) ETL_NOEXCEPT : value(etl::chrono::duration_cast >(other).count()) { + ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + } - bool b = etl::ratio_divide::den == 1; + //*********************************************************************** + ETL_CONSTEXPR14 + etl::chrono::duration operator =(const etl::chrono::duration& other) ETL_NOEXCEPT + { + value = other.count(); - ETL_STATIC_ASSERT(!(etl::is_integral::value && etl::is_floating_point::value), "Cannot convert duration from floating point to integral"); + return *this; } //*********************************************************************** template ETL_CONSTEXPR14 - typename etl::enable_if::den == 1, etl::chrono::duration&>::type - operator =(const etl::chrono::duration& other) ETL_NOEXCEPT + etl::chrono::duration operator =(const etl::chrono::duration& other) ETL_NOEXCEPT { - bool b = etl::ratio_divide::den == 1; - value = etl::chrono::duration_cast >(other).count(); return *this; @@ -185,6 +188,12 @@ namespace etl return etl::chrono::duration(etl::chrono::duration_values::max()); } + //*********************************************************************** + ETL_CONSTEXPR etl::chrono::duration absolute() const ETL_NOEXCEPT + { + return etl::chrono::duration(value < 0 ? -value : value); + } + //*********************************************************************** ETL_CONSTEXPR duration& operator ++() { @@ -350,6 +359,12 @@ namespace etl return TToDuration(static_cast((ct_count * ct_num) / ct_den)); } } + + template + struct is_duration : etl::false_type {}; + + template + struct is_duration> : etl::true_type {}; } //************************************************************************* diff --git a/include/etl/private/chrono/hh_mm_ss.h b/include/etl/private/chrono/hh_mm_ss.h new file mode 100644 index 000000000..b987c96d7 --- /dev/null +++ b/include/etl/private/chrono/hh_mm_ss.h @@ -0,0 +1,186 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +#include "../../absolute.h" +#include "../../power.h" + +namespace etl +{ + //*********************************************************************** + /// absolute + /// Enabled for etl::chrono::duration + //*********************************************************************** + template + ETL_NODISCARD + ETL_CONSTEXPR + typename etl::enable_if::value, TDuration>::type + absolute(TDuration dur) ETL_NOEXCEPT + { + return TDuration((dur.count() < 0) ? -dur.count() : dur.count()); + } + + namespace chrono + { + //*********************************************************************** + /// hh_mm_ss + //*********************************************************************** + template + class hh_mm_ss + { + public: + + //*********************************************************************** + // Fractional width for the duration's subseconds + //*********************************************************************** + static constexpr int fractional_width = []() constexpr + { + if (TDuration::period::den == 1) + { + return 0; + } + + int width = 0; + + for (auto den = TDuration::period::den; den > 1; den /= 10) + { + ++width; + } + + return width; + }(); + + //*********************************************************************** + /// The return type for to_duration. + //*********************************************************************** + using precision = etl::chrono::duration, + ratio<1, etl::power<10, fractional_width>::value>>; + + //*********************************************************************** + /// Default constructor. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + hh_mm_ss() ETL_NOEXCEPT + : d(TDuration::zero()) + { + } + + //*********************************************************************** + /// Construct from duration. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + explicit hh_mm_ss(TDuration d_) ETL_NOEXCEPT + : d(d_) + { + } + + //*********************************************************************** + /// Checks for negative duration. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + bool is_negative() const ETL_NOEXCEPT + { + return d < TDuration::zero(); + } + + //*********************************************************************** + /// Returns the hours. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + etl::chrono::hours hours() const ETL_NOEXCEPT + { + auto dur = etl::absolute(d); + + return etl::chrono::duration_cast(dur); + } + + //*********************************************************************** + /// Returns the minutes. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR etl::chrono::minutes minutes() const ETL_NOEXCEPT + { + auto dur = etl::absolute(d) - hours(); + + return etl::chrono::duration_cast(dur); + } + + //*********************************************************************** + /// Returns the seconds. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + etl::chrono::seconds seconds() const ETL_NOEXCEPT + { + auto dur = etl::absolute(d) - hours() - minutes(); + + return etl::chrono::duration_cast(dur); + } + + //*********************************************************************** + /// Returns the subseconds. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR precision subseconds() const ETL_NOEXCEPT + { + return etl::absolute(d) - etl::chrono::duration_cast(etl::absolute(d)); + } + + //*********************************************************************** + /// Returns the duration. + //*********************************************************************** + ETL_CONSTEXPR explicit operator precision() const ETL_NOEXCEPT + { + return to_duration(); + } + + //*********************************************************************** + /// Returns the duration. + //*********************************************************************** + ETL_NODISCARD + ETL_CONSTEXPR + precision to_duration() const ETL_NOEXCEPT + { + return d; + } + + private: + + TDuration d; + }; + } +} diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h index e58f62f0a..171480b4f 100644 --- a/include/etl/private/chrono/month_day.h +++ b/include/etl/private/chrono/month_day.h @@ -116,7 +116,7 @@ namespace etl //************************************************************************* /// Less-than operator. //************************************************************************* - friend ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD friend ETL_CONSTEXPR bool operator <(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT { @@ -137,7 +137,7 @@ namespace etl //************************************************************************* /// Less-than-equal operator. //************************************************************************* - friend ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD friend ETL_CONSTEXPR bool operator <=(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT { @@ -147,7 +147,7 @@ namespace etl //************************************************************************* /// Greater-than operator. //************************************************************************* - friend ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD friend ETL_CONSTEXPR bool operator >(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT { @@ -157,7 +157,7 @@ namespace etl //************************************************************************* /// Greater-than-equal operator. //************************************************************************* - friend ETL_NODISCARD ETL_CONSTEXPR + ETL_NODISCARD friend ETL_CONSTEXPR bool operator >=(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT { @@ -168,7 +168,7 @@ namespace etl /// Spaceship operator //*********************************************************************** #if ETL_USING_CPP20 - friend [[nodiscard]] constexpr auto operator <=>(const etl::chrono::month_day& lhs, + [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) noexcept { auto cmp = lhs.month() <=> rhs.month(); diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index e434ef565..f5e763ef6 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -468,7 +468,7 @@ namespace etl //*********************************************************************** /// Index operator from etl::chrono::last_spec //*********************************************************************** - ETL_CONSTEXPR etl::chrono::weekday_last etl::chrono::weekday::operator[](etl::chrono::last_spec last) const ETL_NOEXCEPT + ETL_CONSTEXPR etl::chrono::weekday_last etl::chrono::weekday::operator[](etl::chrono::last_spec) const ETL_NOEXCEPT { return etl::chrono::weekday_last(*this); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bac997365..d5781a445 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -60,7 +60,12 @@ add_executable(etl_tests # test_checksum.cpp test_chrono_day.cpp test_chrono_duration.cpp + test_chrono_hh_mm_ss.cpp test_chrono_month.cpp + test_chrono_month_day.cpp + test_chrono_month_day_last.cpp + test_chrono_month_weekday.cpp + test_chrono_month_weekday_last.cpp test_chrono_weekday.cpp test_chrono_weekday_indexed.cpp test_chrono_weekday_last.cpp diff --git a/test/test_chrono_hh_mm_ss.cpp b/test/test_chrono_hh_mm_ss.cpp new file mode 100644 index 000000000..887bb42f7 --- /dev/null +++ b/test/test_chrono_hh_mm_ss.cpp @@ -0,0 +1,289 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2025 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono + #define Ratio etl::ratio +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #define Ratio std::ratio + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_hh_mm_ss) + { + //************************************************************************* + TEST(test_default_constructor) + { + using duration_type = Chrono::seconds; + + // Create a duration of 0 hour, 0 minutes, 0 seconds + Chrono::hh_mm_ss time; + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(Chrono::hours(0).count(), h.count()); + CHECK_EQUAL(Chrono::minutes(0).count(), m.count()); + CHECK_EQUAL(Chrono::seconds(0).count(), s.count()); + CHECK_EQUAL(duration_type(0).count(), sub.count()); + CHECK_EQUAL(0, dur.count()); + CHECK_FALSE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_seconds) + { + using duration_type = Chrono::seconds; + + // Create a duration of 1 hour, 2 minutes, 3 seconds + duration_type duration = Chrono::hours(1) + Chrono::minutes(2) + Chrono::seconds(3); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(Chrono::hours(1).count(), h.count()); + CHECK_EQUAL(Chrono::minutes(2).count(), m.count()); + CHECK_EQUAL(Chrono::seconds(3).count(), s.count()); + CHECK_EQUAL(duration_type(0).count(), sub.count()); + CHECK_EQUAL(3723, dur.count()); + CHECK_FALSE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_negative_seconds) + { + using duration_type = Chrono::seconds; + + // Create a duration of minus 1 hour, 2 minutes, 3 seconds + duration_type duration = -(Chrono::hours(1) + Chrono::minutes(2) + Chrono::seconds(3)); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(Chrono::hours(1).count(), h.count()); + CHECK_EQUAL(Chrono::minutes(2).count(), m.count()); + CHECK_EQUAL(Chrono::seconds(3).count(), s.count()); + CHECK_EQUAL(duration_type(0).count(), sub.count()); + CHECK_EQUAL(-3723, dur.count()); + CHECK_TRUE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_milliseconds) + { + using duration_type = Chrono::milliseconds; + + // Create a duration of 1 hour, 2 minutes, 3 seconds, 456 milliseconds + duration_type duration = Chrono::hours(1) + Chrono::minutes(2) + Chrono::seconds(3) + duration_type(456); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(Chrono::hours(1).count(), h.count()); + CHECK_EQUAL(Chrono::minutes(2).count(), m.count()); + CHECK_EQUAL(Chrono::seconds(3).count(), s.count()); + CHECK_EQUAL(duration_type(456).count(), sub.count()); + CHECK_EQUAL(3723456, dur.count()); + CHECK_FALSE(time.is_negative()); + CHECK_EQUAL(3, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_negative_milliseconds) + { + using duration_type = Chrono::milliseconds; + + // Create a duration of minus 1 hour, 2 minutes, 3 seconds, 456 milliseconds + duration_type duration = -(Chrono::hours(1) + Chrono::minutes(2) + Chrono::seconds(3) + duration_type(456)); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(Chrono::hours(1).count(), h.count()); + CHECK_EQUAL(Chrono::minutes(2).count(), m.count()); + CHECK_EQUAL(Chrono::seconds(3).count(), s.count()); + CHECK_EQUAL(duration_type(456).count(), sub.count()); + CHECK_EQUAL(-3723456, dur.count()); + CHECK_TRUE(time.is_negative()); + CHECK_EQUAL(3, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_float_seconds) + { + using duration_type = Chrono::duration>; + + // Create a duration of 1 hour, 2 minutes, 3.456 seconds + duration_type duration = Chrono::hours(1) + Chrono::minutes(2) + duration_type(3.456); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(1, h.count()); + CHECK_EQUAL(2, m.count()); + CHECK_EQUAL(3, s.count()); + CHECK_CLOSE(0.456f, sub.count(), 0.0001f); + CHECK_CLOSE(3723.456f, dur.count(), 0.0001f); + CHECK_FALSE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_negative_float_seconds) + { + using duration_type = Chrono::duration>; + + // Create a duration of 1 hour, 2 minutes, 3.456 seconds + duration_type duration = -(Chrono::hours(1) + Chrono::minutes(2) + duration_type(3.456)); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(1, h.count()); + CHECK_EQUAL(2, m.count()); + CHECK_EQUAL(3, s.count()); + CHECK_CLOSE(0.456f, sub.count(), 0.0001f); + CHECK_CLOSE(-3723.456f, dur.count(), 0.0001f); + CHECK_TRUE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_double_seconds) + { + using duration_type = Chrono::duration>; + + // Create a duration of 1 hour, 2 minutes, 3.456 seconds + duration_type duration = Chrono::hours(1) + Chrono::minutes(2) + duration_type(3.456); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(1, h.count()); + CHECK_EQUAL(2, m.count()); + CHECK_EQUAL(3, s.count()); + CHECK_CLOSE(0.456, sub.count(), 0.0001); + CHECK_CLOSE(3723.456, dur.count(), 0.0001); + CHECK_FALSE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + + //************************************************************************* + TEST(test_construction_with_negative_double_seconds) + { + using duration_type = Chrono::duration>; + + // Create a duration of 1 hour, 2 minutes, 3.456 seconds + duration_type duration = -(Chrono::hours(1) + Chrono::minutes(2) + duration_type(3.456)); + + Chrono::hh_mm_ss time(duration); + + auto h = time.hours(); + auto m = time.minutes(); + auto s = time.seconds(); + auto sub = time.subseconds(); + auto dur = time.to_duration(); + + CHECK_EQUAL(1, h.count()); + CHECK_EQUAL(2, m.count()); + CHECK_EQUAL(3, s.count()); + CHECK_CLOSE(0.456, sub.count(), 0.0001); + CHECK_CLOSE(-3723.456, dur.count(), 0.0001); + CHECK_TRUE(time.is_negative()); + CHECK_EQUAL(0, time.fractional_width); + CHECK_TRUE((std::is_same::precision>::value)); + } + }; +} diff --git a/test/test_chrono_month.cpp b/test/test_chrono_month.cpp index 058f260a0..2a5f25318 100644 --- a/test/test_chrono_month.cpp +++ b/test/test_chrono_month.cpp @@ -258,9 +258,6 @@ namespace Chrono::months months12 = month1 - month2; Chrono::months months21 = month2 - month1; - int m12 = months12.count(); - int m21 = months21.count(); - int difference12 = expected_month(m1) - expected_month(m2); int difference21 = expected_month(m2) - expected_month(m1); diff --git a/test/test_chrono_month_day.cpp b/test/test_chrono_month_day.cpp index af5d00fc0..edd32e0eb 100644 --- a/test/test_chrono_month_day.cpp +++ b/test/test_chrono_month_day.cpp @@ -126,7 +126,7 @@ namespace CHECK_TRUE(md1 == md1); // January == January CHECK_FALSE(md1 == md2); // January != February - CHECK_FALSE(md1 == md2); // 20th != 15th in the same month + CHECK_FALSE(md1 == md3); // 20th != 15th in the same month } //************************************************************************* @@ -138,7 +138,7 @@ namespace CHECK_FALSE(md1 != md1); // January == January CHECK_TRUE(md1 != md2); // January != February - CHECK_TRUE(md1 != md2); // 20th != 15th in the same month + CHECK_TRUE(md1 != md3); // 20th != 15th in the same month } //************************************************************************* diff --git a/test/test_chrono_month_weekday.cpp b/test/test_chrono_month_weekday.cpp index 2b21a88ca..29b532ab2 100644 --- a/test/test_chrono_month_weekday.cpp +++ b/test/test_chrono_month_weekday.cpp @@ -87,7 +87,6 @@ namespace { Chrono::month_weekday mwd1{Chrono::January, Chrono::weekday_indexed(Chrono::Friday, 2)}; Chrono::month_weekday mwd2{Chrono::February, Chrono::weekday_indexed(Chrono::Friday, 2)}; - Chrono::month_weekday mwd3{Chrono::January, Chrono::weekday_indexed(Chrono::Saturday, 2)}; CHECK_TRUE(mwd1 == mwd1); // January == January CHECK_FALSE(mwd1 == mwd2); // January != February @@ -99,7 +98,6 @@ namespace { Chrono::month_weekday mwd1{Chrono::January, Chrono::weekday_indexed(Chrono::Friday, 2)}; Chrono::month_weekday mwd2{Chrono::February, Chrono::weekday_indexed(Chrono::Friday, 2)}; - Chrono::month_weekday mwd3{Chrono::January, Chrono::weekday_indexed(Chrono::Saturday, 2)}; CHECK_FALSE(mwd1 != mwd1); // January == January CHECK_TRUE(mwd1 != mwd2); // January != February diff --git a/test/test_chrono_month_weekday_last.cpp b/test/test_chrono_month_weekday_last.cpp index 1a95d9176..a79fe0e1c 100644 --- a/test/test_chrono_month_weekday_last.cpp +++ b/test/test_chrono_month_weekday_last.cpp @@ -90,7 +90,7 @@ namespace CHECK_TRUE(mwd1 == mwd1); // January == January CHECK_FALSE(mwd1 == mwd2); // January != February - CHECK_FALSE(mwd1 == mwd2); // Friday != Saturday + CHECK_FALSE(mwd1 == mwd3); // Friday != Saturday } //************************************************************************* @@ -102,7 +102,7 @@ namespace CHECK_FALSE(mwd1 != mwd1); // January == January CHECK_TRUE(mwd1 != mwd2); // January != February - CHECK_TRUE(mwd1 != mwd2); // Friday != Saturday + CHECK_TRUE(mwd1 != mwd3); // Friday != Saturday } #if ETL_USING_ETL_CHRONO diff --git a/test/test_chrono_weekday.cpp b/test/test_chrono_weekday.cpp index ec6cedc8d..d6a4a3e8e 100644 --- a/test/test_chrono_weekday.cpp +++ b/test/test_chrono_weekday.cpp @@ -367,6 +367,8 @@ namespace CHECK_TRUE(weekday1 == weekday1); CHECK_FALSE(weekday1 != weekday1); + CHECK_FALSE(weekday1 == weekday2); + CHECK_TRUE(weekday1 != weekday2); } //************************************************************************* diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index 47de4f708..70c17c8a4 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -34,6 +34,7 @@ SOFTWARE. #include "etl/chrono.h" +#include #include // Set to 0 to reference against std::chrono diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 8a7a4374c..90fa9853d 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -1419,7 +1419,7 @@ /Zc:__cplusplus %(AdditionalOptions) true EnableFastChecks - true + false Console @@ -1444,6 +1444,7 @@ ProgramDatabase /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -1470,6 +1471,7 @@ /Zc:__cplusplus %(AdditionalOptions) true Default + false Console @@ -1494,6 +1496,7 @@ ProgramDatabase /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -1518,6 +1521,7 @@ ProgramDatabase /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -1542,6 +1546,7 @@ ProgramDatabase /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -1566,6 +1571,7 @@ EditAndContinue /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -1591,6 +1597,7 @@ /Zc:__cplusplus %(AdditionalOptions) true Default + false Console @@ -1616,6 +1623,7 @@ /Zc:__cplusplus %(AdditionalOptions) true Default + false Console @@ -1825,6 +1833,7 @@ ProgramDatabase /Zc:__cplusplus %(AdditionalOptions) true + false Console @@ -3180,6 +3189,7 @@ + @@ -8455,6 +8465,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index f868361e2..4f5baf9e7 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1491,6 +1491,9 @@ ETL\Private\chrono + + ETL\Private\chrono + @@ -3512,9 +3515,6 @@ Tests\Containers - - Tests - Tests\Chrono @@ -3539,6 +3539,12 @@ Tests\Chrono + + Tests\Chrono + + + Tests\Syntax Checks\Source + From 99d899c11ccfe92cd4b501e97ce20fad8706e76c Mon Sep 17 00:00:00 2001 From: Zach Van Camp Date: Fri, 25 Apr 2025 12:09:13 -0500 Subject: [PATCH 138/216] Add full West support for ETL (#1075) This will allow ETL to be included via west in a zephyr build without any additional wrappers or external kconfigs. Signed-off-by: Zach Van Camp Co-authored-by: Zach Van Camp # Conflicts: # zephyr/module.yml --- zephyr/CMakeLists.txt | 2 ++ zephyr/Kconfig | 5 +++++ zephyr/module.yml | 4 ++++ 3 files changed, 11 insertions(+) create mode 100644 zephyr/CMakeLists.txt create mode 100644 zephyr/Kconfig create mode 100644 zephyr/module.yml diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt new file mode 100644 index 000000000..0dbac030f --- /dev/null +++ b/zephyr/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory_ifdef(CONFIG_ETL ${CMAKE_CURRENT_LIST_DIR}/.. etl) +zephyr_link_interface_ifdef(CONFIG_ETL etl) diff --git a/zephyr/Kconfig b/zephyr/Kconfig new file mode 100644 index 000000000..b54488ace --- /dev/null +++ b/zephyr/Kconfig @@ -0,0 +1,5 @@ +config ETL + bool "ETL (Embedded Template Library)" + depends on CPP + help + This option enables the 'ETL' library. diff --git a/zephyr/module.yml b/zephyr/module.yml new file mode 100644 index 000000000..b292d6a18 --- /dev/null +++ b/zephyr/module.yml @@ -0,0 +1,4 @@ +name: etl +build: + cmake: zephyr + kconfig: zephyr/Kconfig From 4485a90c0497d299b10ad97177da72a4e2b68da7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Apr 2025 19:21:41 +0100 Subject: [PATCH 139/216] Added etl::chrono::year_month --- include/etl/chrono.h | 2 + include/etl/private/chrono/hh_mm_ss.h | 2 + include/etl/private/chrono/year.h | 2 +- include/etl/private/chrono/year_month.h | 233 ++++++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_chrono_operators.cpp | 64 +++++++ test/test_chrono_year_month.cpp | 144 +++++++++++++++ test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 9 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 include/etl/private/chrono/year_month.h create mode 100644 test/test_chrono_operators.cpp create mode 100644 test/test_chrono_year_month.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 84674ea53..2d20db826 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -35,6 +35,7 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" +#include "integral_limits.h" #if ETL_NOT_USING_CPP11 #error NOT SUPPORTED FOR C++03 OR BELOW @@ -67,6 +68,7 @@ namespace etl #include "private/chrono/month_day.h" #include "private/chrono/month_weekday.h" #include "private/chrono/year.h" +#include "private/chrono/year_month.h" #include "private/chrono/hh_mm_ss.h" #include "private/chrono/operators.h" #endif diff --git a/include/etl/private/chrono/hh_mm_ss.h b/include/etl/private/chrono/hh_mm_ss.h index b987c96d7..90b9eeb77 100644 --- a/include/etl/private/chrono/hh_mm_ss.h +++ b/include/etl/private/chrono/hh_mm_ss.h @@ -60,6 +60,8 @@ namespace etl { public: + ETL_STATIC_ASSERT(etl::chrono::is_duration::value, "TDuration not etl::chrono::duration"); + //*********************************************************************** // Fractional width for the duration's subseconds //*********************************************************************** diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index 84306f784..df90770d6 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -144,7 +144,7 @@ namespace etl //*********************************************************************** ETL_CONSTEXPR bool ok() const ETL_NOEXCEPT { - return (value != -32768); + return (value != etl::integral_limits::min); } //*********************************************************************** diff --git a/include/etl/private/chrono/year_month.h b/include/etl/private/chrono/year_month.h new file mode 100644 index 000000000..3c76033b6 --- /dev/null +++ b/include/etl/private/chrono/year_month.h @@ -0,0 +1,233 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2023 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + class year_month + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + year_month() + : y(etl::integral_limits::min) + , m(0) + { + } + + //************************************************************************* + /// Construct from month and day. + //************************************************************************* + ETL_CONSTEXPR year_month(const etl::chrono::year& y_, const etl::chrono::month& m_) ETL_NOEXCEPT + : y(y_) + , m(m_) + { + } + + //************************************************************************* + /// Returns the year. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year year() const ETL_NOEXCEPT + { + return y; + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns true if the month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + return y.ok() && m.ok(); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() + dy, ym.month()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::years& dy, + const etl::chrono::year_month& ym) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() + dy, ym.month()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::year_month& ym, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() + dm); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator +(const etl::chrono::months& dm, + const etl::chrono::year_month& ym) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() + dm); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year() - dy, ym.month()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month operator -(const etl::chrono::year_month& ym, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month(ym.year(), ym.month() - dm); + } + + //************************************************************************* + /// Subtracts etl::chrono::year_month + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::months operator -(const etl::chrono::year_month& ym1, + const etl::chrono::year_month& ym2) ETL_NOEXCEPT + { + return etl::chrono::months(static_cast(((int(ym1.year()) - int(ym2.year())) * 12) + (unsigned(ym1.month()) - unsigned(ym2.month())))); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return (lhs.y == rhs.y) && (lhs.m == rhs.m); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month& lhs, + const etl::chrono::year_month& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year()<=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.month() <=> rhs.month(); + } + } +#endif + + //*********************************************************************** + /// Compare year_month with another. + /// if month < other.month, returns -1; + /// else if month > other.month, returns 1; + /// else if day < other.day, returns -1; + /// else if day > other.day, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const year_month& other) const ETL_NOEXCEPT + { + if (y < other.y) return -1; + if (y > other.y) return 1; + if (m < other.m) return -1; + if (m > other.m) return 1; + + return 0; + } + + private: + + etl::chrono::year y; + etl::chrono::month m; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::year_month + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year_month& md) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int y = md.year(); + unsigned int m = md.month(); + + memcpy(buffer, &y, sizeof(y)); + memcpy(buffer + sizeof(y), &m, sizeof(m)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d5781a445..5729a1b79 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -70,6 +70,7 @@ add_executable(etl_tests test_chrono_weekday_indexed.cpp test_chrono_weekday_last.cpp test_chrono_year.cpp + test_chrono_year_month.cpp # test_circular_buffer.cpp # test_circular_buffer_external_buffer.cpp # test_circular_iterator.cpp diff --git a/test/test_chrono_operators.cpp b/test/test_chrono_operators.cpp new file mode 100644 index 000000000..30e398d34 --- /dev/null +++ b/test/test_chrono_operators.cpp @@ -0,0 +1,64 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2025 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_operators) + { + //************************************************************************* + TEST(test_operator_for_year_month) + { + + } + }; +} diff --git a/test/test_chrono_year_month.cpp b/test/test_chrono_year_month.cpp new file mode 100644 index 000000000..bd3a87f5f --- /dev/null +++ b/test/test_chrono_year_month.cpp @@ -0,0 +1,144 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2024 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_year_month) + { + //************************************************************************* + TEST(test_default_constructor) + { + Chrono::year_month ym; + + CHECK_FALSE(ym.ok()); // Default-constructed year_month is not valid + } + + //************************************************************************* + TEST(test_constructor_with_month_and_day) + { + Chrono::year_month ym{Chrono::year(2000), Chrono::January}; + + CHECK_TRUE(ym.ok()); // Valid year_month + CHECK_EQUAL(2000, (int)ym.year()); + CHECK_EQUAL((unsigned)Chrono::January, (unsigned)ym.month()); + } + + //************************************************************************* + TEST(test_invalid_year_month) + { + Chrono::year_month ym{Chrono::year{32768}, Chrono::January}; // Invalid year + + CHECK_FALSE(ym.ok()); // Invalid year_month + } + + //************************************************************************* + TEST(test_invalid_month_in_year_month) + { + Chrono::year_month ym{Chrono::year{2000}, Chrono::month{13}}; // Invalid month (13) + + CHECK_FALSE(ym.ok()); // Invalid year_month + } + +#if ETL_USING_CPP20 + //************************************************************************* + TEST(test_year_month_spaceship_operator) + { + Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::January}; + + CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::equal); + CHECK_TRUE((ym1 <=> ym2) == std::strong_ordering::less); + CHECK_TRUE((ym2 <=> ym1) == std::strong_ordering::greater); + } +#endif + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_year_month_compare) + { + Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::January}; + + CHECK_TRUE(ym1.compare(ym3) == 0); + CHECK_TRUE(ym1.compare(ym2) == -1); + CHECK_TRUE(ym2.compare(ym1) == 1); + } +#endif + + //************************************************************************* + TEST(test_year_month_equality_operator) + { + Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; + + CHECK_TRUE(ym1 == ym1); // 2000/January + CHECK_FALSE(ym1 == ym2); // 2000/January != 2001/February + CHECK_FALSE(ym1 == ym3); // 2000/January != 2000/February + } + + //************************************************************************* + TEST(test_year_month_not_equality_operator) + { + Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; + + CHECK_FALSE(ym1 != ym1); // 2000/January + CHECK_TRUE(ym1 != ym2); // 2000/January != 2001/February + CHECK_TRUE(ym1 != ym3); // 2000/January != 2000/February + } + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 90fa9853d..af492705f 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3197,6 +3197,7 @@ + @@ -8475,6 +8476,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 4f5baf9e7..02a498510 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1494,6 +1494,9 @@ ETL\Private\chrono + + ETL\Private\chrono + @@ -3545,6 +3548,9 @@ Tests\Syntax Checks\Source + + Tests\Chrono + From 279ce8f0dc20c5f8dd7260fbbcb4226531499cca Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 27 Apr 2025 20:22:45 +0100 Subject: [PATCH 140/216] Added more chrono classes and operators --- include/etl/chrono.h | 6 +- include/etl/private/chrono/month.h | 13 + include/etl/private/chrono/month_day.h | 8 +- include/etl/private/chrono/month_weekday.h | 6 +- include/etl/private/chrono/operators.h | 437 +++++++++----- include/etl/private/chrono/system_clock.h | 51 ++ include/etl/private/chrono/time_point.h | 232 ++++++++ include/etl/private/chrono/weekday.h | 2 +- include/etl/private/chrono/year.h | 4 +- include/etl/private/chrono/year_month.h | 7 +- include/etl/private/chrono/year_month_day.h | 538 ++++++++++++++++++ .../etl/private/chrono/year_month_weekday.h | 518 +++++++++++++++++ test/test_chrono_month_day_last.cpp | 13 + test/test_chrono_operators.cpp | 256 ++++++++- test/test_chrono_year.cpp | 2 +- test/vs2022/etl.vcxproj | 5 + test/vs2022/etl.vcxproj.filters | 15 + 17 files changed, 1934 insertions(+), 179 deletions(-) create mode 100644 include/etl/private/chrono/system_clock.h create mode 100644 include/etl/private/chrono/time_point.h create mode 100644 include/etl/private/chrono/year_month_day.h create mode 100644 include/etl/private/chrono/year_month_weekday.h diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 2d20db826..8fce7d574 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -60,8 +60,10 @@ namespace etl } } +#include "private/chrono/time_point.h" #include "private/chrono/last_spec.h" #include "private/chrono/duration.h" +#include "private/chrono/system_clock.h" #include "private/chrono/day.h" #include "private/chrono/weekday.h" #include "private/chrono/month.h" @@ -69,8 +71,10 @@ namespace etl #include "private/chrono/month_weekday.h" #include "private/chrono/year.h" #include "private/chrono/year_month.h" +#include "private/chrono/year_month_day.h" +#include "private/chrono/year_month_weekday.h" #include "private/chrono/hh_mm_ss.h" -#include "private/chrono/operators.h" +#include "private/chrono/operators.h" #endif #undef ETL_IN_CHRONO_H diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 1359c5557..5b1e3678d 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -42,6 +42,11 @@ namespace etl ETL_CONSTEXPR etl::chrono::month operator +(const etl::chrono::months& ms, const etl::chrono::month& m) ETL_NOEXCEPT; ETL_CONSTEXPR etl::chrono::month operator -(const etl::chrono::month& m, const etl::chrono::months& ms) ETL_NOEXCEPT; + namespace private_chrono + { + static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + } + //*********************************************************************** /// month //*********************************************************************** @@ -380,6 +385,14 @@ namespace etl return m; } + //************************************************************************* + /// Returns the last day of the month + //************************************************************************* + ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT + { + return etl::chrono::day(private_chrono::days_in_month[static_cast(m)]); + } + //************************************************************************* /// Is the contained month OK? //************************************************************************* diff --git a/include/etl/private/chrono/month_day.h b/include/etl/private/chrono/month_day.h index 171480b4f..97ce4defe 100644 --- a/include/etl/private/chrono/month_day.h +++ b/include/etl/private/chrono/month_day.h @@ -36,11 +36,6 @@ namespace etl { namespace chrono { - namespace private_chrono - { - static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - } - class month_day { public: @@ -53,7 +48,8 @@ namespace etl //************************************************************************* /// Construct from month and day. //************************************************************************* - ETL_CONSTEXPR month_day(const etl::chrono::month& m_, const etl::chrono::day& d_) ETL_NOEXCEPT + ETL_CONSTEXPR month_day(const etl::chrono::month& m_, + const etl::chrono::day& d_) ETL_NOEXCEPT : m(m_) , d(d_) { diff --git a/include/etl/private/chrono/month_weekday.h b/include/etl/private/chrono/month_weekday.h index e1f99d95f..a7d895fc0 100644 --- a/include/etl/private/chrono/month_weekday.h +++ b/include/etl/private/chrono/month_weekday.h @@ -43,7 +43,8 @@ namespace etl //************************************************************************* /// Construct from month and weekday_indexed. //************************************************************************* - ETL_CONSTEXPR month_weekday(const etl::chrono::month& m_, const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT + ETL_CONSTEXPR month_weekday(const etl::chrono::month& m_, + const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT : m(m_) , wdi(wdi_) { @@ -107,7 +108,8 @@ namespace etl //************************************************************************* /// Construct from month and weekday_indexed. //************************************************************************* - ETL_CONSTEXPR month_weekday_last(const etl::chrono::month& m_, const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT + ETL_CONSTEXPR month_weekday_last(const etl::chrono::month& m_, + const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT : m(m_) , wdl(wdl_) { diff --git a/include/etl/private/chrono/operators.h b/include/etl/private/chrono/operators.h index 169217e7f..7872c88cb 100644 --- a/include/etl/private/chrono/operators.h +++ b/include/etl/private/chrono/operators.h @@ -36,154 +36,293 @@ namespace etl { namespace chrono { - //// year_month - //constexpr auto operator/(const etl::chrono::year& y, - // const etl::chrono::month& m ) noexcept - // -> etl::chrono::year_month; - - //constexpr auto operator/( const etl::chrono::year& y, int m ) noexcept - // -> etl::chrono::year_month; - - //// month_day - //constexpr auto operator/( const etl::chrono::month& m, - // const etl::chrono::day& d ) noexcept - // -> etl::chrono::month_day; - - //constexpr auto operator/( const etl::chrono::month& m, int d ) noexcept - // -> etl::chrono::month_day; - - //constexpr auto operator/( int m, const etl::chrono::day& d ) noexcept - // -> etl::chrono::month_day; - - //constexpr auto operator/( const etl::chrono::day& d, - // const etl::chrono::month& m ) noexcept - // -> etl::chrono::month_day; - - //constexpr auto operator/( const etl::chrono::day& d, int m ) noexcept - // -> etl::chrono::month_day; - - //// month_day_last - //constexpr auto operator/( const etl::chrono::month& m, - // etl::chrono::last_spec ) noexcept - // -> etl::chrono::month_day_last; - - //constexpr auto operator/( int m, etl::chrono::last_spec ) noexcept - // -> etl::chrono::month_day_last; - - //constexpr auto operator/( etl::chrono::last_spec, - // const etl::chrono::month& m ) noexcept - // -> etl::chrono::month_day_last; - - //constexpr auto operator/( etl::chrono::last_spec, int m ) noexcept - // -> etl::chrono::month_day_last; - - //// month_weekday - //constexpr auto operator/( const etl::chrono::month& m, - // const etl::chrono::weekday_indexed& wdi ) noexcept - // -> etl::chrono::month_weekday; - - //constexpr auto operator/( int m, const etl::chrono::weekday_indexed& wdi ) noexcept - // -> etl::chrono::month_weekday; - - //constexpr auto operator/(const etl::chrono::weekday_indexed& wdi, - // const etl::chrono::month& m ) noexcept - // -> etl::chrono::month_weekday; - - //constexpr auto operator/( const etl::chrono::weekday_indexed& wdi, int m ) noexcept - // -> etl::chrono::month_weekday; - - //// month_weekday_last - //constexpr auto operator/( const etl::chrono::month& m, - // const etl::chrono::weekday_last& wdl ) noexcept - // -> etl::chrono::month_weekday_last; - - //constexpr auto operator/( int m, const etl::chrono::weekday_last& wdl ) noexcept - // -> etl::chrono::month_weekday_last; - - //constexpr auto operator/( const etl::chrono::weekday_last& wdl, - // const etl::chrono::month& m ) noexcept - // -> etl::chrono::month_weekday_last; - - //constexpr auto operator/( const etl::chrono::weekday_last& wdl, int m ) noexcept - // -> etl::chrono::month_weekday_last; - - //// year_month_day - //constexpr auto operator/( const etl::chrono::year_month& ym, - // const etl::chrono::day& d ) noexcept - // -> etl::chrono::year_month_day; - - //constexpr auto operator/( const etl::chrono::year_month& ym, int d ) noexcept - // -> etl::chrono::year_month_day; - - //constexpr auto operator/( const etl::chrono::year& y, - // const etl::chrono::month_day& md ) noexcept - // -> etl::chrono::year_month_day; - - //constexpr auto operator/( int y, const etl::chrono::month_day& md ) noexcept - // -> etl::chrono::year_month_day; - - //constexpr auto operator/( const etl::chrono::month_day& md, - // const etl::chrono::year& y ) noexcept - // -> etl::chrono::year_month_day; - - //constexpr auto operator/( const etl::chrono::month_day& md, int y ) noexcept - // -> etl::chrono::year_month_day; - - //// year_month_day_last - //constexpr auto operator/( const etl::chrono::year_month& ym, - // etl::chrono::last_spec ) noexcept - // -> etl::chrono::year_month_day_last; - - //constexpr auto operator/( const etl::chrono::year& y, - // const etl::chrono::month_day_last& mdl ) noexcept - // -> etl::chrono::year_month_day_last; - - //constexpr auto operator/( int y, const etl::chrono::month_day_last& mdl ) noexcept - // -> etl::chrono::year_month_day_last; - - //constexpr auto operator/( const etl::chrono::month_day_last& mdl, - // const etl::chrono::year& y ) noexcept - // -> etl::chrono::year_month_day_last; - - //constexpr auto operator/( const etl::chrono::month_day_last& mdl, int y ) noexcept - // -> etl::chrono::year_month_day_last; - - //// year_month_weekday - //constexpr auto operator/( const etl::chrono::year_month& ym, - // const etl::chrono::weekday_indexed& wdi ) noexcept - // -> etl::chrono::year_month_weekday; - - //constexpr auto operator/( const etl::chrono::year& y, - // const etl::chrono::month_weekday& mwd ) noexcept - // -> etl::chrono::year_month_weekday; - - //constexpr auto operator/( int y, const etl::chrono::month_weekday& mwd ) noexcept - // -> etl::chrono::year_month_weekday; - - //constexpr auto operator/( const etl::chrono::month_weekday& mwd, - // const etl::chrono::year& y ) noexcept - // -> etl::chrono::year_month_weekday; - - //constexpr auto operator/( const etl::chrono::month_weekday& mwd, int y ) noexcept - // -> etl::chrono::year_month_weekday; - - //// year_month_weekday_last - //constexpr auto operator/( const etl::chrono::year_month& ym, - // const etl::chrono::weekday_last& wdl ) noexcept - // -> etl::chrono::year_month_weekday_last; - - //constexpr auto operator/( const etl::chrono::year& y, - // const etl::chrono::month_weekday_last& mwdl ) noexcept - // -> etl::chrono::year_month_weekday_last; - - //constexpr auto operator/( int y, const etl::chrono::month_weekday_last& mwdl ) noexcept - // -> etl::chrono::year_month_weekday_last; - - //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, - // const etl::chrono::year& y ) noexcept - // -> etl::chrono::year_month_weekday_last; - - //constexpr auto operator/( const etl::chrono::month_weekday_last& mwdl, int y ) noexcept - // -> etl::chrono::year_month_weekday_last; + //************************************************************************* + // month_day + ETL_CONSTEXPR14 etl::chrono::month_day operator /(const etl::chrono::month& m, + const etl::chrono::day& d) ETL_NOEXCEPT + { + return etl::chrono::month_day(m, d); + } + + // month_day + ETL_CONSTEXPR14 etl::chrono::month_day operator /(const etl::chrono::month& m, + int d) ETL_NOEXCEPT + { + return etl::chrono::month_day(m, etl::chrono::day(d)); + } + + // month_day + ETL_CONSTEXPR14 etl::chrono::month_day operator /(int m, + const etl::chrono::day& d) ETL_NOEXCEPT + { + return etl::chrono::month_day(etl::chrono::month(m), d); + } + + // month_day + ETL_CONSTEXPR14 etl::chrono::month_day operator /(const etl::chrono::day& d, + const etl::chrono::month& m) ETL_NOEXCEPT + { + return etl::chrono::month_day(m, d); + } + + // month_day + ETL_CONSTEXPR14 etl::chrono::month_day operator /(const etl::chrono::day& d, + int m) ETL_NOEXCEPT + { + return etl::chrono::month_day(etl::chrono::month(m), d); + } + + //************************************************************************* + // month_day_last + ETL_CONSTEXPR14 etl::chrono::month_day_last operator /(const etl::chrono::month& m, + etl::chrono::last_spec) ETL_NOEXCEPT + { + return etl::chrono::month_day_last(m); + } + + // month_day_last + ETL_CONSTEXPR14 etl::chrono::month_day_last operator /(int m, + etl::chrono::last_spec) ETL_NOEXCEPT + { + return etl::chrono::month_day_last(etl::chrono::month(m)); + } + + // month_day_last + ETL_CONSTEXPR14 etl::chrono::month_day_last operator /(etl::chrono::last_spec, + const etl::chrono::month& m) ETL_NOEXCEPT + { + return etl::chrono::month_day_last(m); + } + + // month_day_last + ETL_CONSTEXPR14 etl::chrono::month_day_last operator/(etl::chrono::last_spec, + int m) ETL_NOEXCEPT + { + return etl::chrono::month_day_last(etl::chrono::month(m)); + } + + //************************************************************************* + // month_weekday + ETL_CONSTEXPR14 etl::chrono::month_weekday operator /(const etl::chrono::month& m, + const etl::chrono::weekday_indexed& wdi) ETL_NOEXCEPT + { + return etl::chrono::month_weekday(m, wdi); + } + + // month_weekday + ETL_CONSTEXPR14 etl::chrono::month_weekday operator /(int m, + const etl::chrono::weekday_indexed& wdi) ETL_NOEXCEPT + { + return etl::chrono::month_weekday(etl::chrono::month(m), wdi); + } + + // month_weekday + ETL_CONSTEXPR14 etl::chrono::month_weekday operator /(const etl::chrono::weekday_indexed& wdi, + const etl::chrono::month& m) ETL_NOEXCEPT + { + return etl::chrono::month_weekday(m, wdi); + } + + // month_weekday + ETL_CONSTEXPR14 etl::chrono::month_weekday operator /(const etl::chrono::weekday_indexed& wdi, + int m) ETL_NOEXCEPT + { + return etl::chrono::month_weekday(etl::chrono::month(m), wdi); + } + + //************************************************************************* + // month_weekday_last + ETL_CONSTEXPR14 etl::chrono::month_weekday_last operator /(const etl::chrono::month& m, + const etl::chrono::weekday_last& wdl) ETL_NOEXCEPT + { + return etl::chrono::month_weekday_last(m, wdl); + } + + // month_weekday_last + ETL_CONSTEXPR14 etl::chrono::month_weekday_last operator /(int m, + const etl::chrono::weekday_last& wdl) ETL_NOEXCEPT + { + return etl::chrono::month_weekday_last(etl::chrono::month(m), wdl); + } + + // month_weekday_last + ETL_CONSTEXPR14 etl::chrono::month_weekday_last operator /(const etl::chrono::weekday_last& wdl, + const etl::chrono::month& m) ETL_NOEXCEPT + { + return etl::chrono::month_weekday_last(m, wdl); + } + + // month_weekday_last + ETL_CONSTEXPR14 etl::chrono::month_weekday_last operator /(const etl::chrono::weekday_last& wdl, + int m) ETL_NOEXCEPT + { + return etl::chrono::month_weekday_last(etl::chrono::month(m), wdl); + } + + //************************************************************************* + // year_month + ETL_CONSTEXPR14 etl::chrono::year_month operator /(const etl::chrono::year& y, + const etl::chrono::month& m) ETL_NOEXCEPT + { + return etl::chrono::year_month(y, m); + } + + // year_month + ETL_CONSTEXPR14 etl::chrono::year_month operator /(const etl::chrono::year& y, + int m) ETL_NOEXCEPT + { + return etl::chrono::year_month(y, etl::chrono::month(m)); + } + + ////************************************************************************* + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::year_month& ym, + const etl::chrono::day& d) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ym.year(), ym.month(), d); + } + + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::year_month& ym, + int d ) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ym.year(), ym.month(), etl::chrono::day(d)); + } + + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::year& y, + const etl::chrono::month_day& md) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(y, md.month(), md.day()); + } + + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator/(int y, + const etl::chrono::month_day& md) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(etl::chrono::year(y), md.month(), md.day()); + } + + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::month_day& md, + const etl::chrono::year& y) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(y, md.month(), md.day()); + } + + // year_month_day + ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::month_day& md, + int y) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(etl::chrono::year(y), md.month(), md.day()); + } + + //************************************************************************* + // year_month_day_last + ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator /(const etl::chrono::year_month& ym, + etl::chrono::last_spec) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ym.year(), etl::chrono::month_day_last(ym.month())); + } + + // year_month_day_last + ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator /(const etl::chrono::year& y, + const etl::chrono::month_day_last& mdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(y, mdl); + } + + // year_month_day_last + ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator /(int y, + const etl::chrono::month_day_last& mdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(etl::chrono::year(y), mdl); + } + + // year_month_day_last + ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator /(const etl::chrono::month_day_last& mdl, + const etl::chrono::year& y) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(y, mdl); + } + + // year_month_day_last + ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator /(const etl::chrono::month_day_last& mdl, + int y) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(etl::chrono::year(y), mdl); + } + + //************************************************************************* + // year_month_weekday + ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator /(const etl::chrono::year_month& ym, + const etl::chrono::weekday_indexed& wdi) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ym.year(), ym.month(), wdi); + } + + // year_month_weekday + ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator /(const etl::chrono::year& y, + const etl::chrono::month_weekday& mwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(y, mwd.month(), mwd.weekday_indexed()); + } + + // year_month_weekday + ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator/(int y, + const etl::chrono::month_weekday& mwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(etl::chrono::year(y), mwd.month(), mwd.weekday_indexed()); + } + + // year_month_weekday + ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator /(const etl::chrono::month_weekday& mwd, + const etl::chrono::year& y) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(y, mwd.month(), mwd.weekday_indexed()); + } + + // year_month_weekday + ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator /(const etl::chrono::month_weekday& mwd, + int y) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(etl::chrono::year(y), mwd.month(), mwd.weekday_indexed()); + } + + //************************************************************************* + // year_month_weekday_last + ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator /(const etl::chrono::year_month& ym, + const etl::chrono::weekday_last& wdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ym.year(), ym.month(), wdl); + } + + // year_month_weekday_last + ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator /(const etl::chrono::year& y, + const etl::chrono::month_weekday_last& mwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last()); + } + + // year_month_weekday_last + ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator/(int y, + const etl::chrono::month_weekday_last& mwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(etl::chrono::year(y), mwdl.month(), mwdl.weekday_last()); + } + + // year_month_weekday_last + ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator /(const etl::chrono::month_weekday_last& mwdl, + const etl::chrono::year& y) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(y, mwdl.month(), mwdl.weekday_last()); + } + + // year_month_weekday_last + ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator /(const etl::chrono::month_weekday_last& mwdl, + int y) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(etl::chrono::year(y), mwdl.month(), mwdl.weekday_last()); + } } } \ No newline at end of file diff --git a/include/etl/private/chrono/system_clock.h b/include/etl/private/chrono/system_clock.h new file mode 100644 index 000000000..993413134 --- /dev/null +++ b/include/etl/private/chrono/system_clock.h @@ -0,0 +1,51 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + class system_clock + { + + }; + + template + using sys_time = etl::chrono::time_point; + + using sys_seconds = sys_time; + + using sys_days = sys_time; + } +} diff --git a/include/etl/private/chrono/time_point.h b/include/etl/private/chrono/time_point.h new file mode 100644 index 000000000..0d48acb36 --- /dev/null +++ b/include/etl/private/chrono/time_point.h @@ -0,0 +1,232 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //*************************************************************************** + /// Represents a point in time storing a TDuration indicating the time + /// interval from the start of the TClock's epoch. + //*************************************************************************** + template + class time_point + { + public: + + using clock = TClock; + using duration = TDuration; + using rep = typename TDuration::rep; + using period = typename TDuration::period; + + //*************************************************************************** + /// Default constructor. + //*************************************************************************** + ETL_CONSTEXPR time_point() ETL_NOEXCEPT + : dur(duration::zero()) + { + } + + //*************************************************************************** + /// Construct from a duration. + //*************************************************************************** + ETL_CONSTEXPR explicit time_point(const duration& dur_) ETL_NOEXCEPT + : dur(dur_) + { + } + + //*************************************************************************** + /// Copy constructor. + //*************************************************************************** + ETL_CONSTEXPR time_point(const time_point& rhs) ETL_NOEXCEPT + : dur(rhs.dur) + { + } + + //*************************************************************************** + /// Copy construct from another time_point with a different duration type. + //*************************************************************************** + template + explicit time_point(const time_point& rhs) ETL_NOEXCEPT + : dur(rhs.time_since_epoch()) + { + } + + //*************************************************************************** + /// Assignment operator. + //*************************************************************************** + time_point& operator =(const time_point& rhs) ETL_NOEXCEPT + { + dur = rhs.dur; + + return *this; + } + + //*************************************************************************** + /// Returns a duration representing the amount of time between this and the clock's epoch. + //*************************************************************************** + ETL_CONSTEXPR duration time_since_epoch() const ETL_NOEXCEPT + { + return dur; + } + + //*************************************************************************** + /// Adds a duration. + //*************************************************************************** + time_point& operator +=(const duration& rhs) ETL_NOEXCEPT + { + dur += rhs; + + return *this; + } + + //*************************************************************************** + /// Subtracts a duration. + //*************************************************************************** + time_point& operator -=(const duration& rhs) ETL_NOEXCEPT + { + dur -= rhs; + + return *this; + } + + //*************************************************************************** + /// Returns a time_point with the smallest possible duration. + //*************************************************************************** + static ETL_CONSTEXPR time_point min() ETL_NOEXCEPT + { + return time_point(duration::min()); + } + + //*************************************************************************** + /// Returns a time_point with the largest possible duration. + //*************************************************************************** + static ETL_CONSTEXPR time_point max() ETL_NOEXCEPT + { + return time_point(duration::max()); + } + + private: + + duration dur; + }; + + //*************************************************************************** + /// Equality operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator ==(const time_point& lhs, const time_point& rhs) + { + return lhs.time_since_epoch() == rhs.time_since_epoch(); + } + + //*************************************************************************** + /// Inequality operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator !=(const time_point& lhs, const time_point& rhs) + { + return !(lhs == rhs); + } + + //*************************************************************************** + /// Less-than operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator <(const time_point& lhs, const time_point& rhs) + { + return lhs.time_since_epoch() < rhs.time_since_epoch(); + } + + //*************************************************************************** + /// Less-than-equal operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator <=(const time_point& lhs, const time_point& rhs) + { + return !(rhs < lhs); + } + + //*************************************************************************** + /// Greater-than operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator >(const time_point& lhs, const time_point& rhs) + { + return rhs < lhs; + } + + //*************************************************************************** + /// Greater-than-equal operator + //*************************************************************************** + template + ETL_CONSTEXPR bool operator >=(const time_point& lhs, const time_point& rhs) + { + return !(lhs < rhs); + } + + //*************************************************************************** + /// Local time + //*************************************************************************** + //struct local_t + //{ + // using rep = size_t; + // using period = etl::chrono::seconds; + // using duration = etl::chrono::duration; + // using time_point = etl::chrono::time_point; + + // const bool is_steady = true; + + // time_point now() + // { + // return time_point(); + // } + //}; + + //template + //using local_time = etl::chrono::time_point; + + //using local_seconds = local_time; + //using local_days = local_time; + } + + //*************************************************************************** + /// Defines type, which is the common type of two std::chrono::time_points. + //*************************************************************************** + template + struct common_type, etl::chrono::time_point> + { + using type = etl::chrono::time_point::type>; + }; +} diff --git a/include/etl/private/chrono/weekday.h b/include/etl/private/chrono/weekday.h index f5e763ef6..794edbcee 100644 --- a/include/etl/private/chrono/weekday.h +++ b/include/etl/private/chrono/weekday.h @@ -384,7 +384,7 @@ namespace etl ETL_CONSTEXPR bool operator ==(const etl::chrono::weekday_indexed& wd1, const etl::chrono::weekday_indexed& wd2) ETL_NOEXCEPT { return (wd1.weekday() == wd2.weekday()) && - (wd1.index() == wd2.index()); + (wd1.index() == wd2.index()); } //*********************************************************************** diff --git a/include/etl/private/chrono/year.h b/include/etl/private/chrono/year.h index df90770d6..ce723be2f 100644 --- a/include/etl/private/chrono/year.h +++ b/include/etl/private/chrono/year.h @@ -168,7 +168,9 @@ namespace etl //*********************************************************************** ETL_CONSTEXPR bool is_leap() const ETL_NOEXCEPT { - return ((value % 4) == 0) && !((value % 400) == 0); + return ((value % 4) == 0) && // Divisible by 4 + (((value % 100) != 0) || // but not divisible by 100 + ((value % 400) == 0)); // unless divisible by 400 } //*********************************************************************** diff --git a/include/etl/private/chrono/year_month.h b/include/etl/private/chrono/year_month.h index 3c76033b6..ef4ebe186 100644 --- a/include/etl/private/chrono/year_month.h +++ b/include/etl/private/chrono/year_month.h @@ -44,15 +44,16 @@ namespace etl /// Default constructor. //************************************************************************* year_month() - : y(etl::integral_limits::min) - , m(0) + : y() + , m() { } //************************************************************************* /// Construct from month and day. //************************************************************************* - ETL_CONSTEXPR year_month(const etl::chrono::year& y_, const etl::chrono::month& m_) ETL_NOEXCEPT + ETL_CONSTEXPR year_month(const etl::chrono::year& y_, + const etl::chrono::month& m_) ETL_NOEXCEPT : y(y_) , m(m_) { diff --git a/include/etl/private/chrono/year_month_day.h b/include/etl/private/chrono/year_month_day.h new file mode 100644 index 000000000..101dcfb3d --- /dev/null +++ b/include/etl/private/chrono/year_month_day.h @@ -0,0 +1,538 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //************************************************************************* + /// year_month_day + //************************************************************************* + class year_month_day + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + year_month_day() + : y() + , m() + , d() + { + } + + //************************************************************************* + /// Construct from month and day. + //************************************************************************* + ETL_CONSTEXPR year_month_day(const etl::chrono::year& y_, + const etl::chrono::month& m_, + const etl::chrono::day& d_) ETL_NOEXCEPT + : y(y_) + , m(m_) + , d(d_) + { + } + + //************************************************************************* + /// Returns the year. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year year() const ETL_NOEXCEPT + { + return y; + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the day. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT + { + return d; + } + + //************************************************************************* + /// Returns true if the year/month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + // Check if the year, month, and day are valid individually + return y.ok() && + m.ok() && + d.ok() && + d <= etl::chrono::month_day_last(m).day(); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() + dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ymd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_day& ymd) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() + dm, ymd.day()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year() - dy, ymd.month(), ymd.day()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day operator -(const etl::chrono::year_month_day& ymd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day(ymd.year(), ymd.month() - dm, ymd.day()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.d == rhs.d); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_day& lhs, + const etl::chrono::year_month_day& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year() <=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + + cmp = lhs.month() <=> rhs.month(); + + if (cmp != 0) + { + return cmp; + } + + return lhs.day() <=> rhs.day(); + } +#endif + + //*********************************************************************** + /// Compare year_month_day with another. + /// if year < other.year, returns -1; + /// else if year > other.year, returns 1; + /// if month < other.month, returns -1; + /// else if month > other.month, returns 1; + /// else if day < other.day, returns -1; + /// else if day > other.day, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const year_month_day& other) const ETL_NOEXCEPT + { + if (y < other.y) return -1; + if (y > other.y) return 1; + if (m < other.m) return -1; + if (m > other.m) return 1; + if (d < other.d) return -1; + if (d > other.d) return 1; + + return 0; + } + + //*********************************************************************** + /// Converts *this to etl::chrono::sys_days + //*********************************************************************** + //ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT + //{ + // // Start with the first day of the year + // etl::chrono::sys_days first_day_of_year = etl::chrono::sys_days(y / etl::chrono::January / etl::chrono::day(1)); + + // // Add the number of days in the months before the current month + // for (etl::chrono::month m = etl::chrono::January; m < m; ++m) + // { + // first_day_of_year += etl::chrono::days((unsigned)etl::chrono::month_day_last(m).day()); + // } + + // // Add the days in the current month + // first_day_of_year += d - etl::chrono::day(1); + + // return first_day_of_year; + //} + + ////*********************************************************************** + ///// Converts *this to etl::chrono::local_days + ////*********************************************************************** + //ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT + //{ + // return etl::chrono::local_days(); + //} + + private: + + etl::chrono::year y; + etl::chrono::month m; + etl::chrono::day d; + }; + + //************************************************************************* + /// year_month_day_last + //************************************************************************* + class year_month_day_last + { + public: + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR year_month_day_last(const etl::chrono::year& y, + const etl::chrono::month_day_last& mdl) ETL_NOEXCEPT + : y(y) + , m(mdl.month()) + { + + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year year() const ETL_NOEXCEPT + { + return y; + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT + { + return etl::chrono::month_day_last(m).day(); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month_day_last month_day_last() const ETL_NOEXCEPT + { + return etl::chrono::month_day_last(m); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_day_last& operator +=(const etl::chrono::years& dy) ETL_NOEXCEPT + { + y += dy; + + return *this; + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_day_last& operator +=(const etl::chrono::months& dm) ETL_NOEXCEPT + { + m += dm; + + return *this; + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_day_last& operator -=(const etl::chrono::years& dy) ETL_NOEXCEPT + { + y -= dy; + + return *this; + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_day_last& operator -=(const etl::chrono::months& dm) ETL_NOEXCEPT + { + m -= dm; + + return *this; + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() + dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_day_last& ymdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() + dm)); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year() - dy, ymdl.month_day_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day_last& ymdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_day_last(ymdl.year(), etl::chrono::month_day_last(ymdl.month() - dm)); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return (lhs.y == rhs.y) && (lhs.m == rhs.m); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_day_last& lhs, + const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year() <=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + else + { + auto cmp = lhs.month() <=> rhs.month(); + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.month() <=> rhs.month(); + } + } + } +#endif + + //*********************************************************************** + /// Compare year_month_day with another. + /// if year < other.year, returns -1; + /// else if year > other.year, returns 1; + /// if month < other.month, returns -1; + /// else if month > other.month, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const year_month_day_last& other) const ETL_NOEXCEPT + { + if (y < other.y) return -1; + if (y > other.y) return 1; + if (m < other.m) return -1; + if (m > other.m) return 1; + + return 0; + } + + //************************************************************************* + /// + //************************************************************************* + //ETL_CONSTEXPR operator etl::chrono::sys_days() const ETL_NOEXCEPT + //{ + // etl::chrono::sys_days(); + //} + + //************************************************************************* + /// + //************************************************************************* + //ETL_CONSTEXPR explicit operator etl::chrono::local_days() const ETL_NOEXCEPT + //{ + + //} + + private: + + etl::chrono::year y; + etl::chrono::month m; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::year_month_day + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year_month_day& ymd) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int y = ymd.year(); + unsigned int m = ymd.month(); + unsigned int d = ymd.day(); + + memcpy(buffer, &y, sizeof(y)); + memcpy(buffer + sizeof(y), &m, sizeof(m)); + memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif + + //************************************************************************* + /// Hash function for etl::chrono::year_month_day_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year_month_day_last& ymdl) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int y = ymdl.year(); + unsigned int m = ymdl.month(); + unsigned int d = ymdl.day(); + + memcpy(buffer, &y, sizeof(y)); + memcpy(buffer + sizeof(y), &m, sizeof(m)); + memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/include/etl/private/chrono/year_month_weekday.h b/include/etl/private/chrono/year_month_weekday.h new file mode 100644 index 000000000..03242c6eb --- /dev/null +++ b/include/etl/private/chrono/year_month_weekday.h @@ -0,0 +1,518 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //************************************************************************* + /// year_month_weekday + //************************************************************************* + class year_month_weekday + { + public: + + //************************************************************************* + /// Default constructor. + //************************************************************************* + year_month_weekday() + : y() + , m() + , wdi() + { + } + + //************************************************************************* + /// Construct from month and day. + //************************************************************************* + ETL_CONSTEXPR year_month_weekday(const etl::chrono::year& y_, + const etl::chrono::month& m_, + const etl::chrono::weekday_indexed& wdi_) ETL_NOEXCEPT + : y(y_) + , m(m_) + , wdi(wdi_) + { + } + + //************************************************************************* + /// Returns the year. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year year() const ETL_NOEXCEPT + { + return y; + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the weekday. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT + { + return wdi.weekday(); + } + + //************************************************************************* + /// Returns the weekday index. + //************************************************************************* + ETL_CONSTEXPR unsigned index() const ETL_NOEXCEPT + { + return wdi.index(); + } + + //************************************************************************* + /// Returns the weekday_indexed. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday_indexed weekday_indexed() const ETL_NOEXCEPT + { + return wdi; + } + + //************************************************************************* + /// Returns true if the year/month/day is valid. + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + return y.ok() && m.ok() && wdi.ok(); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() + dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Adds etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_weekday& ymwd) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() + dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year() - dy, ymwd.month(), ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday operator -(const etl::chrono::year_month_weekday& ymwd, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday(ymwd.year(), ymwd.month() - dm, ymwd.weekday_indexed()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::year_month_weekday& lhs, + const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT + { + return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.wdi == rhs.wdi); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::year_month_weekday& lhs, + const etl::chrono::year_month_weekday& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Converts *this to etl::chrono::sys_days + //*********************************************************************** + //ETL_CONSTEXPR14 operator etl::chrono::sys_days() const ETL_NOEXCEPT + //{ + // // Start with the first day of the given year and month + // etl::chrono::year_month_day first_day_of_month(y, m, etl::chrono::day(1)); + + // // Convert the first day of the month to sys_days + // etl::chrono::sys_days first_day_sys_days = static_cast(first_day_of_month); + + // // Determine the weekday of the first day of the month + // etl::chrono::weekday first_weekday = etl::chrono::weekday(first_day_sys_days); + + // // Calculate the offset to the desired weekday + // int offset = (wd.weekday().c_encoding() - first_weekday.c_encoding() + 7) % 7; + + // // Calculate the day of the month for the desired weekday_indexed + // int day_of_month = 1 + offset + (wdi.index() - 1) * 7; + + // // Ensure the calculated day is valid for the given month + // if (day_of_month > etl::chrono::month_day_last(m).day().count()) + // { + // day_of_month = 0; // Invalid day + // } + + // // Create a year_month_day object for the calculated day + // etl::chrono::year_month_day ymwd(y, m, etl::chrono::day(day_of_month)); + + // // Convert the year_month_day to sys_days + // return static_cast(ymwd); + //} + + ////*********************************************************************** + ///// Converts *this to etl::chrono::local_days + ////*********************************************************************** + //ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT + //{ + // return etl::chrono::local_days(); + //} + + private: + + etl::chrono::year y; + etl::chrono::month m; + etl::chrono::weekday_indexed wdi; + }; + + //************************************************************************* + /// year_month_weekday_last + //************************************************************************* + class year_month_weekday_last + { + public: + + //************************************************************************* + /// Construct from year, month, weekday_last + //************************************************************************* + ETL_CONSTEXPR year_month_weekday_last(const etl::chrono::year& y_, + const etl::chrono::month& m_, + const etl::chrono::weekday_last& wdl_) ETL_NOEXCEPT + : y(y_) + , m(m_) + , wdl(wdl_) + { + } + + //************************************************************************* + /// Returns the year. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year year() const ETL_NOEXCEPT + { + return y; + } + + //************************************************************************* + /// Returns the month. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::month month() const ETL_NOEXCEPT + { + return m; + } + + //************************************************************************* + /// Returns the weekday. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday weekday() const ETL_NOEXCEPT + { + return wdl.weekday(); + } + + //************************************************************************* + /// Returns the weekday_last. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::weekday_last weekday_last() const ETL_NOEXCEPT + { + return wdl; + } + + //************************************************************************* + /// Adds etl::chrono::years. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_weekday_last& operator +=(const etl::chrono::years& dy) ETL_NOEXCEPT + { + y += dy; + + return *this; + } + + //************************************************************************* + /// Adds etl::chrono::months. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_weekday_last& operator +=(const etl::chrono::months& dm) ETL_NOEXCEPT + { + m += dm; + + return *this; + } + + //************************************************************************* + /// Subtracts etl::chrono::years. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_weekday_last& operator -=(const etl::chrono::years& dy) ETL_NOEXCEPT + { + y -= dy; + + return *this; + } + + //************************************************************************* + /// Subtracts etl::chrono::months. + //************************************************************************* + ETL_CONSTEXPR etl::chrono::year_month_weekday_last& operator -=(const etl::chrono::months& dm) ETL_NOEXCEPT + { + m -= dm; + + return *this; + } + + //************************************************************************* + /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds etl::chrono::years and const etl::chrono::year_month_weekday_last. + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::years& dy, + const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() + dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds const etl::chrono::year_month_weekday_last and etl::chrono::months. + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Adds etl::chrono::months and const etl::chrono::year_month_weekday_last. + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator +(const etl::chrono::months& dm, + const etl::chrono::year_month_weekday_last& ymwdl) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() + dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::years from const etl::chrono::year_month_weekday_last. + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::years& dy) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year() - dy, ymwdl.month(), ymwdl.weekday_last()); + } + + //************************************************************************* + /// Subtracts etl::chrono::months from const etl::chrono::year_month_weekday_last + //************************************************************************* + friend ETL_CONSTEXPR14 etl::chrono::year_month_weekday_last operator -(const etl::chrono::year_month_weekday_last& ymwdl, + const etl::chrono::months& dm) ETL_NOEXCEPT + { + return etl::chrono::year_month_weekday_last(ymwdl.year(), ymwdl.month() - dm, ymwdl.weekday_last()); + } + + //************************************************************************* + /// Equality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator ==(const etl::chrono::year_month_weekday_last& lhs, + const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT + { + return (lhs.y == rhs.y) && (lhs.m == rhs.m) && (lhs.weekday() == rhs.weekday()); + } + + //************************************************************************* + /// Inequality operator. + //************************************************************************* + friend ETL_CONSTEXPR bool operator !=(const etl::chrono::year_month_weekday_last& lhs, + const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //*********************************************************************** + /// Spaceship operator + //*********************************************************************** +#if ETL_USING_CPP20 + [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_weekday_last& lhs, + const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT + { + auto cmp = lhs.year() <=> rhs.year(); + + if (cmp != 0) + { + return cmp; + } + else + { + auto cmp = lhs.month() <=> rhs.month(); + + if (cmp != 0) + { + return cmp; + } + else + { + return lhs.weekday().c_encoding() <=> rhs.weekday().c_encoding(); + } + } + } +#endif + + //*********************************************************************** + /// Compare year_month_weekday with another. + /// if year < other.year, returns -1; + /// else if year > other.year, returns 1; + /// if month < other.month, returns -1; + /// else if month > other.month, returns 1; + /// else returns 0; + //*********************************************************************** + ETL_CONSTEXPR14 int compare(const year_month_weekday_last& other) const ETL_NOEXCEPT + { + if (y < other.y) return -1; + if (y > other.y) return 1; + if (m < other.m) return -1; + if (m > other.m) return 1; + + return 0; + } + + //************************************************************************* + /// + //************************************************************************* + //ETL_CONSTEXPR operator etl::chrono::sys_days() const ETL_NOEXCEPT + //{ + // etl::chrono::sys_days(); + //} + + //************************************************************************* + /// + //************************************************************************* + //ETL_CONSTEXPR explicit operator etl::chrono::local_days() const ETL_NOEXCEPT + //{ + + //} + + private: + + etl::chrono::year y; + etl::chrono::month m; + etl::chrono::weekday_last wdl; + }; + } + + //************************************************************************* + /// Hash function for etl::chrono::year_month_weekday + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year_month_weekday& ymwd) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int y = ymwd.year(); + unsigned int m = ymwd.month(); + unsigned int d = ymwd.weekday().c_encoding(); + + memcpy(buffer, &y, sizeof(y)); + memcpy(buffer + sizeof(y), &m, sizeof(m)); + memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif + + //************************************************************************* + /// Hash function for etl::chrono::year_month_weekday_last + //************************************************************************* +#if ETL_USING_8BIT_TYPES + template <> + struct hash + { + size_t operator()(const etl::chrono::year_month_weekday_last& ymwdl) const + { + uint8_t buffer[sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)]; + + unsigned int y = ymwdl.year(); + unsigned int m = ymwdl.month(); + unsigned int d = ymwdl.weekday_last().weekday().c_encoding(); + + memcpy(buffer, &y, sizeof(y)); + memcpy(buffer + sizeof(y), &m, sizeof(m)); + memcpy(buffer + sizeof(y) + sizeof(m), &d, sizeof(d)); + + return etl::private_hash::generic_hash(buffer, buffer + sizeof(unsigned int) + sizeof(unsigned int) + sizeof(unsigned int)); + } + }; +#endif +} + diff --git a/test/test_chrono_month_day_last.cpp b/test/test_chrono_month_day_last.cpp index ec9b6ae4f..f47792c71 100644 --- a/test/test_chrono_month_day_last.cpp +++ b/test/test_chrono_month_day_last.cpp @@ -84,6 +84,19 @@ namespace CHECK_TRUE(month_day_last_october.ok()); CHECK_TRUE(month_day_last_november.ok()); CHECK_TRUE(month_day_last_december.ok()); + + CHECK_EQUAL(31, month_day_last_january.day()); + CHECK_EQUAL(29, month_day_last_february.day()); + CHECK_EQUAL(31, month_day_last_march.day()); + CHECK_EQUAL(30, month_day_last_april.day()); + CHECK_EQUAL(31, month_day_last_may.day()); + CHECK_EQUAL(30, month_day_last_june.day()); + CHECK_EQUAL(31, month_day_last_july.day()); + CHECK_EQUAL(31, month_day_last_august.day()); + CHECK_EQUAL(30, month_day_last_september.day()); + CHECK_EQUAL(31, month_day_last_october.day()); + CHECK_EQUAL(30, month_day_last_november.day()); + CHECK_EQUAL(31, month_day_last_december.day()); } //************************************************************************* diff --git a/test/test_chrono_operators.cpp b/test/test_chrono_operators.cpp index 30e398d34..f9fca7ffb 100644 --- a/test/test_chrono_operators.cpp +++ b/test/test_chrono_operators.cpp @@ -37,28 +37,254 @@ SOFTWARE. #include #include -// Set to 0 to reference against std::chrono -#define ETL_USING_ETL_CHRONO 1 - -#if ETL_USING_ETL_CHRONO - #define Chrono etl::chrono -#else - #if ETL_USING_CPP20 - #include - #define Chrono std::chrono - #else - #error std::chrono not supported - #endif -#endif +using namespace etl::literals::chrono_literals; namespace { SUITE(test_chrono_operators) { //************************************************************************* - TEST(test_operator_for_year_month) + TEST(test_construction_operator_for_month_day) { + etl::chrono::month_day md1 = etl::chrono::January / etl::chrono::day(2); + etl::chrono::month_day md2 = etl::chrono::February / 3; + etl::chrono::month_day md3 = 3 / etl::chrono::day(4); + etl::chrono::month_day md4 = etl::chrono::day(5) / etl::chrono::April; + etl::chrono::month_day md5 = etl::chrono::day(6) / 5; + CHECK_EQUAL(etl::chrono::January, md1.month()); + CHECK_EQUAL(etl::chrono::day(2), md1.day()); + + CHECK_EQUAL(etl::chrono::February, md2.month()); + CHECK_EQUAL(etl::chrono::day(3), md2.day()); + + CHECK_EQUAL(etl::chrono::March, md3.month()); + CHECK_EQUAL(etl::chrono::day(4), md3.day()); + + CHECK_EQUAL(etl::chrono::April, md4.month()); + CHECK_EQUAL(etl::chrono::day(5), md4.day()); + + CHECK_EQUAL(etl::chrono::May, md5.month()); + CHECK_EQUAL(etl::chrono::day(6), md5.day()); + } + + //************************************************************************* + TEST(test_construction_operator_for_month_day_last) + { + etl::chrono::month_day_last mdl1 = etl::chrono::January / etl::chrono::last; + etl::chrono::month_day_last mdl2 = 2 / etl::chrono::last; + etl::chrono::month_day_last mdl3 = etl::chrono::last / etl::chrono::March; + etl::chrono::month_day_last mdl4 = etl::chrono::last / 4; + + CHECK_EQUAL(etl::chrono::January, mdl1.month()); + CHECK_EQUAL(etl::chrono::February, mdl2.month()); + CHECK_EQUAL(etl::chrono::March, mdl3.month()); + CHECK_EQUAL(etl::chrono::April, mdl4.month()); + } + + //************************************************************************* + TEST(test_construction_operator_for_month_weekday) + { + etl::chrono::month_weekday mwd1 = etl::chrono::January / etl::chrono::weekday_indexed(etl::chrono::Monday, 0); + etl::chrono::month_weekday mwd2 = 2 / etl::chrono::weekday_indexed(etl::chrono::Wednesday, 1); + etl::chrono::month_weekday mwd3 = etl::chrono::weekday_indexed(etl::chrono::Friday, 2) / etl::chrono::March; + etl::chrono::month_weekday mwd4 = etl::chrono::weekday_indexed(etl::chrono::Sunday, 3) / 4; + + CHECK_EQUAL(etl::chrono::January, mwd1.month()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Monday, 0).weekday().c_encoding(), + mwd1.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Monday, 0).index(), + mwd1.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::February, mwd2.month()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Wednesday, 1).weekday().c_encoding(), + mwd2.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Wednesday, 1).index(), + mwd2.weekday_indexed().index()); + + + CHECK_EQUAL(etl::chrono::March, mwd3.month()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Friday, 2).weekday().c_encoding(), + mwd3.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Friday, 2).index(), + mwd3.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::April, mwd4.month()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Sunday, 3).weekday().c_encoding(), + mwd4.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::weekday_indexed(etl::chrono::Sunday, 3).index(), + mwd4.weekday_indexed().index()); + } + + //************************************************************************* + TEST(test_construction_operator_for_month_weekday_last) + { + etl::chrono::month_weekday_last mdl1 = etl::chrono::January / etl::chrono::weekday_last(etl::chrono::Monday); + etl::chrono::month_weekday_last mdl2 = 2 / etl::chrono::weekday_last(etl::chrono::Tuesday); + etl::chrono::month_weekday_last mdl3 = etl::chrono::weekday_last(etl::chrono::Wednesday) / etl::chrono::March; + etl::chrono::month_weekday_last mdl4 = etl::chrono::weekday_last(etl::chrono::Thursday) / 4; + + CHECK_EQUAL(etl::chrono::January, mdl1.month()); + CHECK_EQUAL(etl::chrono::Monday.c_encoding(), mdl1.weekday_last().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::February, mdl2.month()); + CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), mdl2.weekday_last().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::March, mdl3.month()); + CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), mdl3.weekday_last().weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::April, mdl4.month()); + CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), mdl4.weekday_last().weekday().c_encoding()); + } + + //************************************************************************* + TEST(test_construction_operator_for_year_month) + { + etl::chrono::year_month ym1 = 2000_year / etl::chrono::April; + etl::chrono::year_month ym2 = 2001_year / 5; + + CHECK_EQUAL(2000_year, ym1.year()); + CHECK_EQUAL(etl::chrono::April, ym1.month()); + + CHECK_EQUAL(2001_year, ym2.year()); + CHECK_EQUAL(etl::chrono::May, ym2.month()); + } + + //************************************************************************* + TEST(test_construction_operator_for_year_month_day) + { + etl::chrono::year_month_day ymd1 = etl::chrono::year_month(etl::chrono::year(2000), etl::chrono::January) / etl::chrono::day(1); + etl::chrono::year_month_day ymd2 = etl::chrono::year_month(etl::chrono::year(2001), etl::chrono::February) / 2; + etl::chrono::year_month_day ymd3 = etl::chrono::year(2002) / etl::chrono::month_day(etl::chrono::March, etl::chrono::day(3)); + etl::chrono::year_month_day ymd4 = 2003 / etl::chrono::month_day(etl::chrono::April, etl::chrono::day(4)); + etl::chrono::year_month_day ymd5 = etl::chrono::month_day(etl::chrono::May, etl::chrono::day(5)) / etl::chrono::year(2004); + etl::chrono::year_month_day ymd6 = etl::chrono::month_day(etl::chrono::June, etl::chrono::day(6)) / 2005; + + CHECK_EQUAL(etl::chrono::year(2000), ymd1.year()); + CHECK_EQUAL(etl::chrono::January, ymd1.month()); + CHECK_EQUAL(etl::chrono::day(1), ymd1.day()); + + CHECK_EQUAL(etl::chrono::year(2001), ymd2.year()); + CHECK_EQUAL(etl::chrono::February, ymd2.month()); + CHECK_EQUAL(etl::chrono::day(2), ymd2.day()); + + CHECK_EQUAL(etl::chrono::year(2002), ymd3.year()); + CHECK_EQUAL(etl::chrono::March, ymd3.month()); + CHECK_EQUAL(etl::chrono::day(3), ymd3.day()); + + CHECK_EQUAL(etl::chrono::year(2003), ymd4.year()); + CHECK_EQUAL(etl::chrono::April, ymd4.month()); + CHECK_EQUAL(etl::chrono::day(4), ymd4.day()); + + CHECK_EQUAL(etl::chrono::year(2004), ymd5.year()); + CHECK_EQUAL(etl::chrono::May, ymd5.month()); + CHECK_EQUAL(etl::chrono::day(5), ymd5.day()); + + CHECK_EQUAL(etl::chrono::year(2005), ymd6.year()); + CHECK_EQUAL(etl::chrono::June, ymd6.month()); + CHECK_EQUAL(etl::chrono::day(6), ymd6.day()); + } + + //************************************************************************* + TEST(test_construction_operator_for_year_month_day_last) + { + etl::chrono::year_month_day_last ymdl1 = etl::chrono::year_month(etl::chrono::year(2000), etl::chrono::January) / etl::chrono::last; + etl::chrono::year_month_day_last ymdl2 = etl::chrono::year(2001) / etl::chrono::month_day_last(etl::chrono::February); + etl::chrono::year_month_day_last ymdl3 = 2002 / etl::chrono::month_day_last(etl::chrono::March); + etl::chrono::year_month_day_last ymdl4 = etl::chrono::month_day_last(etl::chrono::April) / etl::chrono::year(2003); + etl::chrono::year_month_day_last ymdl5 = etl::chrono::month_day_last(etl::chrono::May) / 2004; + + CHECK_EQUAL(etl::chrono::year(2000), ymdl1.year()); + CHECK_EQUAL(etl::chrono::January, ymdl1.month()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).day(), ymdl1.day()); + CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::January) == ymdl1.month_day_last()); + + CHECK_EQUAL(etl::chrono::year(2001), ymdl2.year()); + CHECK_EQUAL(etl::chrono::February, ymdl2.month()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).day(), ymdl2.day()); + CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::February) == ymdl2.month_day_last()); + + CHECK_EQUAL(etl::chrono::year(2002), ymdl3.year()); + CHECK_EQUAL(etl::chrono::March, ymdl3.month()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).day(), ymdl3.day()); + CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::March) == ymdl3.month_day_last()); + + CHECK_EQUAL(etl::chrono::year(2003), ymdl4.year()); + CHECK_EQUAL(etl::chrono::April, ymdl4.month()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).day(), ymdl4.day()); + CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::April) == ymdl4.month_day_last()); + + CHECK_EQUAL(etl::chrono::year(2004), ymdl5.year()); + CHECK_EQUAL(etl::chrono::May, ymdl5.month()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).day(), ymdl5.day()); + CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::May) == ymdl5.month_day_last()); + } + + //************************************************************************* + TEST(test_construction_operator_for_year_month_weekday) + { + etl::chrono::year_month_weekday ymwd1 = etl::chrono::year_month(etl::chrono::year(2000), etl::chrono::January) / etl::chrono::weekday_indexed(etl::chrono::Monday, 0); + etl::chrono::year_month_weekday ymwd2 = etl::chrono::year(2001) / etl::chrono::month_weekday(etl::chrono::February, etl::chrono::weekday_indexed(etl::chrono::Tuesday, 1)); + etl::chrono::year_month_weekday ymwd3 = 2002 / etl::chrono::month_weekday(etl::chrono::March, etl::chrono::weekday_indexed(etl::chrono::Wednesday, 2)); + etl::chrono::year_month_weekday ymwd4 = etl::chrono::month_weekday(etl::chrono::April, etl::chrono::weekday_indexed(etl::chrono::Thursday, 3)) / etl::chrono::year(2003); + etl::chrono::year_month_weekday ymwd5 = etl::chrono::month_weekday(etl::chrono::May, etl::chrono::weekday_indexed(etl::chrono::Friday, 4)) / 2004; + + CHECK_EQUAL(etl::chrono::year(2000), ymwd1.year()); + CHECK_EQUAL(etl::chrono::January, ymwd1.month()); + CHECK_EQUAL(etl::chrono::Monday.c_encoding(), ymwd1.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Monday.c_encoding(), ymwd1.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(0, ymwd1.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::year(2001), ymwd2.year()); + CHECK_EQUAL(etl::chrono::February, ymwd2.month()); + CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), ymwd2.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Tuesday.c_encoding(), ymwd2.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(1, ymwd2.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::year(2002), ymwd3.year()); + CHECK_EQUAL(etl::chrono::March, ymwd3.month()); + CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), ymwd3.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Wednesday.c_encoding(), ymwd3.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(2, ymwd3.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::year(2003), ymwd4.year()); + CHECK_EQUAL(etl::chrono::April, ymwd4.month()); + CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), ymwd4.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Thursday.c_encoding(), ymwd4.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(3, ymwd4.weekday_indexed().index()); + + CHECK_EQUAL(etl::chrono::year(2004), ymwd5.year()); + CHECK_EQUAL(etl::chrono::May, ymwd5.month()); + CHECK_EQUAL(etl::chrono::Friday.c_encoding(), ymwd5.weekday().c_encoding()); + CHECK_EQUAL(etl::chrono::Friday.c_encoding(), ymwd5.weekday_indexed().weekday().c_encoding()); + CHECK_EQUAL(4, ymwd5.weekday_indexed().index()); + } + + //************************************************************************* + TEST(test_construction_operator_for_year_month_weekday_last) + { + etl::chrono::year_month_weekday_last ymdl1 = etl::chrono::year_month(etl::chrono::year(2000), etl::chrono::January) / etl::chrono::weekday_last(etl::chrono::Monday); + etl::chrono::year_month_weekday_last ymdl2 = etl::chrono::year(2001) / etl::chrono::month_weekday_last(etl::chrono::February, etl::chrono::weekday_last(etl::chrono::Tuesday)); + etl::chrono::year_month_weekday_last ymdl3 = 2002 / etl::chrono::month_weekday_last(etl::chrono::March, etl::chrono::weekday_last(etl::chrono::Wednesday)); + etl::chrono::year_month_weekday_last ymdl4 = etl::chrono::month_weekday_last(etl::chrono::April, etl::chrono::weekday_last(etl::chrono::Thursday)) / etl::chrono::year(2003); + etl::chrono::year_month_weekday_last ymdl5 = etl::chrono::month_weekday_last(etl::chrono::May, etl::chrono::weekday_last(etl::chrono::Friday))/ 2004; + + CHECK_EQUAL(etl::chrono::year(2000), ymdl1.year()); + CHECK_EQUAL(etl::chrono::January, ymdl1.month()); + CHECK_EQUAL(etl::chrono::weekday_last(etl::chrono::Monday).weekday().c_encoding(), ymdl1.weekday().c_encoding()); + + CHECK_EQUAL(etl::chrono::year(2001), ymdl2.year()); + CHECK_EQUAL(etl::chrono::February, ymdl2.month()); + CHECK_EQUAL(etl::chrono::weekday_last(etl::chrono::Tuesday).weekday().c_encoding(), ymdl2.weekday().c_encoding()); + + CHECK_EQUAL(etl::chrono::year(2002), ymdl3.year()); + CHECK_EQUAL(etl::chrono::March, ymdl3.month()); + CHECK_EQUAL(etl::chrono::weekday_last(etl::chrono::Wednesday).weekday().c_encoding(), ymdl3.weekday().c_encoding()); + + CHECK_EQUAL(etl::chrono::year(2003), ymdl4.year()); + CHECK_EQUAL(etl::chrono::April, ymdl4.month()); + CHECK_EQUAL(etl::chrono::weekday_last(etl::chrono::Thursday).weekday().c_encoding(), ymdl4.weekday().c_encoding()); + + CHECK_EQUAL(etl::chrono::year(2004), ymdl5.year()); + CHECK_EQUAL(etl::chrono::May, ymdl5.month()); + CHECK_EQUAL(etl::chrono::weekday_last(etl::chrono::Friday).weekday().c_encoding(), ymdl5.weekday().c_encoding()); } }; -} +} \ No newline at end of file diff --git a/test/test_chrono_year.cpp b/test/test_chrono_year.cpp index 70c17c8a4..90f909a60 100644 --- a/test/test_chrono_year.cpp +++ b/test/test_chrono_year.cpp @@ -243,7 +243,7 @@ namespace { for (int i = -32767; i <= 32767; ++i) { - bool is_leap = ((i % 4) == 0) && ((i % 400) != 0); + bool is_leap = ((i % 4) == 0) && (((i % 100) != 0) || ((i % 400) == 0)); etl::chrono::year year(i); diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index af492705f..8489c79fd 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3195,9 +3195,13 @@ + + + + @@ -8472,6 +8476,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 02a498510..7dea846b7 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1497,6 +1497,18 @@ ETL\Private\chrono + + ETL\Private\chrono + + + ETL\Private\chrono + + + ETL\Private\chrono + + + ETL\Private\chrono + @@ -3551,6 +3563,9 @@ Tests\Chrono + + Tests\Chrono + From 39f17a94b8ddf79f4b713955be5a3bb99bd4dbf2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Apr 2025 19:58:39 +0100 Subject: [PATCH 141/216] Added floating point duration types --- include/etl/private/chrono/duration.h | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 1b9297094..409a24867 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -628,6 +628,14 @@ namespace etl return etl::chrono::hours(static_cast(h)); } + //*********************************************************************** + /// Literal for floating point hours duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration> operator""_h(long double h) noexcept + { + return etl::chrono::duration>(h); + } + //*********************************************************************** /// Literal for minutes duration //*********************************************************************** @@ -636,6 +644,14 @@ namespace etl return etl::chrono::minutes(static_cast(m)); } + //*********************************************************************** + /// Literal for floating point minutes duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration> operator ""_minutes(long double m) noexcept + { + return etl::chrono::duration>(m); + } + //*********************************************************************** /// Literal for seconds duration //*********************************************************************** @@ -644,6 +660,14 @@ namespace etl return etl::chrono::seconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point seconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_seconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for milliseconds duration //*********************************************************************** @@ -652,6 +676,14 @@ namespace etl return etl::chrono::milliseconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point milliseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_milliseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for microseconds duration //*********************************************************************** @@ -660,6 +692,14 @@ namespace etl return etl::chrono::microseconds(static_cast(s)); } + //*********************************************************************** + /// Literal for floating point microseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_microseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } + //*********************************************************************** /// Literal for nanoseconds duration //*********************************************************************** @@ -667,6 +707,14 @@ namespace etl { return etl::chrono::nanoseconds(static_cast(s)); } + + //*********************************************************************** + /// Literal for floating point microseconds duration + //*********************************************************************** + inline ETL_CONSTEXPR etl::chrono::duration operator ""_nanoseconds(long double s) noexcept + { + return etl::chrono::duration(s); + } } } } From e7cbc10df8095eca4bccc653f7703ed3b05341fe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Apr 2025 19:59:32 +0100 Subject: [PATCH 142/216] Added experimental system_clock, time_point, and time_zone classes --- include/etl/private/chrono/system_clock.h | 2 +- include/etl/private/chrono/time_point.h | 2 +- include/etl/private/chrono/time_zone.h | 80 +++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 include/etl/private/chrono/time_zone.h diff --git a/include/etl/private/chrono/system_clock.h b/include/etl/private/chrono/system_clock.h index 993413134..a9d6f7141 100644 --- a/include/etl/private/chrono/system_clock.h +++ b/include/etl/private/chrono/system_clock.h @@ -38,7 +38,7 @@ namespace etl { class system_clock { - + using duration = etl::chrono::seconds; }; template diff --git a/include/etl/private/chrono/time_point.h b/include/etl/private/chrono/time_point.h index 0d48acb36..2ee0159fe 100644 --- a/include/etl/private/chrono/time_point.h +++ b/include/etl/private/chrono/time_point.h @@ -78,7 +78,7 @@ namespace etl /// Copy construct from another time_point with a different duration type. //*************************************************************************** template - explicit time_point(const time_point& rhs) ETL_NOEXCEPT + explicit time_point(const time_point& rhs) ETL_NOEXCEPT : dur(rhs.time_since_epoch()) { } diff --git a/include/etl/private/chrono/time_zone.h b/include/etl/private/chrono/time_zone.h new file mode 100644 index 000000000..a01154a97 --- /dev/null +++ b/include/etl/private/chrono/time_zone.h @@ -0,0 +1,80 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +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_IN_CHRONO_H + #error DO NOT DIRECTLY INCLUDE THIS FILE. USE CHRONO.H +#endif + +namespace etl +{ + namespace chrono + { + //class time_zone + //{ + //public: + + // /// Obtains the name of this time_zone. + // etl::string_view name() const ETL_NOEXCEPT + // { + // return etl::string_view(tz_name, etl::strlen(tz_name)); + // } + + // template + // etl::chrono::sys_info get_info(const etl::chrono::sys_time& tp) const + // { + + // } + + // template + // etl::chrono::local_info get_info(const etl::chrono::local_time& tp) const + // { + // return etl::chrono::local_info(); + // } + + // template + // etl::chrono::sys_time> to_sys(const etl::chrono::local_time& tp) const + // { + // etl::chrono::sys_time>() + // } + + // template + // etl::chrono::sys_time> to_sys(const etl::chrono::local_time& tp, + // etl::chrono::choose z) const + // { + // etl::chrono::sys_time>(); + // } + + //private: + + // static const char *tz_name; + + //}; + } +} \ No newline at end of file From 5143aa7f530ba4b150ce9fdca82b2bbd6067d781 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Apr 2025 20:00:18 +0100 Subject: [PATCH 143/216] Added year_month_day and year_month_day_last classes and tests --- include/etl/chrono.h | 2 + include/etl/private/chrono/year_month_day.h | 17 +- test/test_chrono_operators.cpp | 10 +- test/test_chrono_year_month.cpp | 32 ++-- test/test_chrono_year_month_day.cpp | 167 ++++++++++++++++++++ test/test_chrono_year_month_day_last.cpp | 145 +++++++++++++++++ test/vs2022/etl.vcxproj | 3 + test/vs2022/etl.vcxproj.filters | 9 ++ 8 files changed, 364 insertions(+), 21 deletions(-) create mode 100644 test/test_chrono_year_month_day.cpp create mode 100644 test/test_chrono_year_month_day_last.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h index 8fce7d574..fbc0b47d9 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -36,6 +36,7 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" #include "integral_limits.h" +#include "string_view.h" #if ETL_NOT_USING_CPP11 #error NOT SUPPORTED FOR C++03 OR BELOW @@ -75,6 +76,7 @@ namespace etl #include "private/chrono/year_month_weekday.h" #include "private/chrono/hh_mm_ss.h" #include "private/chrono/operators.h" +#include "private/chrono/time_zone.h" #endif #undef ETL_IN_CHRONO_H diff --git a/include/etl/private/chrono/year_month_day.h b/include/etl/private/chrono/year_month_day.h index 101dcfb3d..0cae2211e 100644 --- a/include/etl/private/chrono/year_month_day.h +++ b/include/etl/private/chrono/year_month_day.h @@ -245,7 +245,11 @@ namespace etl ////*********************************************************************** //ETL_CONSTEXPR14 explicit operator etl::chrono::local_days() const ETL_NOEXCEPT //{ - // return etl::chrono::local_days(); + //// Convert the year_month_day to sys_days first + //etl::chrono::sys_days sys_days_representation = static_cast(*this); + + //// Convert sys_days to local_days (assuming local_days is a wrapper around sys_days) + //return etl::chrono::local_days(sys_days_representation); //} private: @@ -270,7 +274,6 @@ namespace etl : y(y) , m(mdl.month()) { - } //************************************************************************* @@ -305,6 +308,16 @@ namespace etl return etl::chrono::month_day_last(m); } + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT + { + return y.ok() && + m.ok() && + day() == etl::chrono::month_day_last(m).day(); + } + //************************************************************************* /// //************************************************************************* diff --git a/test/test_chrono_operators.cpp b/test/test_chrono_operators.cpp index f9fca7ffb..f9f55b786 100644 --- a/test/test_chrono_operators.cpp +++ b/test/test_chrono_operators.cpp @@ -194,27 +194,27 @@ namespace CHECK_EQUAL(etl::chrono::year(2000), ymdl1.year()); CHECK_EQUAL(etl::chrono::January, ymdl1.month()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).day(), ymdl1.day()); - CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::January) == ymdl1.month_day_last()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).month(), ymdl1.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2001), ymdl2.year()); CHECK_EQUAL(etl::chrono::February, ymdl2.month()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).day(), ymdl2.day()); - CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::February) == ymdl2.month_day_last()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).month(), ymdl2.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2002), ymdl3.year()); CHECK_EQUAL(etl::chrono::March, ymdl3.month()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).day(), ymdl3.day()); - CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::March) == ymdl3.month_day_last()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).month(), ymdl3.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2003), ymdl4.year()); CHECK_EQUAL(etl::chrono::April, ymdl4.month()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).day(), ymdl4.day()); - CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::April) == ymdl4.month_day_last()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).month(), ymdl4.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2004), ymdl5.year()); CHECK_EQUAL(etl::chrono::May, ymdl5.month()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).day(), ymdl5.day()); - CHECK_TRUE(etl::chrono::month_day_last(etl::chrono::May) == ymdl5.month_day_last()); + CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).month(), ymdl5.month_day_last().month()); } //************************************************************************* diff --git a/test/test_chrono_year_month.cpp b/test/test_chrono_year_month.cpp index bd3a87f5f..a0e8ab7f6 100644 --- a/test/test_chrono_year_month.cpp +++ b/test/test_chrono_year_month.cpp @@ -94,12 +94,14 @@ namespace TEST(test_year_month_spaceship_operator) { Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; - Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; - Chrono::year_month ym3{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::January}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; - CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::equal); + CHECK_TRUE((ym1 <=> ym1) == std::strong_ordering::equal); CHECK_TRUE((ym1 <=> ym2) == std::strong_ordering::less); CHECK_TRUE((ym2 <=> ym1) == std::strong_ordering::greater); + CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::less); + CHECK_TRUE((ym3 <=> ym1) == std::strong_ordering::greater); } #endif @@ -108,12 +110,14 @@ namespace TEST(test_year_month_compare) { Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; - Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; - Chrono::year_month ym3{Chrono::year(2000), Chrono::January}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::January}; + Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; - CHECK_TRUE(ym1.compare(ym3) == 0); + CHECK_TRUE(ym1.compare(ym1) == 0); CHECK_TRUE(ym1.compare(ym2) == -1); CHECK_TRUE(ym2.compare(ym1) == 1); + CHECK_TRUE(ym1.compare(ym3) == -1); + CHECK_TRUE(ym3.compare(ym1) == 1); } #endif @@ -121,24 +125,24 @@ namespace TEST(test_year_month_equality_operator) { Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; - Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::January}; Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; - CHECK_TRUE(ym1 == ym1); // 2000/January - CHECK_FALSE(ym1 == ym2); // 2000/January != 2001/February - CHECK_FALSE(ym1 == ym3); // 2000/January != 2000/February + CHECK_TRUE(ym1 == ym1); // Same year/month/day + CHECK_FALSE(ym1 == ym2); // Different year + CHECK_FALSE(ym1 == ym3); // Different month } //************************************************************************* TEST(test_year_month_not_equality_operator) { Chrono::year_month ym1{Chrono::year(2000), Chrono::January}; - Chrono::year_month ym2{Chrono::year(2001), Chrono::February}; + Chrono::year_month ym2{Chrono::year(2001), Chrono::January}; Chrono::year_month ym3{Chrono::year(2000), Chrono::February}; - CHECK_FALSE(ym1 != ym1); // 2000/January - CHECK_TRUE(ym1 != ym2); // 2000/January != 2001/February - CHECK_TRUE(ym1 != ym3); // 2000/January != 2000/February + CHECK_FALSE(ym1 != ym1); // Same year/month/day + CHECK_TRUE(ym1 != ym2); // Different year + CHECK_TRUE(ym1 != ym3); // Different month } }; } diff --git a/test/test_chrono_year_month_day.cpp b/test/test_chrono_year_month_day.cpp new file mode 100644 index 000000000..77641c7d4 --- /dev/null +++ b/test/test_chrono_year_month_day.cpp @@ -0,0 +1,167 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2025 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_year_month_day) + { + //************************************************************************* + TEST(test_default_constructor) + { + Chrono::year_month_day ymd; + + CHECK_FALSE(ymd.ok()); // Default-constructed year_month_day is not valid + } + + //************************************************************************* + TEST(test_constructor_with_month_and_day) + { + Chrono::year_month_day ymd{Chrono::year(2000), Chrono::January, Chrono::day(1)}; + + CHECK_TRUE(ymd.ok()); // Valid year_month_day + CHECK_EQUAL(2000, (int)ymd.year()); + CHECK_EQUAL((unsigned)Chrono::January, (unsigned)ymd.month()); + CHECK_EQUAL(Chrono::day(1), ymd.day()); + } + + //************************************************************************* + TEST(test_invalid_year_month) + { + Chrono::year_month_day ymd{Chrono::year{32768}, Chrono::January, Chrono::day(1)}; // Invalid year + + CHECK_FALSE(ymd.ok()); // Invalid year_month_day + } + + //************************************************************************* + TEST(test_invalid_month_in_year_month) + { + Chrono::year_month_day ymd{Chrono::year{2000}, Chrono::month{13}, Chrono::day(1)}; // Invalid month (13) + + CHECK_FALSE(ymd.ok()); // Invalid year_month_day + } + + //************************************************************************* + TEST(test_invalid_day_in_year_month) + { + Chrono::year_month_day ymd{Chrono::year{2000}, Chrono::January, Chrono::day(32)}; // Invalid day (32) + + CHECK_FALSE(ymd.ok()); // Invalid year_month_day + } + +#if ETL_USING_CPP20 + //************************************************************************* + TEST(test_year_month_day_spaceship_operator) + { + Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)}; + Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)}; + + CHECK_TRUE((ym1 <=> ym1) == std::strong_ordering::equal); + CHECK_TRUE((ym1 <=> ym2) == std::strong_ordering::less); + CHECK_TRUE((ym2 <=> ym1) == std::strong_ordering::greater); + CHECK_TRUE((ym1 <=> ym3) == std::strong_ordering::less); + CHECK_TRUE((ym3 <=> ym1) == std::strong_ordering::greater); + CHECK_TRUE((ym1 <=> ym4) == std::strong_ordering::less); + CHECK_TRUE((ym4 <=> ym1) == std::strong_ordering::greater); + } +#endif + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_year_month_day_compare) + { + Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)}; + Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)}; + + CHECK_TRUE(ym1.compare(ym1) == 0); + CHECK_TRUE(ym1.compare(ym2) == -1); + CHECK_TRUE(ym2.compare(ym1) == 1); + CHECK_TRUE(ym1.compare(ym3) == -1); + CHECK_TRUE(ym3.compare(ym1) == 1); + CHECK_TRUE(ym1.compare(ym4) == -1); + CHECK_TRUE(ym4.compare(ym1) == 1); + } +#endif + + //************************************************************************* + TEST(test_year_month_day_equality_operator) + { + Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)}; + Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)}; + + CHECK_TRUE(ym1 == ym1); // Same year/month/day + CHECK_FALSE(ym1 == ym2); // Different year + CHECK_FALSE(ym1 == ym3); // Different month + CHECK_FALSE(ym1 == ym4); // Different day + } + + //************************************************************************* + TEST(test_year_month_day_not_equality_operator) + { + Chrono::year_month_day ym1{Chrono::year(2000), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym2{Chrono::year(2001), Chrono::January, Chrono::day(1)}; + Chrono::year_month_day ym3{Chrono::year(2000), Chrono::February, Chrono::day(1)}; + Chrono::year_month_day ym4{Chrono::year(2000), Chrono::January, Chrono::day(2)}; + + CHECK_FALSE(ym1 != ym1); // Same year/month/day + CHECK_TRUE(ym1 != ym2); // Different year + CHECK_TRUE(ym1 != ym3); // Different month + CHECK_TRUE(ym1 != ym4); // Different day + } + }; +} diff --git a/test/test_chrono_year_month_day_last.cpp b/test/test_chrono_year_month_day_last.cpp new file mode 100644 index 000000000..28df871a1 --- /dev/null +++ b/test/test_chrono_year_month_day_last.cpp @@ -0,0 +1,145 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: + +Copyright(c) 2025 John Wellbelove + +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 "etl/platform.h" + +#include "unit_test_framework.h" + +#include "etl/chrono.h" + +#include +#include +#include + +// Set to 0 to reference against std::chrono +#define ETL_USING_ETL_CHRONO 1 + +#if ETL_USING_ETL_CHRONO + #define Chrono etl::chrono +#else + #if ETL_USING_CPP20 + #include + #define Chrono std::chrono + #else + #error std::chrono not supported + #endif +#endif + +namespace +{ + SUITE(test_chrono_year_month_day_last) + { + //************************************************************************* + TEST(test_constructor_in_range) + { + Chrono::year_month_day_last year_month_day_last_2000_january(Chrono::year(2000), Chrono::month_day_last(Chrono::January)); + Chrono::year_month_day_last year_month_day_last_2001_february(Chrono::year(2001), Chrono::month_day_last(Chrono::February)); + Chrono::year_month_day_last year_month_day_last_2002_march(Chrono::year(2002), Chrono::month_day_last(Chrono::March)); + Chrono::year_month_day_last year_month_day_last_2003_april(Chrono::year(2003), Chrono::month_day_last(Chrono::April)); + Chrono::year_month_day_last year_month_day_last_2004_may(Chrono::year(2004), Chrono::month_day_last(Chrono::May)); + Chrono::year_month_day_last year_month_day_last_2005_june(Chrono::year(2005), Chrono::month_day_last(Chrono::June)); + Chrono::year_month_day_last year_month_day_last_2006_july(Chrono::year(2006), Chrono::month_day_last(Chrono::July)); + Chrono::year_month_day_last year_month_day_last_2007_august(Chrono::year(2007), Chrono::month_day_last(Chrono::August)); + Chrono::year_month_day_last year_month_day_last_2008_september(Chrono::year(2008), Chrono::month_day_last(Chrono::September)); + Chrono::year_month_day_last year_month_day_last_2009_october(Chrono::year(2009), Chrono::month_day_last(Chrono::October)); + Chrono::year_month_day_last year_month_day_last_2010_november(Chrono::year(2010), Chrono::month_day_last(Chrono::November)); + Chrono::year_month_day_last year_month_day_last_2011_december(Chrono::year(2011), Chrono::month_day_last(Chrono::December)); + + CHECK_TRUE(year_month_day_last_2000_january.ok()); + CHECK_TRUE(year_month_day_last_2001_february.ok()); + CHECK_TRUE(year_month_day_last_2002_march.ok()); + CHECK_TRUE(year_month_day_last_2003_april.ok()); + CHECK_TRUE(year_month_day_last_2004_may.ok()); + CHECK_TRUE(year_month_day_last_2005_june.ok()); + CHECK_TRUE(year_month_day_last_2006_july.ok()); + CHECK_TRUE(year_month_day_last_2007_august.ok()); + CHECK_TRUE(year_month_day_last_2008_september.ok()); + CHECK_TRUE(year_month_day_last_2009_october.ok()); + CHECK_TRUE(year_month_day_last_2010_november.ok()); + CHECK_TRUE(year_month_day_last_2011_december.ok()); + + CHECK_EQUAL(31, year_month_day_last_2000_january.day()); + CHECK_EQUAL(29, year_month_day_last_2001_february.day()); + CHECK_EQUAL(31, year_month_day_last_2002_march.day()); + CHECK_EQUAL(30, year_month_day_last_2003_april.day()); + CHECK_EQUAL(31, year_month_day_last_2004_may.day()); + CHECK_EQUAL(30, year_month_day_last_2005_june.day()); + CHECK_EQUAL(31, year_month_day_last_2006_july.day()); + CHECK_EQUAL(31, year_month_day_last_2007_august.day()); + CHECK_EQUAL(30, year_month_day_last_2008_september.day()); + CHECK_EQUAL(31, year_month_day_last_2009_october.day()); + CHECK_EQUAL(30, year_month_day_last_2010_november.day()); + CHECK_EQUAL(31, year_month_day_last_2011_december.day()); + } + + //************************************************************************* + TEST(test_year_month_day_last_comparison_operators) + { + Chrono::year_month_day_last year_month_day_last1(Chrono::year(2000), Chrono::month_day_last(Chrono::January)); + Chrono::year_month_day_last year_month_day_last2(Chrono::year(2001), Chrono::month_day_last(Chrono::January)); + Chrono::year_month_day_last year_month_day_last3(Chrono::year(2000), Chrono::month_day_last(Chrono::February)); + + CHECK_TRUE(year_month_day_last1 == year_month_day_last1); + CHECK_FALSE(year_month_day_last1 == year_month_day_last2); + CHECK_FALSE(year_month_day_last1 == year_month_day_last3); + + CHECK_FALSE(year_month_day_last1 != year_month_day_last1); + CHECK_TRUE(year_month_day_last1 != year_month_day_last2); + CHECK_TRUE(year_month_day_last1 != year_month_day_last3); + } + +#if ETL_USING_ETL_CHRONO + //************************************************************************* + TEST(test_year_month_day_last_hashes_are_unique) + { + std::vector hashes; + + for (int i = 0; i < 6; ++i) + { + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2000), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2001), Chrono::month_day_last(Chrono::February)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2002), Chrono::month_day_last(Chrono::March)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2003), Chrono::month_day_last(Chrono::April)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2004), Chrono::month_day_last(Chrono::May)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2005), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2006), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2007), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2008), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2009), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2010), Chrono::month_day_last(Chrono::January)))); + hashes.push_back(etl::hash()(Chrono::year_month_day_last(Chrono::year(2011), Chrono::month_day_last(Chrono::January)))); + } + + std::sort(hashes.begin(), hashes.end()); + (void)std::unique(hashes.begin(), hashes.end()); + } +#endif + }; +} diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 8489c79fd..e94c20bc3 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3197,6 +3197,7 @@ + @@ -8482,6 +8483,8 @@ + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 7dea846b7..04a090319 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1509,6 +1509,9 @@ ETL\Private\chrono + + ETL\Private\chrono + @@ -3566,6 +3569,12 @@ Tests\Chrono + + Tests\Chrono + + + Tests\Chrono + From 42ba4d824841fc002524c3d51221e4f7bcac19dd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 30 Apr 2025 09:26:34 +0100 Subject: [PATCH 144/216] Updated tests --- test/test_chrono_year_month_day_last.cpp | 27 +++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/test_chrono_year_month_day_last.cpp b/test/test_chrono_year_month_day_last.cpp index 28df871a1..3fc82f1af 100644 --- a/test/test_chrono_year_month_day_last.cpp +++ b/test/test_chrono_year_month_day_last.cpp @@ -60,6 +60,7 @@ namespace TEST(test_constructor_in_range) { Chrono::year_month_day_last year_month_day_last_2000_january(Chrono::year(2000), Chrono::month_day_last(Chrono::January)); + Chrono::year_month_day_last year_month_day_last_2000_february(Chrono::year(2000), Chrono::month_day_last(Chrono::February)); Chrono::year_month_day_last year_month_day_last_2001_february(Chrono::year(2001), Chrono::month_day_last(Chrono::February)); Chrono::year_month_day_last year_month_day_last_2002_march(Chrono::year(2002), Chrono::month_day_last(Chrono::March)); Chrono::year_month_day_last year_month_day_last_2003_april(Chrono::year(2003), Chrono::month_day_last(Chrono::April)); @@ -73,6 +74,7 @@ namespace Chrono::year_month_day_last year_month_day_last_2011_december(Chrono::year(2011), Chrono::month_day_last(Chrono::December)); CHECK_TRUE(year_month_day_last_2000_january.ok()); + CHECK_TRUE(year_month_day_last_2000_february.ok()); CHECK_TRUE(year_month_day_last_2001_february.ok()); CHECK_TRUE(year_month_day_last_2002_march.ok()); CHECK_TRUE(year_month_day_last_2003_april.ok()); @@ -85,18 +87,19 @@ namespace CHECK_TRUE(year_month_day_last_2010_november.ok()); CHECK_TRUE(year_month_day_last_2011_december.ok()); - CHECK_EQUAL(31, year_month_day_last_2000_january.day()); - CHECK_EQUAL(29, year_month_day_last_2001_february.day()); - CHECK_EQUAL(31, year_month_day_last_2002_march.day()); - CHECK_EQUAL(30, year_month_day_last_2003_april.day()); - CHECK_EQUAL(31, year_month_day_last_2004_may.day()); - CHECK_EQUAL(30, year_month_day_last_2005_june.day()); - CHECK_EQUAL(31, year_month_day_last_2006_july.day()); - CHECK_EQUAL(31, year_month_day_last_2007_august.day()); - CHECK_EQUAL(30, year_month_day_last_2008_september.day()); - CHECK_EQUAL(31, year_month_day_last_2009_october.day()); - CHECK_EQUAL(30, year_month_day_last_2010_november.day()); - CHECK_EQUAL(31, year_month_day_last_2011_december.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2000_january.day()); + CHECK_EQUAL(29, (unsigned)year_month_day_last_2000_february.day()); + CHECK_EQUAL(28, (unsigned)year_month_day_last_2001_february.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2002_march.day()); + CHECK_EQUAL(30, (unsigned)year_month_day_last_2003_april.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2004_may.day()); + CHECK_EQUAL(30, (unsigned)year_month_day_last_2005_june.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2006_july.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2007_august.day()); + CHECK_EQUAL(30, (unsigned)year_month_day_last_2008_september.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2009_october.day()); + CHECK_EQUAL(30, (unsigned)year_month_day_last_2010_november.day()); + CHECK_EQUAL(31, (unsigned)year_month_day_last_2011_december.day()); } //************************************************************************* From 2b141e0f22cc35092d8dea5a7047846513741d47 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 30 Apr 2025 12:07:15 +0100 Subject: [PATCH 145/216] Fixed tests to be compatible with std::chrono --- include/etl/private/chrono/duration.h | 56 +++++++++++++-------- include/etl/private/chrono/month.h | 10 +--- include/etl/private/chrono/year_month_day.h | 33 ++++++++++-- test/test_chrono_duration.cpp | 46 ++++++++++++----- test/test_chrono_month_day_last.cpp | 13 ----- test/test_chrono_operators.cpp | 5 -- test/test_chrono_weekday_last.cpp | 2 + 7 files changed, 100 insertions(+), 65 deletions(-) diff --git a/include/etl/private/chrono/duration.h b/include/etl/private/chrono/duration.h index 409a24867..5494c8e5d 100644 --- a/include/etl/private/chrono/duration.h +++ b/include/etl/private/chrono/duration.h @@ -412,7 +412,8 @@ namespace etl /// Check equality. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator ==(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator ==(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { typedef typename etl::common_type, etl::chrono::duration >::type common_t; @@ -426,7 +427,8 @@ namespace etl /// Check inequality. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator !=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator !=(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { return !(lhs == rhs); } @@ -435,7 +437,8 @@ namespace etl /// Less-than. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator <(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator <(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { typedef typename etl::common_type, etl::chrono::duration >::type common_t; @@ -449,7 +452,8 @@ namespace etl /// Less-than-or-equal. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator <=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator <=(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { return !(rhs < lhs); } @@ -458,7 +462,8 @@ namespace etl /// Greater-than. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator >(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator >(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { return rhs < lhs; } @@ -467,7 +472,8 @@ namespace etl /// Greater-than-or-equal. //*********************************************************************** template - ETL_CONSTEXPR14 bool operator >=(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 bool operator >=(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { return !(lhs < rhs); } @@ -477,7 +483,8 @@ namespace etl //*********************************************************************** #if ETL_USING_CPP20 template - [[nodiscard]] constexpr auto operator <=>(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) noexcept + [[nodiscard]] constexpr auto operator <=>(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) noexcept { typedef typename etl::common_type, etl::chrono::duration >::type common_t; @@ -493,7 +500,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 typename etl::common_type, etl::chrono::duration >::type - operator +(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + operator +(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { // Determine the common type of the two durations. using common_duration = typename etl::common_type, etl::chrono::duration>::type; @@ -511,7 +519,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 typename etl::common_type, etl::chrono::duration >::type - operator -(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + operator -(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { // Determine the common type of the two durations. using common_duration = typename etl::common_type, etl::chrono::duration>::type; @@ -529,7 +538,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> - operator *(const etl::chrono::duration& lhs, const TRep2& rhs) + operator *(const etl::chrono::duration& lhs, + const TRep2& rhs) { using common_rep = typename etl::common_type::type; using result_duration = etl::chrono::duration; @@ -543,7 +553,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod2> - operator *(const TRep1& lhs, const etl::chrono::duration& rhs) + operator *(const TRep1& lhs, + const etl::chrono::duration& rhs) { using common_rep = typename etl::common_type::type; using result_duration = etl::chrono::duration; @@ -557,7 +568,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> - operator /(const etl::chrono::duration& lhs, const TRep2& rhs) + operator /(const etl::chrono::duration& lhs, + const TRep2& rhs) { using common_rep = typename etl::common_type::type; using result_duration = etl::chrono::duration; @@ -571,7 +583,8 @@ namespace etl //*********************************************************************** template ETL_CONSTEXPR14 typename etl::common_type::type - operator /(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + operator /(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { // Determine the common type of the two durations. using common_duration = typename etl::common_type, etl::chrono::duration>::type; @@ -586,22 +599,23 @@ namespace etl /// Operator % //*********************************************************************** template - ETL_CONSTEXPR14 etl::chrono::duration::type, TPeriod1> - operator %(const etl::chrono::duration& lhs, const TRep2& rhs) + ETL_CONSTEXPR14 typename etl::common_type::type + operator %(const etl::chrono::duration& lhs, + const TRep2& rhs) { - using common_rep = typename etl::common_type::type; - using result_duration = etl::chrono::duration; + using common_rep = typename etl::common_type::type; // Mod the count of the duration by the scalar value - return result_duration(static_cast(lhs.count()) % static_cast(rhs)); + return common_rep(static_cast(lhs.count()) % static_cast(rhs)); } //*********************************************************************** /// Operator % //*********************************************************************** template - ETL_CONSTEXPR14 typename etl::common_type::type - operator %(const etl::chrono::duration& lhs, const etl::chrono::duration& rhs) + ETL_CONSTEXPR14 typename etl::common_type, etl::chrono::duration>::type + operator %(const etl::chrono::duration& lhs, + const etl::chrono::duration& rhs) { // Determine the common type of the two durations. using common_duration = typename etl::common_type, etl::chrono::duration>::type; @@ -609,7 +623,7 @@ namespace etl common_duration lhs_converted = etl::chrono::duration_cast(lhs); common_duration rhs_converted = etl::chrono::duration_cast(rhs); - return typename etl::common_type::type(lhs_converted.count() % rhs_converted.count()); + return common_duration(lhs_converted.count() % rhs_converted.count()); } } diff --git a/include/etl/private/chrono/month.h b/include/etl/private/chrono/month.h index 5b1e3678d..538495939 100644 --- a/include/etl/private/chrono/month.h +++ b/include/etl/private/chrono/month.h @@ -44,7 +44,7 @@ namespace etl namespace private_chrono { - static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + static ETL_CONSTANT unsigned char days_in_month[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; } //*********************************************************************** @@ -385,14 +385,6 @@ namespace etl return m; } - //************************************************************************* - /// Returns the last day of the month - //************************************************************************* - ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT - { - return etl::chrono::day(private_chrono::days_in_month[static_cast(m)]); - } - //************************************************************************* /// Is the contained month OK? //************************************************************************* diff --git a/include/etl/private/chrono/year_month_day.h b/include/etl/private/chrono/year_month_day.h index 0cae2211e..7b60c9071 100644 --- a/include/etl/private/chrono/year_month_day.h +++ b/include/etl/private/chrono/year_month_day.h @@ -94,11 +94,13 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT { + private_chrono::days_in_month[m]; + // Check if the year, month, and day are valid individually return y.ok() && m.ok() && d.ok() && - d <= etl::chrono::month_day_last(m).day(); + d <= max_day_for_month(); } //************************************************************************* @@ -254,6 +256,27 @@ namespace etl private: + //*********************************************************************** + /// Calculates the last day in the year/month. + /// Returns 0 if either the year or month are not OK. + //*********************************************************************** + etl::chrono::day max_day_for_month() const + { + unsigned char count = 0; + + if (y.ok() && m.ok()) + { + count = private_chrono::days_in_month[m]; + + if (y.is_leap() && (m == February)) + { + ++count; + } + } + + return etl::chrono::day(count); + } + etl::chrono::year y; etl::chrono::month m; etl::chrono::day d; @@ -297,7 +320,9 @@ namespace etl //************************************************************************* ETL_CONSTEXPR etl::chrono::day day() const ETL_NOEXCEPT { - return etl::chrono::month_day_last(m).day(); + etl::chrono::day d = etl::chrono::day(etl::chrono::private_chrono::days_in_month[m]); + + return (d == 28) && y.is_leap() ? etl::chrono::day(29) : d; } //************************************************************************* @@ -313,9 +338,7 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT { - return y.ok() && - m.ok() && - day() == etl::chrono::month_day_last(m).day(); + return y.ok() && m.ok(); } //************************************************************************* diff --git a/test/test_chrono_duration.cpp b/test/test_chrono_duration.cpp index 90bca5358..6b8f3043d 100644 --- a/test/test_chrono_duration.cpp +++ b/test/test_chrono_duration.cpp @@ -57,6 +57,7 @@ namespace { SUITE(test_chrono_duration) { +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_default_constructor) { @@ -68,6 +69,7 @@ namespace CHECK_TRUE((etl::is_same::value)); CHECK_EQUAL(0, duration.count()); } +#endif //************************************************************************* TEST(test_duration_values_zero_min_max) @@ -79,6 +81,7 @@ namespace CHECK_EQUAL(std::numeric_limits::max(), duration_values_type::max()); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_zero_min_max) { @@ -88,6 +91,7 @@ namespace CHECK_EQUAL(duration_type(std::numeric_limits::min()).count(), duration_type::min().count()); CHECK_EQUAL(duration_type(std::numeric_limits::max()).count(), duration_type::max().count()); } +#endif //************************************************************************* TEST(test_predefined_duration_periods) @@ -126,18 +130,21 @@ namespace CHECK_EQUAL(etl::ratio<31556952U>::type::den, Chrono::years::period::den); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_common_type) { using duration_type1 = Chrono::duration; using duration_type2 = Chrono::duration; - using duration_type = etl::common_type::type; + using duration_type = etl::common_type_t; - CHECK_TRUE((std::is_same::value)); + CHECK_TRUE((std::is_same::value)); CHECK_TRUE((std::is_same::value)); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_cast_with_same_rep_and_period_for_duration_type1_and_duration_type2) { @@ -151,7 +158,9 @@ namespace CHECK_EQUAL(duration_type1::period::den, duration_type2::period::den); CHECK_EQUAL(dur1.count(), dur2.count()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_cast_where_ratio_divide_of_periods_num_is_1) { @@ -168,7 +177,9 @@ namespace CHECK_EQUAL(1, ratio_divide_t::num); CHECK_EQUAL(dur1.count(), dur2.count() * microseonds_per_millisecond); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_cast_where_ratio_divide_of_periods_den_is_1) { @@ -185,7 +196,9 @@ namespace CHECK_EQUAL(1, ratio_divide_t::den); CHECK_EQUAL(dur1.count() * microseonds_per_millisecond, dur2.count()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_cast_when_rep_and_period_are_not_equal_and_ratio_divide_of_periods_num_and_den_are_not_1) { @@ -202,6 +215,7 @@ namespace CHECK_FALSE(1 == ratio_divide_t::den); CHECK_EQUAL(dur1.count(), (dur2.count() * duration_type2::period::num) / duration_type1::period::num); } +#endif //************************************************************************* TEST(test_duration_assignment) @@ -223,6 +237,7 @@ namespace CHECK_EQUAL(Four_Hours, hours2.count()); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_comparison_operators) { @@ -276,7 +291,9 @@ namespace CHECK_FALSE(dur1a >= dur2c); CHECK_TRUE(dur2c >= dur1a); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_unary_operators) { @@ -290,7 +307,9 @@ namespace CHECK_EQUAL(245, positive.count()); CHECK_EQUAL(-245, negative.count()); } +#endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_hashes_are_unique) { @@ -307,6 +326,7 @@ namespace (void)std::unique(hashes.begin(), hashes.end()); CHECK_EQUAL(256U, hashes.size()); } +#endif //************************************************************************* TEST(test_duration_pre_increment) @@ -779,7 +799,7 @@ namespace auto result = s1 % scalar; - CHECK_EQUAL(1, result.count()); // 10 % 3 = 1 second + CHECK_EQUAL(1, result); // 10 % 3 = 1 second } //************************************************************************* @@ -790,7 +810,7 @@ namespace auto result = s1 % scalar; - CHECK_EQUAL(1, result.count()); // 10 % -3 = 1 second (modulus result is positive) + CHECK_EQUAL(1, result); // 10 % -3 = 1 second (modulus result is positive) } //************************************************************************* @@ -801,7 +821,7 @@ namespace auto result = s1 % scalar; - CHECK_EQUAL(10, result.count()); // 10 % 100 = 10 seconds + CHECK_EQUAL(10, result); // 10 % 100 = 10 seconds } //************************************************************************* @@ -812,7 +832,7 @@ namespace auto result = ms1 % scalar; - CHECK_EQUAL(50, result.count()); // 1050 % 500 = 50 milliseconds + CHECK_EQUAL(50, result); // 1050 % 500 = 50 milliseconds } //************************************************************************* @@ -823,7 +843,7 @@ namespace auto result = s1 % s2; - CHECK_EQUAL(1, result); // 10 % 3 = 1 second + CHECK_EQUAL(1, result.count()); // 10 % 3 = 1 second } //************************************************************************* @@ -835,7 +855,7 @@ namespace auto result = s1 % ms1; // Result should be in the common type (milliseconds) - CHECK_EQUAL(1000, result); // 10 seconds % 3000 milliseconds = 1000 milliseconds + CHECK_EQUAL(1000, result.count()); // 10 seconds % 3000 milliseconds = 1000 milliseconds } //************************************************************************* @@ -846,7 +866,7 @@ namespace auto result = s1 % ms1; - CHECK_EQUAL(0, result); // 1,000,000 seconds % 500,000 milliseconds = 0 + CHECK_EQUAL(0, result.count()); // 1,000,000 seconds % 500,000 milliseconds = 0 } //************************************************************************* @@ -857,7 +877,7 @@ namespace auto result = s1 % s2; - CHECK_EQUAL(1, result); // 7 % 3 = 1 second + CHECK_EQUAL(1, result.count()); // 7 % 3 = 1 second } //************************************************************************* @@ -868,7 +888,7 @@ namespace auto result = s1 % s2; - CHECK_EQUAL(5, result); // 5 % 10 = 5 seconds + CHECK_EQUAL(5, result.count()); // 5 % 10 = 5 seconds } //************************************************************************* @@ -880,7 +900,7 @@ namespace auto result = s1 % ms1; // Result should be in the common type (milliseconds) - CHECK_EQUAL(0, result); // 10 seconds % 2500 milliseconds = 0 milliseconds + CHECK_EQUAL(0, result.count()); // 10 seconds % 2500 milliseconds = 0 milliseconds } //************************************************************************* @@ -1028,6 +1048,7 @@ namespace } #endif +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_duration_compare) { @@ -1038,5 +1059,6 @@ namespace CHECK_EQUAL(-1, ms1.compare(s1)); CHECK_EQUAL(1, s1.compare(ms1)); } +#endif }; } diff --git a/test/test_chrono_month_day_last.cpp b/test/test_chrono_month_day_last.cpp index f47792c71..ec9b6ae4f 100644 --- a/test/test_chrono_month_day_last.cpp +++ b/test/test_chrono_month_day_last.cpp @@ -84,19 +84,6 @@ namespace CHECK_TRUE(month_day_last_october.ok()); CHECK_TRUE(month_day_last_november.ok()); CHECK_TRUE(month_day_last_december.ok()); - - CHECK_EQUAL(31, month_day_last_january.day()); - CHECK_EQUAL(29, month_day_last_february.day()); - CHECK_EQUAL(31, month_day_last_march.day()); - CHECK_EQUAL(30, month_day_last_april.day()); - CHECK_EQUAL(31, month_day_last_may.day()); - CHECK_EQUAL(30, month_day_last_june.day()); - CHECK_EQUAL(31, month_day_last_july.day()); - CHECK_EQUAL(31, month_day_last_august.day()); - CHECK_EQUAL(30, month_day_last_september.day()); - CHECK_EQUAL(31, month_day_last_october.day()); - CHECK_EQUAL(30, month_day_last_november.day()); - CHECK_EQUAL(31, month_day_last_december.day()); } //************************************************************************* diff --git a/test/test_chrono_operators.cpp b/test/test_chrono_operators.cpp index f9f55b786..717d653e6 100644 --- a/test/test_chrono_operators.cpp +++ b/test/test_chrono_operators.cpp @@ -193,27 +193,22 @@ namespace CHECK_EQUAL(etl::chrono::year(2000), ymdl1.year()); CHECK_EQUAL(etl::chrono::January, ymdl1.month()); - CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).day(), ymdl1.day()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::January).month(), ymdl1.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2001), ymdl2.year()); CHECK_EQUAL(etl::chrono::February, ymdl2.month()); - CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).day(), ymdl2.day()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::February).month(), ymdl2.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2002), ymdl3.year()); CHECK_EQUAL(etl::chrono::March, ymdl3.month()); - CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).day(), ymdl3.day()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::March).month(), ymdl3.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2003), ymdl4.year()); CHECK_EQUAL(etl::chrono::April, ymdl4.month()); - CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).day(), ymdl4.day()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::April).month(), ymdl4.month_day_last().month()); CHECK_EQUAL(etl::chrono::year(2004), ymdl5.year()); CHECK_EQUAL(etl::chrono::May, ymdl5.month()); - CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).day(), ymdl5.day()); CHECK_EQUAL(etl::chrono::month_day_last(etl::chrono::May).month(), ymdl5.month_day_last().month()); } diff --git a/test/test_chrono_weekday_last.cpp b/test/test_chrono_weekday_last.cpp index a3a2a0783..4db7e658f 100644 --- a/test/test_chrono_weekday_last.cpp +++ b/test/test_chrono_weekday_last.cpp @@ -110,6 +110,7 @@ namespace CHECK_FALSE(weekday_last1 == weekday_last3); } +#if ETL_USING_ETL_CHRONO //************************************************************************* TEST(test_weekday_last_hashes_are_unique) { @@ -129,5 +130,6 @@ namespace std::sort(hashes.begin(), hashes.end()); (void)std::unique(hashes.begin(), hashes.end()); } +#endif }; } From a1ec6136301aca8f7f2a2fad57bd207c7222afdc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 30 Apr 2025 12:11:23 +0100 Subject: [PATCH 146/216] Fixed parameter shadowing warnings --- include/etl/private/chrono/year_month_day.h | 22 +++++++++---------- .../etl/private/chrono/year_month_weekday.h | 12 +++++----- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/include/etl/private/chrono/year_month_day.h b/include/etl/private/chrono/year_month_day.h index 7b60c9071..53a14619d 100644 --- a/include/etl/private/chrono/year_month_day.h +++ b/include/etl/private/chrono/year_month_day.h @@ -94,8 +94,6 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT { - private_chrono::days_in_month[m]; - // Check if the year, month, and day are valid individually return y.ok() && m.ok() && @@ -292,10 +290,10 @@ namespace etl //************************************************************************* /// //************************************************************************* - ETL_CONSTEXPR year_month_day_last(const etl::chrono::year& y, - const etl::chrono::month_day_last& mdl) ETL_NOEXCEPT - : y(y) - , m(mdl.month()) + ETL_CONSTEXPR year_month_day_last(const etl::chrono::year& y_, + const etl::chrono::month_day_last& mdl_) ETL_NOEXCEPT + : y(y_) + , m(mdl_.month()) { } @@ -460,19 +458,19 @@ namespace etl [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_day_last& lhs, const etl::chrono::year_month_day_last& rhs) ETL_NOEXCEPT { - auto cmp = lhs.year() <=> rhs.year(); + auto cmp1 = lhs.year() <=> rhs.year(); - if (cmp != 0) + if (cmp1 != 0) { - return cmp; + return cmp1; } else { - auto cmp = lhs.month() <=> rhs.month(); + auto cmp2 = lhs.month() <=> rhs.month(); - if (cmp != 0) + if (cmp2 != 0) { - return cmp; + return cmp2; } else { diff --git a/include/etl/private/chrono/year_month_weekday.h b/include/etl/private/chrono/year_month_weekday.h index 03242c6eb..b12be8057 100644 --- a/include/etl/private/chrono/year_month_weekday.h +++ b/include/etl/private/chrono/year_month_weekday.h @@ -403,19 +403,19 @@ namespace etl [[nodiscard]] friend constexpr auto operator <=>(const etl::chrono::year_month_weekday_last& lhs, const etl::chrono::year_month_weekday_last& rhs) ETL_NOEXCEPT { - auto cmp = lhs.year() <=> rhs.year(); + auto cmp1 = lhs.year() <=> rhs.year(); - if (cmp != 0) + if (cmp1 != 0) { - return cmp; + return cmp1; } else { - auto cmp = lhs.month() <=> rhs.month(); + auto cmp2 = lhs.month() <=> rhs.month(); - if (cmp != 0) + if (cmp2 != 0) { - return cmp; + return cmp2; } else { From 6ed64f7b21f49db2d4f19207901a71580c157800 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 30 Apr 2025 13:22:38 +0200 Subject: [PATCH 147/216] Support const pointers in etl::is_aligned() (#1082) * Add Zephyr build system module.yml (#1074) The Zephyr build system requires that modules have a `module.yml` file to specify where the module cmake and kconfig files are located. These can also be explicitly set as "external" meaning that they do not exist within the module tree, itself. These build file can still be specified elsewhere via cmake variables, explained more in-depth here: https://docs.zephyrproject.org/latest/develop/modules.html#modules-module-ext-root This change makes it such that ETL can be included more easily in zephyr projects running on embedded systems. A similar change can be observed in the public nanopb repository, where the repo only requires its own `zephyr/module.yml` file to be found by the zephyr build system, but the kconfig and cmake additions can exist outside of the library repository. * Support const pointers to etl::is_aligned() --------- Co-authored-by: Zach Van Camp --- include/etl/alignment.h | 6 +++--- test/test_alignment.cpp | 17 +++++++++++++++++ zephyr/module.yml | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 zephyr/module.yml diff --git a/include/etl/alignment.h b/include/etl/alignment.h index 627517be3..dab558322 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -88,7 +88,7 @@ namespace etl //***************************************************************************** /// Check that 'p' has 'required_alignment'. //***************************************************************************** - inline bool is_aligned(void* p, size_t required_alignment) + inline bool is_aligned(const void* p, size_t required_alignment) { uintptr_t address = reinterpret_cast(p); return (address % required_alignment) == 0U; @@ -98,7 +98,7 @@ namespace etl /// Check that 'p' has 'Alignment'. //***************************************************************************** template - bool is_aligned(void* p) + bool is_aligned(const void* p) { uintptr_t address = reinterpret_cast(p); return (address % Alignment) == 0U; @@ -108,7 +108,7 @@ namespace etl /// Check that 'p' has the alignment of 'T'. //***************************************************************************** template - bool is_aligned(void* p) + bool is_aligned(const void* p) { return is_aligned::value>(p); } diff --git a/test/test_alignment.cpp b/test/test_alignment.cpp index d9a9de57b..73c1f00fb 100644 --- a/test/test_alignment.cpp +++ b/test/test_alignment.cpp @@ -161,6 +161,23 @@ namespace CHECK_FALSE(etl::is_aligned(p)); } + //************************************************************************* + TEST(test_is_aligned_tests_const) + { + alignas(uint32_t) const char buffer[2U * sizeof(uint32_t)] = {0, 1}; + + const char* p = buffer; + + CHECK_TRUE(etl::is_aligned(p, std::alignment_of())); + CHECK_TRUE(etl::is_aligned(p)); + CHECK_TRUE(etl::is_aligned(p)); + + ++p; + CHECK_FALSE(etl::is_aligned(p, std::alignment_of())); + CHECK_FALSE(etl::is_aligned(p)); + CHECK_FALSE(etl::is_aligned(p)); + } + //************************************************************************* TEST(test_type_with_alignment) { diff --git a/zephyr/module.yml b/zephyr/module.yml new file mode 100644 index 000000000..b8bf28d43 --- /dev/null +++ b/zephyr/module.yml @@ -0,0 +1,4 @@ +name: etl +build: + cmake-ext: true + kconfig-ext: true From 2fd4e171baba19318a14e593963ae5d0efe3b878 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Wed, 30 Apr 2025 20:47:39 +0500 Subject: [PATCH 148/216] rise up cmake minimum required (#1066) Co-authored-by: John Wellbelove --- CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- test/UnitTest++/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f81b8bbe..1be0f648d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ ####################################################################### # The Embedded Template Library (https://www.etlcpp.com/) ####################################################################### -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8747bcb48..f88666567 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10.0) +cmake_minimum_required(VERSION 3.10) project(etl_unit_tests LANGUAGES CXX) #include(FetchContent) diff --git a/test/UnitTest++/CMakeLists.txt b/test/UnitTest++/CMakeLists.txt index 934c93b02..1d0e0b577 100644 --- a/test/UnitTest++/CMakeLists.txt +++ b/test/UnitTest++/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.5.0) +cmake_minimum_required(VERSION 3.10) project(UnitTestpp LANGUAGES CXX) add_library(UnitTestpp From f0af24b6038ba2801826db5974ac9baed980fece Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 30 Apr 2025 17:49:02 +0200 Subject: [PATCH 149/216] Various cleanup changes (#1049) * Various Cleanup Remove remove() by pointer because erase() can be used for that Fix signed distance handling, with added check for order Add missing file ID Fix File IDs Added test for algorithm.h * Improve types --- include/etl/algorithm.h | 49 +++++++++++++++++++++++---- include/etl/file_error_numbers.h | 1 + include/etl/intrusive_forward_list.h | 23 ------------- include/etl/intrusive_list.h | 2 +- include/etl/private/bitset_new.h | 4 +-- include/etl/queue.h | 2 -- include/etl/reference_flat_multiset.h | 2 +- include/etl/reference_flat_set.h | 2 +- include/etl/singleton_base.h | 2 +- test/test_algorithm.cpp | 11 ++++++ test/test_intrusive_forward_list.cpp | 29 ---------------- 11 files changed, 60 insertions(+), 67 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 5dc231bb3..db5c3a2a5 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -44,6 +44,8 @@ SOFTWARE. #include "functional.h" #include "utility.h" #include "gcd.h" +#include "error_handler.h" +#include "exception.h" #include #include @@ -82,6 +84,27 @@ namespace etl template ETL_CONSTEXPR14 void insertion_sort(TIterator first, TIterator last, TCompare compare); + + class algorithm_exception : public etl::exception + { + public: + + algorithm_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + class algorithm_error : public algorithm_exception + { + public: + + algorithm_error(string_type file_name_, numeric_type line_number_) + : algorithm_exception(ETL_ERROR_TEXT("algorithm:error", ETL_ALGORITHM_FILE_ID"A"), file_name_, line_number_) + { + } + }; + } //***************************************************************************** @@ -2262,11 +2285,17 @@ namespace etl TOutputIterator o_begin, TOutputIterator o_end) { - size_t s_size = etl::distance(i_begin, i_end); - size_t d_size = etl::distance(o_begin, o_end); - size_t size = (s_size < d_size) ? s_size : d_size; + using s_size_type = typename iterator_traits::difference_type; + using d_size_type = typename iterator_traits::difference_type; + using min_size_type = typename etl::common_type::type; + + s_size_type s_size = etl::distance(i_begin, i_end); + ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error)); + d_size_type d_size = etl::distance(o_begin, o_end); + ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error)); + min_size_type size = etl::min(s_size, d_size); - return etl::copy(i_begin, i_begin + size, o_begin); + return etl::copy(i_begin, i_begin + size, o_begin); } //*************************************************************************** @@ -2429,9 +2458,15 @@ namespace etl TOutputIterator o_begin, TOutputIterator o_end) { - size_t s_size = etl::distance(i_begin, i_end); - size_t d_size = etl::distance(o_begin, o_end); - size_t size = (s_size < d_size) ? s_size : d_size; + using s_size_type = typename iterator_traits::difference_type; + using d_size_type = typename iterator_traits::difference_type; + using min_size_type = typename etl::common_type::type; + + s_size_type s_size = etl::distance(i_begin, i_end); + ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error)); + d_size_type d_size = etl::distance(o_begin, o_end); + ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error)); + min_size_type size = etl::min(s_size, d_size); return etl::move(i_begin, i_begin + size, o_begin); } diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 64d94d573..3de007228 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -105,4 +105,5 @@ SOFTWARE. #define ETL_BASE64_FILE_ID "72" #define ETL_SINGLETON_BASE_FILE_ID "73" #define ETL_UNALIGNED_TYPE_FILE_ID "74" +#define ETL_ALGORITHM_FILE_ID "75" #endif diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index d1a024fcf..84d0aa94e 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -991,29 +991,6 @@ namespace etl } } - //************************************************************************* - // Removes the element specified by pointer. - //************************************************************************* - void remove(const_pointer element) - { - iterator i_item = begin(); - iterator i_last_item = before_begin(); - - while (i_item != end()) - { - if (&i_item == element) - { - i_item = erase_after(i_last_item); - return; - } - else - { - ++i_item; - ++i_last_item; - } - } - } - //************************************************************************* /// Removes according to a predicate. //************************************************************************* diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 6bbd906f5..5d3aec2c9 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -113,7 +113,7 @@ namespace etl public: intrusive_list_value_is_already_linked(string_type file_name_, numeric_type line_number_) - : intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"E"), file_name_, line_number_) + : intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"D"), file_name_, line_number_) { } }; diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index 2fcbc990e..e7673f4bb 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -141,7 +141,7 @@ namespace etl public: bitset_overflow(string_type file_name_, numeric_type line_number_) - : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"C"), file_name_, line_number_) + : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"B"), file_name_, line_number_) { } }; @@ -155,7 +155,7 @@ namespace etl public: bitset_invalid_buffer(string_type file_name_, numeric_type line_number_) - : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"D"), file_name_, line_number_) + : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"C"), file_name_, line_number_) { } }; diff --git a/include/etl/queue.h b/include/etl/queue.h index 99e4d50eb..47e9d4703 100644 --- a/include/etl/queue.h +++ b/include/etl/queue.h @@ -32,9 +32,7 @@ SOFTWARE. #define ETL_QUEUE_INCLUDED #include "platform.h" -#include "iterator.h" #include "alignment.h" -#include "array.h" #include "exception.h" #include "error_handler.h" #include "debug_count.h" diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 9d43848df..78abcce94 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -86,7 +86,7 @@ namespace etl public: flat_multiset_iterator(string_type file_name_, numeric_type line_number_) - : flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"C"), file_name_, line_number_) + : flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index dfb654247..44bbea965 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -87,7 +87,7 @@ namespace etl public: flat_set_iterator(string_type file_name_, numeric_type line_number_) - : flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"C"), file_name_, line_number_) + : flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/include/etl/singleton_base.h b/include/etl/singleton_base.h index eb9653b4b..72f0744aa 100644 --- a/include/etl/singleton_base.h +++ b/include/etl/singleton_base.h @@ -78,7 +78,7 @@ namespace etl public: singleton_base_already_created(string_type file_name_, numeric_type line_number_) - : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"A"), file_name_, line_number_) + : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index f12427189..2d362dd94 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -1364,6 +1364,17 @@ namespace CHECK(is_same); } + //************************************************************************* + TEST(copy_s_random_iterator) + { + int data1[] = { 1, 2, 3, 4, 5 }; + int out1[10]; + CHECK_THROW(etl::copy_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error); + CHECK_THROW(etl::copy_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error); + CHECK_THROW(etl::move_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error); + CHECK_THROW(etl::move_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error); + } + //************************************************************************* TEST(copy_4_parameter_non_random_iterator) { diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 8134f921c..20c8d830c 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -859,35 +859,6 @@ namespace CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_remove_by_pointer) - { - std::forward_list compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC0 data0(sorted_data.begin(), sorted_data.end()); - DataNDC1 data1(sorted_data.begin(), sorted_data.end()); - - auto it = data0.begin(); - for (int i = 0; i < 7; ++i) - { - it++; - } - ItemNDCNode* element = ⁢ - - compare_data.remove(ItemNDCNode("7")); - data0.remove(*element); - - bool are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); - - CHECK(are_equal); - CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); - - are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); - CHECK(are_equal); - CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_remove_if) { From 49acd2d2abce604218dbe2a455e3267f0c028fee Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Wed, 30 Apr 2025 17:49:02 +0200 Subject: [PATCH 150/216] Various cleanup changes (#1049) * Various Cleanup Remove remove() by pointer because erase() can be used for that Fix signed distance handling, with added check for order Add missing file ID Fix File IDs Added test for algorithm.h * Improve types # Conflicts: # include/etl/file_error_numbers.h --- include/etl/algorithm.h | 49 +++++++++++++++++++++++---- include/etl/file_error_numbers.h | 2 +- include/etl/intrusive_forward_list.h | 23 ------------- include/etl/intrusive_list.h | 2 +- include/etl/private/bitset_new.h | 4 +-- include/etl/queue.h | 2 -- include/etl/reference_flat_multiset.h | 2 +- include/etl/reference_flat_set.h | 2 +- include/etl/singleton_base.h | 2 +- test/test_algorithm.cpp | 11 ++++++ test/test_intrusive_forward_list.cpp | 29 ---------------- 11 files changed, 60 insertions(+), 68 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 5dc231bb3..db5c3a2a5 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -44,6 +44,8 @@ SOFTWARE. #include "functional.h" #include "utility.h" #include "gcd.h" +#include "error_handler.h" +#include "exception.h" #include #include @@ -82,6 +84,27 @@ namespace etl template ETL_CONSTEXPR14 void insertion_sort(TIterator first, TIterator last, TCompare compare); + + class algorithm_exception : public etl::exception + { + public: + + algorithm_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + class algorithm_error : public algorithm_exception + { + public: + + algorithm_error(string_type file_name_, numeric_type line_number_) + : algorithm_exception(ETL_ERROR_TEXT("algorithm:error", ETL_ALGORITHM_FILE_ID"A"), file_name_, line_number_) + { + } + }; + } //***************************************************************************** @@ -2262,11 +2285,17 @@ namespace etl TOutputIterator o_begin, TOutputIterator o_end) { - size_t s_size = etl::distance(i_begin, i_end); - size_t d_size = etl::distance(o_begin, o_end); - size_t size = (s_size < d_size) ? s_size : d_size; + using s_size_type = typename iterator_traits::difference_type; + using d_size_type = typename iterator_traits::difference_type; + using min_size_type = typename etl::common_type::type; + + s_size_type s_size = etl::distance(i_begin, i_end); + ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error)); + d_size_type d_size = etl::distance(o_begin, o_end); + ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error)); + min_size_type size = etl::min(s_size, d_size); - return etl::copy(i_begin, i_begin + size, o_begin); + return etl::copy(i_begin, i_begin + size, o_begin); } //*************************************************************************** @@ -2429,9 +2458,15 @@ namespace etl TOutputIterator o_begin, TOutputIterator o_end) { - size_t s_size = etl::distance(i_begin, i_end); - size_t d_size = etl::distance(o_begin, o_end); - size_t size = (s_size < d_size) ? s_size : d_size; + using s_size_type = typename iterator_traits::difference_type; + using d_size_type = typename iterator_traits::difference_type; + using min_size_type = typename etl::common_type::type; + + s_size_type s_size = etl::distance(i_begin, i_end); + ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error)); + d_size_type d_size = etl::distance(o_begin, o_end); + ETL_ASSERT(d_size >= 0, ETL_ERROR(algorithm_error)); + min_size_type size = etl::min(s_size, d_size); return etl::move(i_begin, i_begin + size, o_begin); } diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 2369f68cf..5404828af 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -106,5 +106,5 @@ SOFTWARE. #define ETL_SINGLETON_BASE_FILE_ID "73" #define ETL_UNALIGNED_TYPE_FILE_ID "74" #define ETL_SPAN_FILE_ID "75" - +#define ETL_ALGORITHM_FILE_ID "76" #endif diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index 7e6d4dba2..d68dd6ad9 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -1032,29 +1032,6 @@ namespace etl } } - //************************************************************************* - // Removes the element specified by pointer. - //************************************************************************* - void remove(const_pointer element) - { - iterator i_item = begin(); - iterator i_last_item = before_begin(); - - while (i_item != end()) - { - if (&i_item == element) - { - i_item = erase_after(i_last_item); - return; - } - else - { - ++i_item; - ++i_last_item; - } - } - } - //************************************************************************* /// Removes according to a predicate. //************************************************************************* diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index 563fadfa8..970d0589f 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -113,7 +113,7 @@ namespace etl public: intrusive_list_value_is_already_linked(string_type file_name_, numeric_type line_number_) - : intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"E"), file_name_, line_number_) + : intrusive_list_exception(ETL_ERROR_TEXT("intrusive_list:value is already linked", ETL_INTRUSIVE_LIST_FILE_ID"D"), file_name_, line_number_) { } }; diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index 2fcbc990e..e7673f4bb 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -141,7 +141,7 @@ namespace etl public: bitset_overflow(string_type file_name_, numeric_type line_number_) - : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"C"), file_name_, line_number_) + : bitset_exception(ETL_ERROR_TEXT("bitset:overflow", ETL_BITSET_FILE_ID"B"), file_name_, line_number_) { } }; @@ -155,7 +155,7 @@ namespace etl public: bitset_invalid_buffer(string_type file_name_, numeric_type line_number_) - : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"D"), file_name_, line_number_) + : bitset_exception(ETL_ERROR_TEXT("bitset:invalid buffer", ETL_BITSET_FILE_ID"C"), file_name_, line_number_) { } }; diff --git a/include/etl/queue.h b/include/etl/queue.h index 99e4d50eb..47e9d4703 100644 --- a/include/etl/queue.h +++ b/include/etl/queue.h @@ -32,9 +32,7 @@ SOFTWARE. #define ETL_QUEUE_INCLUDED #include "platform.h" -#include "iterator.h" #include "alignment.h" -#include "array.h" #include "exception.h" #include "error_handler.h" #include "debug_count.h" diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 9d43848df..78abcce94 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -86,7 +86,7 @@ namespace etl public: flat_multiset_iterator(string_type file_name_, numeric_type line_number_) - : flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"C"), file_name_, line_number_) + : flat_multiset_exception(ETL_ERROR_TEXT("flat_multiset:iterator", ETL_REFERENCE_FLAT_MULTISET_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index dfb654247..44bbea965 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -87,7 +87,7 @@ namespace etl public: flat_set_iterator(string_type file_name_, numeric_type line_number_) - : flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"C"), file_name_, line_number_) + : flat_set_exception(ETL_ERROR_TEXT("flat_set:iterator", ETL_REFERENCE_FLAT_SET_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/include/etl/singleton_base.h b/include/etl/singleton_base.h index eb9653b4b..72f0744aa 100644 --- a/include/etl/singleton_base.h +++ b/include/etl/singleton_base.h @@ -78,7 +78,7 @@ namespace etl public: singleton_base_already_created(string_type file_name_, numeric_type line_number_) - : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"A"), file_name_, line_number_) + : singleton_base_exception(ETL_ERROR_TEXT("singleton_base:already created", ETL_SINGLETON_BASE_FILE_ID"B"), file_name_, line_number_) { } }; diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index f12427189..2d362dd94 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -1364,6 +1364,17 @@ namespace CHECK(is_same); } + //************************************************************************* + TEST(copy_s_random_iterator) + { + int data1[] = { 1, 2, 3, 4, 5 }; + int out1[10]; + CHECK_THROW(etl::copy_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error); + CHECK_THROW(etl::copy_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error); + CHECK_THROW(etl::move_s(std::end(data1), std::begin(data1), std::begin(out1), std::end(out1)), etl::algorithm_error); + CHECK_THROW(etl::move_s(std::begin(data1), std::end(data1), std::end(out1), std::begin(out1)), etl::algorithm_error); + } + //************************************************************************* TEST(copy_4_parameter_non_random_iterator) { diff --git a/test/test_intrusive_forward_list.cpp b/test/test_intrusive_forward_list.cpp index 9e8544861..da4d185ca 100644 --- a/test/test_intrusive_forward_list.cpp +++ b/test/test_intrusive_forward_list.cpp @@ -979,35 +979,6 @@ namespace CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_remove_by_pointer) - { - std::forward_list compare_data(sorted_data.begin(), sorted_data.end()); - DataNDC0 data0(sorted_data.begin(), sorted_data.end()); - DataNDC1 data1(sorted_data.begin(), sorted_data.end()); - - auto it = data0.begin(); - for (int i = 0; i < 7; ++i) - { - it++; - } - ItemNDCNode* element = ⁢ - - compare_data.remove(ItemNDCNode("7")); - data0.remove(*element); - - bool are_equal = std::equal(data0.begin(), data0.end(), compare_data.begin()); - - CHECK(are_equal); - CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data0.size()); - CHECK_EQUAL(std::distance(compare_data.begin(), compare_data.end()), std::distance(data0.begin(), data0.end())); - - are_equal = std::equal(data1.begin(), data1.end(), sorted_data.begin()); - CHECK(are_equal); - CHECK_EQUAL(sorted_data.size(), data1.size()); - CHECK_EQUAL(sorted_data.size(), size_t(std::distance(data1.begin(), data1.end()))); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_remove_if) { From a24977a3dbbb96bcf18d6b64d3cdd6eaee09b733 Mon Sep 17 00:00:00 2001 From: BartolomeyKant Date: Wed, 30 Apr 2025 20:55:57 +0500 Subject: [PATCH 151/216] Fix cmake helper functions collision (#1065) * add etl prefix name for cmake helper functions * remove unused functions from GetGitRevistionDescription --- CMakeLists.txt | 4 +- cmake/GetGitRevisionDescription.cmake | 101 ++------------------------ cmake/helpers.cmake | 6 +- 3 files changed, 13 insertions(+), 98 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1be0f648d..8dd4b5049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,9 @@ cmake_minimum_required(VERSION 3.10) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake) set(MSG_PREFIX "etl |") -determine_version_with_git(${GIT_DIR_LOOKUP_POLICY}) +etl_determine_version_with_git(${GIT_DIR_LOOKUP_POLICY}) if(NOT ETL_VERSION) - determine_version_with_file("version.txt") + etl_determine_version_with_file("version.txt") endif() project(etl VERSION ${ETL_VERSION} LANGUAGES CXX) diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index 07ec5fafb..d0966da11 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -12,23 +12,6 @@ # Returns the results of git describe on the source tree, and adjusting # the output so that it tests false if an error occurs. # -# git_describe_working_tree( [ ...]) -# -# Returns the results of git describe on the working tree (--dirty option), -# and adjusting the output so that it tests false if an error occurs. -# -# git_get_exact_tag( [ ...]) -# -# Returns the results of git describe --exact-match on the source tree, -# and adjusting the output so that it tests false if there was no exact -# matching tag. -# -# git_local_changes() -# -# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes. -# Uses the return code of "git diff-index --quiet HEAD --". -# Does not regard untracked files. -# # Requires CMake 2.6 or newer (uses the 'function' command) # # Original Author: @@ -43,10 +26,10 @@ # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) -if(__get_git_revision_description) +if(__etl_get_git_revision_description) return() endif() -set(__get_git_revision_description YES) +set(__etl_get_git_revision_description YES) # We must run the following at "include" time, not at function call time, # to find the path to this module rather than the path to a calling list file @@ -62,7 +45,7 @@ get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) # neither foo nor bar contain a file/directory .git. This will return # C:/bla/.git # -function(_git_find_closest_git_dir _start_dir _git_dir_var) +function(_etl_git_find_closest_git_dir _start_dir _git_dir_var) set(cur_dir "${_start_dir}") set(git_dir "${_start_dir}/.git") while(NOT EXISTS "${git_dir}") @@ -83,8 +66,8 @@ function(_git_find_closest_git_dir _start_dir _git_dir_var) PARENT_SCOPE) endfunction() -function(get_git_head_revision _refspecvar _hashvar) - _git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR) +function(etl_get_git_head_revision _refspecvar _hashvar) + _etl_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR) if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR") set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE) @@ -143,7 +126,7 @@ function(get_git_head_revision _refspecvar _hashvar) string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir ${worktree_ref}) string(STRIP ${git_worktree_dir} git_worktree_dir) - _git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR) + _etl_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR) set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD") endif() else() @@ -172,11 +155,11 @@ function(get_git_head_revision _refspecvar _hashvar) PARENT_SCOPE) endfunction() -function(git_describe _var) +function(etl_git_describe _var) if(NOT GIT_FOUND) find_package(Git QUIET) endif() - get_git_head_revision(refspec hash ${ARGN}) + etl_get_git_head_revision(refspec hash ${ARGN}) if(NOT GIT_FOUND) set(${_var} "GIT-NOTFOUND" @@ -214,71 +197,3 @@ function(git_describe _var) "${out}" PARENT_SCOPE) endfunction() - -function(git_describe_working_tree _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - if(NOT GIT_FOUND) - set(${_var} - "GIT-NOTFOUND" - PARENT_SCOPE) - return() - endif() - - execute_process( - COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN} - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - RESULT_VARIABLE res - OUTPUT_VARIABLE out - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if(NOT res EQUAL 0) - set(out "${out}-${res}-NOTFOUND") - endif() - - set(${_var} - "${out}" - PARENT_SCOPE) -endfunction() - -function(git_get_exact_tag _var) - git_describe(out --exact-match ${ARGN}) - set(${_var} - "${out}" - PARENT_SCOPE) -endfunction() - -function(git_local_changes _var) - if(NOT GIT_FOUND) - find_package(Git QUIET) - endif() - get_git_head_revision(refspec hash) - if(NOT GIT_FOUND) - set(${_var} - "GIT-NOTFOUND" - PARENT_SCOPE) - return() - endif() - if(NOT hash) - set(${_var} - "HEAD-HASH-NOTFOUND" - PARENT_SCOPE) - return() - endif() - - execute_process( - COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD -- - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" - RESULT_VARIABLE res - OUTPUT_VARIABLE out - ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) - if(res EQUAL 0) - set(${_var} - "CLEAN" - PARENT_SCOPE) - else() - set(${_var} - "DIRTY" - PARENT_SCOPE) - endif() -endfunction() diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index 4624f3c2e..00172c880 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -1,4 +1,4 @@ -function(determine_version_with_file VER_FILE_NAME) +function(etl_determine_version_with_file VER_FILE_NAME) file(READ ${VER_FILE_NAME} ETL_VERSION_RAW) # Remove trailing whitespaces and/or newline string(STRIP ${ETL_VERSION_RAW} ETL_VERSION) @@ -8,9 +8,9 @@ function(determine_version_with_file VER_FILE_NAME) message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from version.txt file") endfunction() -function(determine_version_with_git) +function(etl_determine_version_with_git) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake) - git_describe(VERSION ${ARGN}) + etl_git_describe(VERSION ${ARGN}) string(FIND ${VERSION} "." VALID_VERSION) if(VALID_VERSION EQUAL -1) if(CMAKE_CURRENT_LIST_DIR STREQUAL PROJECT_SOURCE_DIR) From f69da8577ed8bcf2fcbed763a8d8328026211045 Mon Sep 17 00:00:00 2001 From: Jiang Yi Date: Wed, 30 Apr 2025 18:01:44 +0200 Subject: [PATCH 152/216] Support etl::underlying_type with compiler builtin (#1045) msvc is unsupported currently Co-authored-by: John Wellbelove --- .../etl/generators/type_traits_generator.h | 29 +++++++++++++ .../etl/profiles/determine_builtin_support.h | 12 ++++++ include/etl/type_traits.h | 29 +++++++++++++ include/etl/utility.h | 8 ++++ test/test_type_traits.cpp | 40 +++++++++++++++++ test/test_utility.cpp | 43 +++++++++++++++++++ 6 files changed, 161 insertions(+) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index ac421eb95..1ebdf3df2 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2352,6 +2352,35 @@ typedef integral_constant true_type; using type_identity_t = typename type_identity::type; #endif +#if ETL_USING_BUILTIN_UNDERLYING_TYPE +namespace private_type_traits +{ + template ::value> + struct __underlying_type_impl; + + template + struct __underlying_type_impl + { + }; + + template + struct __underlying_type_impl + { + using type = __underlying_type(T); + }; +} + +template +struct underlying_type : private_type_traits::__underlying_type_impl::value> +{ +}; + +#if ETL_USING_CPP11 +template +using underlying_type_t = typename underlying_type::type; +#endif +#endif + #if ETL_USING_CPP11 //********************************************* // has_duplicates diff --git a/include/etl/profiles/determine_builtin_support.h b/include/etl/profiles/determine_builtin_support.h index 725927f32..313a18a20 100644 --- a/include/etl/profiles/determine_builtin_support.h +++ b/include/etl/profiles/determine_builtin_support.h @@ -51,6 +51,10 @@ SOFTWARE. #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 1 #endif + + #if !defined(ETL_USING_BUILTIN_UNDERLYING_TYPE) + #define ETL_USING_BUILTIN_UNDERLYING_TYPE 1 + #endif #endif #if defined(__has_builtin) // Use __has_builtin to check for existence of builtin functions? @@ -73,6 +77,10 @@ SOFTWARE. #if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE) #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE (__has_builtin(__has_trivial_copy) || __has_builtin(__is_trivially_copyable)) #endif + + #if !defined(ETL_USING_BUILTIN_UNDERLYING_TYPE) + #define ETL_USING_BUILTIN_UNDERLYING_TYPE __has_builtin(__underlying_type) + #endif #endif // The default. Set to 0, if not already set. @@ -96,6 +104,10 @@ SOFTWARE. #define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 0 #endif +#if !defined(ETL_USING_BUILTIN_UNDERLYING_TYPE) + #define ETL_USING_BUILTIN_UNDERLYING_TYPE 0 +#endif + namespace etl { namespace traits diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 44b7805f3..ad55f35f9 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -2345,6 +2345,35 @@ typedef integral_constant true_type; using type_identity_t = typename type_identity::type; #endif +#if ETL_USING_BUILTIN_UNDERLYING_TYPE +namespace private_type_traits +{ + template ::value> + struct __underlying_type_impl; + + template + struct __underlying_type_impl + { + }; + + template + struct __underlying_type_impl + { + using type = __underlying_type(T); + }; +} + +template +struct underlying_type : private_type_traits::__underlying_type_impl::value> +{ +}; + +#if ETL_USING_CPP11 +template +using underlying_type_t = typename underlying_type::type; +#endif +#endif + #if ETL_USING_CPP11 //********************************************* // has_duplicates diff --git a/include/etl/utility.h b/include/etl/utility.h index 15b450e8b..3c3e9988f 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -134,6 +134,14 @@ namespace etl using forward_like_t = decltype(etl::forward_like(etl::declval())); #endif +#if ETL_USING_BUILTIN_UNDERLYING_TYPE && ETL_USING_CPP11 +template +ETL_CONSTEXPR underlying_type_t to_underlying(T val) ETL_NOEXCEPT +{ + return static_cast>(val); +} +#endif + // We can't have std::swap and etl::swap templates coexisting in the unit tests // as the compiler will be unable to decide which one to use, due to ADL. #if ETL_NOT_USING_STL && !defined(ETL_IN_UNIT_TEST) diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index a01e1b0ae..cd919c120 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -1364,6 +1364,46 @@ namespace CHECK_CLOSE(type_identity_test_add(1.5f, 2), 3.5f, 0.01f); } + //************************************************************************* +#if ETL_USING_BUILTIN_UNDERLYING_TYPE + TEST(test_underlying_type) + { + enum enum0_t : char + { + }; + + enum enum1_t : uint32_t + { + }; + + enum class enum2_t : short + { + }; + + enum class enum3_t : size_t + { + }; + + using enum4_t = enum1_t; + using enum5_t = std::add_const::type; + + CHECK_TRUE((std::is_same::type, char>::value)); + CHECK_TRUE((std::is_same::type, uint32_t>::value)); + CHECK_TRUE((std::is_same::type, short>::value)); + CHECK_TRUE((std::is_same::type, size_t>::value)); + CHECK_TRUE((std::is_same::type, uint32_t>::value)); + CHECK_TRUE((std::is_same::type, short>::value)); +#if ETL_USING_CPP11 + CHECK_TRUE((std::is_same, char>::value)); + CHECK_TRUE((std::is_same, uint32_t>::value)); + CHECK_TRUE((std::is_same, short>::value)); + CHECK_TRUE((std::is_same, size_t>::value)); + CHECK_TRUE((std::is_same, uint32_t>::value)); + CHECK_TRUE((std::is_same, short>::value)); +#endif + } +#endif + //************************************************************************* TEST(test_has_duplicates) { diff --git a/test/test_utility.cpp b/test/test_utility.cpp index e049198da..70b525ec9 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -719,6 +719,49 @@ namespace CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); } +#if ETL_USING_BUILTIN_UNDERLYING_TYPE && ETL_USING_CPP11 + TEST(test_to_underlying) + { + enum enum0_t : char + { + a0 = 'e', + a1 = 't', + a2 = 'l', + a3 = '3' + }; + + enum enum1_t : uint32_t + { + b0 = 2, + b1 = 3, + b2 = 5, + }; + + enum enum2_t : signed + { + c0 = -2, + c1 = 100, + }; + + using enum3_t = enum1_t; + + enum0_t e0 = enum0_t::a1; + enum1_t e1 = enum1_t::b2; + enum2_t e2 = enum2_t::c0; + enum3_t e3 = enum3_t::b0; + + CHECK_EQUAL(etl::to_underlying(e0), 't'); + CHECK_EQUAL(etl::to_underlying(e1), 5); + CHECK_EQUAL(etl::to_underlying(e2), -2); + CHECK_EQUAL(etl::to_underlying(e3), 2); + CHECK_EQUAL(etl::to_underlying(enum0_t::a0), 'e'); + CHECK_EQUAL(etl::to_underlying(enum0_t::a2), 'l'); + CHECK_EQUAL(etl::to_underlying(enum0_t::a3), '3'); + CHECK_EQUAL(etl::to_underlying(enum3_t::b1), 3); + CHECK_EQUAL(etl::to_underlying(enum2_t::c1), 100); + } +#endif + #if ETL_HAS_PACKED //********************************* TEST(test_packed) From 22391aa7506f16d586990269e0aad70c676312b9 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 1 May 2025 08:57:33 +0100 Subject: [PATCH 153/216] Imported and updated etl::underlying_type --- .../etl/generators/type_traits_generator.h | 57 +++++++++++++------ .../etl/profiles/determine_builtin_support.h | 3 +- include/etl/type_traits.h | 40 +++++++------ include/etl/utility.h | 15 ++--- test/test_utility.cpp | 16 +++--- 5 files changed, 84 insertions(+), 47 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 1ebdf3df2..021d58a09 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2352,33 +2352,58 @@ typedef integral_constant true_type; using type_identity_t = typename type_identity::type; #endif -#if ETL_USING_BUILTIN_UNDERLYING_TYPE -namespace private_type_traits -{ - template ::value> - struct __underlying_type_impl; + //********************************************* + // underlying_type + // Primary template for etl::underlying_type + template ::value> + struct underlying_type; + + // Specialization for non-enum types (invalid case) template - struct __underlying_type_impl + struct underlying_type { + // Static assertion to ensure this is only used with enums + static_assert(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); }; +#if ETL_USING_BUILTIN_UNDERLYING_TYPE template - struct __underlying_type_impl + struct underlying_type { - using type = __underlying_type(T); + typedef __underlying_type(T) type; }; -} +#else + template + struct underlying_type + { + private: -template -struct underlying_type : private_type_traits::__underlying_type_impl::value> -{ -}; + // Helper union to deduce the underlying type + union Helper + { + T enum_value; + unsigned char raw[sizeof(T)]; + }; -#if ETL_USING_CPP11 -template -using underlying_type_t = typename underlying_type::type; + public: + + // The deduced underlying type + typedef typename etl::conditional::type>::type>::type>::type type; + }; #endif + +#if ETL_USING_CPP11 + template + using underlying_type_t = typename underlying_type::type; #endif #if ETL_USING_CPP11 diff --git a/include/etl/profiles/determine_builtin_support.h b/include/etl/profiles/determine_builtin_support.h index 313a18a20..0d18c3152 100644 --- a/include/etl/profiles/determine_builtin_support.h +++ b/include/etl/profiles/determine_builtin_support.h @@ -57,7 +57,7 @@ SOFTWARE. #endif #endif -#if defined(__has_builtin) // Use __has_builtin to check for existence of builtin functions? +#if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT) // Use __has_builtin to check for existence of builtin functions? Fix VS2022 intellisense issue. #if !defined(ETL_USING_BUILTIN_IS_ASSIGNABLE) #define ETL_USING_BUILTIN_IS_ASSIGNABLE __has_builtin(__is_assignable) #endif @@ -119,6 +119,7 @@ namespace etl static ETL_CONSTANT bool using_builtin_is_trivially_constructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE == 1); static ETL_CONSTANT bool using_builtin_is_trivially_destructible = (ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE == 1); static ETL_CONSTANT bool using_builtin_is_trivially_copyable = (ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE == 1); + static ETL_CONSTANT bool using_builtin_underlying_type = (ETL_USING_BUILTIN_UNDERLYING_TYPE == 1); } } diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index ad55f35f9..8ef010f0d 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -2345,33 +2345,41 @@ typedef integral_constant true_type; using type_identity_t = typename type_identity::type; #endif + //********************************************* + // underlying_type + #if ETL_USING_BUILTIN_UNDERLYING_TYPE -namespace private_type_traits -{ - template ::value> - struct __underlying_type_impl; + // Primary template for etl::underlying_type + template ::value> + struct underlying_type; + // Specialization for non-enum types (invalid case) template - struct __underlying_type_impl + struct underlying_type { + // Static assertion to ensure this is only used with enums + static_assert(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); }; template - struct __underlying_type_impl + struct underlying_type { - using type = __underlying_type(T); + typedef __underlying_type(T) type; }; -} - -template -struct underlying_type : private_type_traits::__underlying_type_impl::value> -{ -}; +#else + template + struct underlying_type + { + ETL_STATIC_ASSERT(false, "No user defined specialisation of etl::underlying_type for this type"); + typedef char type; + }; +#endif #if ETL_USING_CPP11 -template -using underlying_type_t = typename underlying_type::type; -#endif + /// Primary template for etl::underlying_type + /// Users must spelialise this template for their enumerations. + template + using underlying_type_t = typename underlying_type::type; #endif #if ETL_USING_CPP11 diff --git a/include/etl/utility.h b/include/etl/utility.h index 3c3e9988f..00ba8ca8b 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -134,13 +134,14 @@ namespace etl using forward_like_t = decltype(etl::forward_like(etl::declval())); #endif -#if ETL_USING_BUILTIN_UNDERLYING_TYPE && ETL_USING_CPP11 -template -ETL_CONSTEXPR underlying_type_t to_underlying(T val) ETL_NOEXCEPT -{ - return static_cast>(val); -} -#endif + //*********************************** + // Gets the underlying type of an enum. + //*********************************** + template + ETL_CONSTEXPR underlying_type_t to_underlying(T value) ETL_NOEXCEPT + { + return static_cast>(value); + } // We can't have std::swap and etl::swap templates coexisting in the unit tests // as the compiler will be unable to decide which one to use, due to ADL. diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 70b525ec9..433d5c9c9 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -719,10 +719,11 @@ namespace CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); } -#if ETL_USING_BUILTIN_UNDERLYING_TYPE && ETL_USING_CPP11 +#if ETL_USING_BUILTIN_UNDERLYING_TYPE + //********************************* TEST(test_to_underlying) { - enum enum0_t : char + enum enum0_t : int8_t { a0 = 'e', a1 = 't', @@ -730,25 +731,26 @@ namespace a3 = '3' }; - enum enum1_t : uint32_t + enum class enum1_t : unsigned char { b0 = 2, b1 = 3, b2 = 5, }; - enum enum2_t : signed + enum enum2_t : int32_t { c0 = -2, c1 = 100, }; - using enum3_t = enum1_t; - enum0_t e0 = enum0_t::a1; enum1_t e1 = enum1_t::b2; enum2_t e2 = enum2_t::c0; - enum3_t e3 = enum3_t::b0; + + CHECK_TRUE(etl::is_same>::value); + CHECK_TRUE(etl::is_same>::value); + CHECK_TRUE(etl::is_same>::value); CHECK_EQUAL(etl::to_underlying(e0), 't'); CHECK_EQUAL(etl::to_underlying(e1), 5); From 394b1110fb7b8dc65bf7add9886af436a7129f3c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 5 May 2025 18:01:29 +0100 Subject: [PATCH 154/216] Added all arithmetic operators to type_def --- include/etl/type_def.h | 425 ++++++++++++++++++++++++++++++++++++++--- test/test_type_def.cpp | 115 ++++++++--- test/test_utility.cpp | 9 +- 3 files changed, 495 insertions(+), 54 deletions(-) diff --git a/include/etl/type_def.h b/include/etl/type_def.h index cdd916e7f..2671e4825 100644 --- a/include/etl/type_def.h +++ b/include/etl/type_def.h @@ -32,10 +32,12 @@ SOFTWARE. #define ETL_TYPE_DEF_INCLUDED #include "platform.h" +#include "type_traits.h" namespace etl { #define ETL_TYPEDEF(T, name) class name##_tag; typedef etl::type_def name + #define ETL_USING(name, T) class name##_tag; typedef etl::type_def name //************************************************************************* /// A template type to define strong typedefs. @@ -43,10 +45,12 @@ namespace etl ///\code /// // Short form. /// ETL_TYPEDEF(int, mytype); + /// or + /// ETL_USING(mytype, int); /// /// // Long form. /// class mytype_t_tag; - /// typedef etl::type_def mytype_t_tag; + /// typedef etl::type_def mytype; ///\endcode //************************************************************************* template @@ -54,16 +58,19 @@ namespace etl { public: + typedef TValue type; typedef TValue value_type; typedef TIdType id_type; //********************************************************************* -#if ETL_USING_CPP11 - ETL_CONSTEXPR type_def() = default; -#endif + ETL_CONSTEXPR type_def() + : value(TValue()) + { + } //********************************************************************* - ETL_CONSTEXPR type_def(TValue value_) + template ::value, void>::type> + ETL_CONSTEXPR type_def(T value_) : value(value_) { } @@ -110,21 +117,28 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator +=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator +=(T rhs) { value += rhs; return *this; } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator +=(const type_def& rhs) + ETL_CONSTEXPR14 + type_def& operator +=(const type_def& rhs) { value += rhs.value; return *this; } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator -=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator -=(T rhs) { value -= rhs; return *this; @@ -138,7 +152,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator *=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator *=(T rhs) { value *= rhs; return *this; @@ -152,7 +169,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator /=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator /=(T rhs) { value /= rhs; return *this; @@ -166,7 +186,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator %=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator %=(T rhs) { value %= rhs; return *this; @@ -180,7 +203,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator &=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator &=(T rhs) { value &= rhs; return *this; @@ -194,7 +220,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator |=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator |=(T rhs) { value |= rhs; return *this; @@ -208,7 +237,10 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator ^=(TValue rhs) + template + ETL_CONSTEXPR14 + typename etl::enable_if::value, type_def&>::type + operator ^=(T rhs) { value ^= rhs; return *this; @@ -222,26 +254,19 @@ namespace etl } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator <<=(TValue rhs) + ETL_CONSTEXPR14 type_def& operator <<=(int rhs) { value <<= rhs; return *this; } //********************************************************************* - ETL_CONSTEXPR14 type_def& operator >>=(TValue rhs) + ETL_CONSTEXPR14 type_def& operator >>=(int rhs) { value >>= rhs; return *this; } - //********************************************************************* - ETL_CONSTEXPR14 type_def& operator =(TValue rhs) - { - value = rhs; - return *this; - } - //********************************************************************* #if ETL_USING_CPP11 ETL_CONSTEXPR14 type_def& operator =(const type_def& rhs) = default; @@ -259,24 +284,378 @@ namespace etl return value; } + //********************************************************************* + // + operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator +(const type_def& lhs, T rhs) + { + return type_def(lhs.value + rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR type_def operator +(T lhs, const type_def& rhs) + { + return type_def(lhs + rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator +(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value + rhs.value); + } + + //********************************************************************* + // - operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator -(const type_def& lhs, T rhs) + { + return type_def(lhs.value - rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator -(T lhs, const type_def& rhs) + { + return type_def(lhs - rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator -(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value - rhs.value); + } + + //********************************************************************* + // * operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator *(const type_def& lhs, T rhs) + { + return type_def(lhs.value * rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator *(T lhs, const type_def& rhs) + { + return type_def(lhs * rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator *(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value * rhs.value); + } + + //********************************************************************* + // / operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator /(const type_def& lhs, T rhs) + { + return type_def(lhs.value / rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator /(T lhs, const type_def& rhs) + { + return type_def(lhs / rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator /(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value / rhs.value); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator %(const type_def& lhs, T rhs) + { + return type_def(lhs.value % rhs); + } + + //********************************************************************* + // % operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator %(T lhs, const type_def& rhs) + { + return type_def(lhs % rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator %(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value % rhs.value); + } + + //********************************************************************* + // & operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator &(const type_def& lhs, T rhs) + { + return type_def(lhs.value & rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator &(T lhs, const type_def& rhs) + { + return type_def(lhs & rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator &(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value & rhs.value); + } + + //********************************************************************* + // | operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator |(const type_def& lhs, T rhs) + { + return type_def(lhs.value | rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator |(T lhs, const type_def& rhs) + { + return type_def(lhs | rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator |(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value | rhs.value); + } + + //********************************************************************* + // ^ operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator ^(const type_def& lhs, T rhs) + { + return type_def(lhs.value ^ rhs); + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, type_def>::type + operator ^(T lhs, const type_def& rhs) + { + return type_def(lhs ^ rhs.value); + } + + //********************************************************************* + friend ETL_CONSTEXPR type_def operator ^(const type_def& lhs, const type_def& rhs) + { + return type_def(lhs.value ^ rhs.value); + } + + //********************************************************************* + // << operator + //********************************************************************* + friend ETL_CONSTEXPR type_def operator <<(const type_def& lhs, int rhs) + { + return type_def(lhs.value << rhs); + } + + //********************************************************************* + // >> operator + //********************************************************************* + friend ETL_CONSTEXPR type_def operator >>(const type_def& lhs, int rhs) + { + return type_def(lhs.value >> rhs); + } + + //********************************************************************* + // < operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator <(const type_def& lhs, T rhs) + { + return lhs.value < rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator <(T lhs, const type_def& rhs) + { + return lhs < rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator <(const type_def& lhs, const type_def& rhs) + { + return lhs.value < rhs.value; + } + + //********************************************************************* + // <= operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator <=(const type_def& lhs, T rhs) + { + return lhs.value <= rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator <=(T lhs, const type_def& rhs) + { + return lhs <= rhs.value; + } + + //********************************************************************* + friend ETL_CONSTEXPR bool operator <=(const type_def& lhs, const type_def& rhs) + { + return lhs.value <= rhs.value; + } + + //********************************************************************* + // > operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator >(const type_def& lhs, T rhs) + { + return lhs.value > rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator >(T lhs, const type_def& rhs) + { + return lhs > rhs.value; + } + //********************************************************************* friend ETL_CONSTEXPR bool operator >(const type_def& lhs, const type_def& rhs) { return lhs.value > rhs.value; } + //********************************************************************* + // >= operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator >=(const type_def& lhs, T rhs) + { + return lhs.value >= rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator >=(T lhs, const type_def& rhs) + { + return lhs >= rhs.value; + } + //********************************************************************* friend ETL_CONSTEXPR bool operator >=(const type_def& lhs, const type_def& rhs) { return lhs.value >= rhs.value; } + //********************************************************************* + // == operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator ==(const type_def& lhs, T rhs) + { + return lhs.value == rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator ==(T lhs, const type_def& rhs) + { + return lhs == rhs.value; + } + //********************************************************************* friend ETL_CONSTEXPR bool operator ==(const type_def& lhs, const type_def& rhs) { return lhs.value == rhs.value; } + //********************************************************************* + // != operator + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator !=(const type_def& lhs, T rhs) + { + return lhs.value != rhs; + } + + //********************************************************************* + template + friend ETL_CONSTEXPR + typename etl::enable_if::value, bool>::type + operator !=(T lhs, const type_def& rhs) + { + return lhs != rhs.value; + } + //********************************************************************* friend ETL_CONSTEXPR bool operator !=(const type_def& lhs, const type_def& rhs) { diff --git a/test/test_type_def.cpp b/test/test_type_def.cpp index f42b593be..30d277728 100644 --- a/test/test_type_def.cpp +++ b/test/test_type_def.cpp @@ -32,20 +32,37 @@ SOFTWARE. #include "etl/type_def.h" -#include "etl/type_traits.h" - namespace { + const char One = 1; + const char Two = 2; + SUITE(test_type_def) { //************************************************************************* - TEST(test_macro) + TEST(test_macro_ETL_TYPEDEF) { ETL_TYPEDEF(uint32_t, type1_t); ETL_TYPEDEF(uint32_t, type2_t); - type1_t t1 = type1_t(1); - type2_t t2 = type2_t(1); + type1_t t1 = type1_t(One); + type2_t t2 = type2_t(One); + + uint32_t i1 = t1.get(); + uint32_t i2 = t2.get(); + + CHECK_EQUAL(i1, i2); + CHECK_TRUE(std::is_trivially_copyable::value); + } + + //************************************************************************* + TEST(test_macro_ETL_USING) + { + ETL_USING(type1_t, uint32_t); + ETL_USING(type2_t, uint32_t); + + type1_t t1 = type1_t(One); + type2_t t2 = type2_t(One); uint32_t i1 = t1.get(); uint32_t i2 = t2.get(); @@ -60,8 +77,8 @@ namespace ETL_TYPEDEF(uint32_t, type1_t); ETL_TYPEDEF(uint32_t, type2_t); - constexpr type1_t t1 = type1_t(1); - constexpr type2_t t2 = type2_t(1); + constexpr type1_t t1 = type1_t(One); + constexpr type2_t t2 = type2_t(One); uint32_t i1 = t1.get(); uint32_t i2 = t2.get(); @@ -78,8 +95,8 @@ namespace class type2_t_tag; typedef etl::type_def type2_t; - type1_t t1 = type1_t(1); - type2_t t2 = type2_t(1); + type1_t t1 = type1_t(One); + type2_t t2 = type2_t(One); uint32_t i1 = t1.get(); uint32_t i2 = t2.get(); @@ -96,8 +113,8 @@ namespace class type2_t_tag; typedef etl::type_def type2_t; - constexpr type1_t t1 = type1_t(1); - constexpr type2_t t2 = type2_t(1); + constexpr type1_t t1 = type1_t(One); + constexpr type2_t t2 = type2_t(One); uint32_t i1 = t1.get(); uint32_t i2 = t2.get(); @@ -114,8 +131,8 @@ namespace class type2_t_tag; typedef etl::type_def type2_t; - type1_t t1(1); - type2_t t2(1); + type1_t t1(One); + type2_t t2(One); CHECK_EQUAL(t1.get(), t2.get()); } @@ -129,14 +146,14 @@ namespace class type2_t_tag; typedef etl::type_def type2_t; - constexpr type1_t t1(1); - constexpr type2_t t2(1); + constexpr type1_t t1(One); + constexpr type2_t t2(One); CHECK_EQUAL(t1.get(), t2.get()); } //************************************************************************* - TEST(test_operators) + TEST(test_unary_operators) { class __type_t__; typedef etl::type_def<__type_t__, uint32_t> type_t; @@ -148,14 +165,14 @@ namespace CHECK_EQUAL(i++, uint32_t(t++)); CHECK_EQUAL(--i, uint32_t(--t)); CHECK_EQUAL(i--, uint32_t(t--)); - CHECK_EQUAL(i += 2, uint32_t(t += 2)); - CHECK_EQUAL(i += 2, uint32_t(t += type_t(2))); - CHECK_EQUAL(i -= 2, uint32_t(t -= 2)); - CHECK_EQUAL(i -= 2, uint32_t(t -= type_t(2))); - CHECK_EQUAL(i *= 2, uint32_t(t *= 2)); - CHECK_EQUAL(i *= 2, uint32_t(t *= type_t(2))); - CHECK_EQUAL(i /= 2, uint32_t(t /= 2)); - CHECK_EQUAL(i /= 2, uint32_t(t /= type_t(2))); + CHECK_EQUAL(i += Two, uint32_t(t += Two)); + CHECK_EQUAL(i += Two, uint32_t(t += type_t(Two))); + CHECK_EQUAL(i -= Two, uint32_t(t -= Two)); + CHECK_EQUAL(i -= Two, uint32_t(t -= type_t(Two))); + CHECK_EQUAL(i *= Two, uint32_t(t *= Two)); + CHECK_EQUAL(i *= Two, uint32_t(t *= type_t(Two))); + CHECK_EQUAL(i /= Two, uint32_t(t /= Two)); + CHECK_EQUAL(i /= Two, uint32_t(t /= type_t(Two))); CHECK_EQUAL(i &= 0xFF00U, uint32_t(t &= 0xFF00U)); CHECK_EQUAL(i &= 0xFF00U, uint32_t(t &= type_t(0xFF00U))); CHECK_EQUAL(i |= 0x003DU, uint32_t(t |= 0x003DU)); @@ -170,6 +187,52 @@ namespace CHECK_EQUAL(0x1234U, uint32_t(t)); } + //************************************************************************* + TEST(test_binary_operators) + { + class __type_t__; + using type_t = etl::type_def<__type_t__, uint32_t> ; + + uint32_t i1 = 0x5A3DUL; + uint32_t i2 = 0xB47AUL; + type_t t1(0x5A3DUL); + type_t t2(0xB47AUL); + + CHECK_EQUAL(i1 + Two, t1 + Two); + CHECK_EQUAL(Two + i1, Two + t1); + CHECK_EQUAL(i1 + i2, t1 + t2); + + CHECK_EQUAL(i1 - Two, t1 - Two); + CHECK_EQUAL(i2 - i1, i2 - t1); + CHECK_EQUAL(i2 - i1, t2 - t1); + + CHECK_EQUAL(i1 * Two, t1 * Two); + CHECK_EQUAL(Two * i1, Two * t1); + CHECK_EQUAL(i1 * i2, t1 * t2); + + CHECK_EQUAL(i1 / Two, t1 / Two); + CHECK_EQUAL(i2 / i1, i2 / t1); + CHECK_EQUAL(i2 / i1, t2 / t1); + + CHECK_EQUAL(uint32_t(0xFF00) & i1, uint32_t(0xFF00) & t1); + CHECK_EQUAL(i1 & uint32_t(0xFF00), t1 & uint32_t(0xFF00)); + CHECK_EQUAL(uint32_t(0xFF00) & i1, type_t(0xFF00UL) & t1); + + CHECK_EQUAL(uint32_t(0x003D) | i1, uint32_t(0x003D) | t1); + CHECK_EQUAL(i1 | uint32_t(0x003D), t1 | uint32_t(0x003D)); + CHECK_EQUAL(uint32_t(0x003D) | i1, type_t(0x003DUL) | t1); + + CHECK_EQUAL(uint32_t(0xAA55) ^ i1, uint32_t(0xAA55) ^ t1); + CHECK_EQUAL(i1 ^ uint32_t(0xAA55), t1 ^ uint32_t(0xAA55)); + CHECK_EQUAL(uint32_t(0xAA55) ^ i1, type_t(0xAA55UL) ^ t1); + + CHECK_EQUAL(i1 << 2, t1 << 2); + CHECK_EQUAL(i1 >> 2, t1 >> 2); + + CHECK_EQUAL(i1 % uint32_t(23), t1 % uint32_t(23)); + CHECK_EQUAL(uint32_t(23) % i1, uint32_t(23) % t1); + } + //************************************************************************* TEST(test_comparisons) { @@ -177,7 +240,7 @@ namespace typedef etl::type_def<__type_t__, uint32_t> type_t; type_t t1(1); - type_t t2(2); + type_t t2(Two); type_t t3(t1); type_t t4(t2); @@ -200,7 +263,7 @@ namespace typedef etl::type_def<__type_t__, uint32_t> type_t; constexpr type_t t1(1); - constexpr type_t t2(2); + constexpr type_t t2(Two); constexpr bool eq = t1 == t1; constexpr bool neq = t1 == t2; diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 433d5c9c9..4b378625f 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -748,18 +748,17 @@ namespace enum1_t e1 = enum1_t::b2; enum2_t e2 = enum2_t::c0; - CHECK_TRUE(etl::is_same>::value); - CHECK_TRUE(etl::is_same>::value); - CHECK_TRUE(etl::is_same>::value); + CHECK_TRUE((etl::is_same>::value)); + CHECK_TRUE((etl::is_same>::value)); + CHECK_TRUE((etl::is_same>::value)); CHECK_EQUAL(etl::to_underlying(e0), 't'); CHECK_EQUAL(etl::to_underlying(e1), 5); CHECK_EQUAL(etl::to_underlying(e2), -2); - CHECK_EQUAL(etl::to_underlying(e3), 2); CHECK_EQUAL(etl::to_underlying(enum0_t::a0), 'e'); CHECK_EQUAL(etl::to_underlying(enum0_t::a2), 'l'); CHECK_EQUAL(etl::to_underlying(enum0_t::a3), '3'); - CHECK_EQUAL(etl::to_underlying(enum3_t::b1), 3); + CHECK_EQUAL(etl::to_underlying(enum1_t::b1), 3); CHECK_EQUAL(etl::to_underlying(enum2_t::c1), 100); } #endif From 66af2a69c15de33b87920782537926b9b7842680 Mon Sep 17 00:00:00 2001 From: Helder Duarte Date: Mon, 5 May 2025 19:16:38 +0100 Subject: [PATCH 155/216] Add swap(circular_buffer_ext&&) (#1068) (#1072) --- include/etl/circular_buffer.h | 30 ++++++++++++++++ test/test_circular_buffer_external_buffer.cpp | 34 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/etl/circular_buffer.h b/include/etl/circular_buffer.h index a6967d82b..a644b0d28 100644 --- a/include/etl/circular_buffer.h +++ b/include/etl/circular_buffer.h @@ -1385,6 +1385,25 @@ namespace etl #endif } +#if ETL_USING_CPP11 + //************************************************************************* + /// Swap with another circular buffer + //************************************************************************* + void swap(circular_buffer_ext&& other) ETL_NOEXCEPT + { + using ETL_OR_STD::swap; // Allow ADL + + swap(this->in, other.in); + swap(this->out, other.out); + swap(this->pbuffer, other.pbuffer); + swap(this->buffer_size, other.buffer_size); + +#if defined(ETL_DEBUG_COUNT) + this->etl_debug_count.swap(other.etl_debug_count); +#endif + } +#endif + //************************************************************************* /// set_buffer //************************************************************************* @@ -1439,6 +1458,17 @@ namespace etl lhs.swap(rhs); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Overloaded swap for etl::circular_buffer_ext + //************************************************************************* + template + void swap(etl::circular_buffer_ext& lhs, etl::circular_buffer_ext&& rhs) + { + lhs.swap(rhs); + } +#endif + //************************************************************************* /// Equality operator //************************************************************************* diff --git a/test/test_circular_buffer_external_buffer.cpp b/test/test_circular_buffer_external_buffer.cpp index 271f88d34..40d1933ff 100644 --- a/test/test_circular_buffer_external_buffer.cpp +++ b/test/test_circular_buffer_external_buffer.cpp @@ -1033,6 +1033,40 @@ namespace CHECK(std::equal(input2.begin(), input2.end(), data1.begin())); } +#if ETL_USING_CPP11 + //************************************************************************* + TEST(test_swap_with_rvalue) + { + etl::uninitialized_buffer_of buffer1; + etl::uninitialized_buffer_of buffer2; + etl::uninitialized_buffer_of buffer3; + + Compare input1{ Ndc("0"), Ndc("1"), Ndc("2"), Ndc("3"), Ndc("4") }; + Compare input2{ Ndc("7"), Ndc("8"), Ndc("9"), Ndc("10"), Ndc("11"), Ndc("12") }; + Compare input3{ Ndc("13"), Ndc("14"), Ndc("15"), Ndc("16"), Ndc("17"), Ndc("18"), Ndc("19") }; + Data data1(buffer1.raw, 5U); + Data data2(buffer2.raw, 6U); + Data data3(buffer3.raw, 7U); + data1.push(input1.begin(), input1.end()); + data2.push(input2.begin(), input2.end()); + data3.push(input3.begin(), input3.end()); + + data1.swap(std::move(data2)); + + CHECK_EQUAL(input1.size(), data2.size()); + CHECK_EQUAL(input2.size(), data1.size()); + CHECK(std::equal(input1.begin(), input1.end(), data2.begin())); + CHECK(std::equal(input2.begin(), input2.end(), data1.begin())); + + swap(data1, std::move(data3)); + + CHECK_EQUAL(input2.size(), data3.size()); + CHECK_EQUAL(input3.size(), data1.size()); + CHECK(std::equal(input2.begin(), input2.end(), data3.begin())); + CHECK(std::equal(input3.begin(), input3.end(), data1.begin())); + } +#endif + //************************************************************************* TEST(test_equal) { From 0b280bf5f0028549d4952946aaa9013cd4553d93 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 5 May 2025 21:10:03 +0100 Subject: [PATCH 156/216] Fixed test syntax error --- test/test_utility.cpp | 9 ++++----- test/vs2022/etl.vcxproj.filters | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 433d5c9c9..4b378625f 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -748,18 +748,17 @@ namespace enum1_t e1 = enum1_t::b2; enum2_t e2 = enum2_t::c0; - CHECK_TRUE(etl::is_same>::value); - CHECK_TRUE(etl::is_same>::value); - CHECK_TRUE(etl::is_same>::value); + CHECK_TRUE((etl::is_same>::value)); + CHECK_TRUE((etl::is_same>::value)); + CHECK_TRUE((etl::is_same>::value)); CHECK_EQUAL(etl::to_underlying(e0), 't'); CHECK_EQUAL(etl::to_underlying(e1), 5); CHECK_EQUAL(etl::to_underlying(e2), -2); - CHECK_EQUAL(etl::to_underlying(e3), 2); CHECK_EQUAL(etl::to_underlying(enum0_t::a0), 'e'); CHECK_EQUAL(etl::to_underlying(enum0_t::a2), 'l'); CHECK_EQUAL(etl::to_underlying(enum0_t::a3), '3'); - CHECK_EQUAL(etl::to_underlying(enum3_t::b1), 3); + CHECK_EQUAL(etl::to_underlying(enum1_t::b1), 3); CHECK_EQUAL(etl::to_underlying(enum2_t::c1), 100); } #endif diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 8b0716093..340f6a2f8 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3462,7 +3462,7 @@ Tests\Containers - Tests + Tests\Syntax Checks\Source From ba487bcb0421ec27116a9f795e4db69192b82030 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 6 May 2025 09:52:51 +0200 Subject: [PATCH 157/216] Add take() to etl::span (#1083) --- include/etl/span.h | 37 +++++++++ test/test_span_dynamic_extent.cpp | 131 ++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) diff --git a/include/etl/span.h b/include/etl/span.h index 5e364b233..32bf118b6 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -932,6 +932,43 @@ namespace etl (pend - pbegin) * sizeof(element_type) / sizeof(TNew)); } + //************************************************************************* + /// Split off and return an initial span of specified type of this span. + /// The original span is advanced by the size of the returned span. + /// \tparam TRet Returned span type + /// \param n Number of elements in returned span + //************************************************************************* + template + ETL_NODISCARD etl::span take(size_t const n) + { + ETL_STATIC_ASSERT(sizeof(TRet) % sizeof(element_type) == 0, "sizeof(TRet) must be divisible by sizeof(T)"); + + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + ETL_ASSERT(sizeof(TRet) * n <= sizeof(element_type) * size(), ETL_ERROR(span_size_mismatch)); + + etl::span result = reinterpret_as().first(n); + advance(sizeof(TRet) / sizeof(element_type) * n); + return result; + } + + //************************************************************************* + /// Split off and return an initial value of specified type of this span. + /// The original span is advanced by the size of TRet + /// \tparam TRet Returned span type + //************************************************************************* + template + ETL_NODISCARD TRet& take() + { + ETL_STATIC_ASSERT(sizeof(TRet) % sizeof(element_type) == 0, "sizeof(TRet) must be divisible by sizeof(T)"); + + ETL_ASSERT(etl::is_aligned::value>(pbegin), ETL_ERROR(span_alignment_exception)); + ETL_ASSERT(sizeof(TRet) <= sizeof(element_type) * size(), ETL_ERROR(span_size_mismatch)); + + TRet& result = *reinterpret_cast(data()); + advance(sizeof(TRet) / sizeof(element_type)); + return result; + } + private: pointer pbegin; diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index ee85f843b..9707dd1d6 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -1370,6 +1370,137 @@ namespace CHECK_EQUAL(etl::copy(data0, data1), true); } + //************************************************************************* + TEST(test_take_span_size_error) + { + uint8_t src[] = { 0x01, 0x02, 0x03 }; + etl::span data0 = src; + + CHECK_THROW({etl::span data1 = data0.take(1); (void) data1;}, etl::span_size_mismatch); + } + + //************************************************************************* + TEST(test_take_span) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; + etl::span data0 = src; + + etl::span data1 = data0.take(1); + + CHECK_EQUAL(data0.size(), 4); + CHECK_EQUAL(data1.size(), 1); + CHECK_EQUAL(data1[0], 0x01); + + etl::span data2 = data0.take(1); + + CHECK_EQUAL(data0.size(), 0); + CHECK_EQUAL(data2.size(), 1); + CHECK_EQUAL(data2[0], 0x02030405); + + data1 = data0.take(0); + + CHECK_EQUAL(data0.size(), 0); + CHECK_EQUAL(data1.size(), 0); + + CHECK_THROW({etl::span data3 = data0.take(1); (void) data3;}, etl::span_size_mismatch); + } + + //************************************************************************* + TEST(test_take_span_2) + { + + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + etl::span data0 = src; + + etl::span data1 = data0.take(2); + + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data1.size(), 2); + CHECK_EQUAL(data1[0], 0x01020304); + CHECK_EQUAL(data1[1], 0x05060708); + + etl::span data2 = data0.take(1); + + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data2.size(), 1); + CHECK_EQUAL(data2[0], 0x09); + } + + //************************************************************************* + TEST(test_take_span_const) + { + const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + etl::span data0 = src; + + etl::span data1 = data0.take(2); + + CHECK_EQUAL(data0.size(), 2); + CHECK_EQUAL(data1.size(), 2); + CHECK_EQUAL(data1[0], 0x01020304); + CHECK_EQUAL(data1[1], 0x05060708); + + etl::span data2 = data0.take(1); + + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data2.size(), 1); + CHECK_EQUAL(data2[0], 0x09); + + data2 = data0.take(0); + + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data2.size(), 0); + } + + //************************************************************************* + TEST(test_take_value) + { + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + etl::span data0 = src; + + uint8_t& data1 = data0.take(); + CHECK_EQUAL(data0.size(), 9); + CHECK_EQUAL(data1, 0x01); + + etl::be_uint32_t& data2 = data0.take(); + CHECK_EQUAL(data0.size(), 5); + CHECK_EQUAL(data2, 0x02030405); + + etl::be_uint32_t& data3 = data0.take(); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data3, 0x06070809); + + uint8_t& data4 = data0.take(); + CHECK_EQUAL(data0.size(), 0); + CHECK_EQUAL(data4, 0x0a); + + CHECK_THROW({uint8_t& data5 = data0.take(); (void) data5;}, etl::span_size_mismatch); + } + + //************************************************************************* + TEST(test_take_value_const) + { + const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + etl::span data0 = src; + + const uint8_t& data1 = data0.take(); + CHECK_EQUAL(data0.size(), 9); + CHECK_EQUAL(data1, 0x01); + + const etl::be_uint32_t& data2 = data0.take(); + CHECK_EQUAL(data0.size(), 5); + CHECK_EQUAL(data2, 0x02030405); + + const etl::be_uint32_t& data3 = data0.take(); + CHECK_EQUAL(data0.size(), 1); + CHECK_EQUAL(data3, 0x06070809); + + const uint8_t& data4 = data0.take(); + CHECK_EQUAL(data0.size(), 0); + CHECK_EQUAL(data4, 0x0a); + + CHECK_THROW({const uint8_t& data5 = data0.take(); (void) data5;}, etl::span_size_mismatch); + } + #include "etl/private/diagnostic_pop.h" }; } From d1f118bb79a1b74e6795026f0604a4b0fd45a3a7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:20:08 +0100 Subject: [PATCH 158/216] Minor style changes --- include/etl/hash.h | 2 +- include/etl/largest.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/hash.h b/include/etl/hash.h index 8066a0123..211c73e82 100644 --- a/include/etl/hash.h +++ b/include/etl/hash.h @@ -93,7 +93,7 @@ namespace etl //************************************************************************* /// Primary definition of base hash class, by default is poisoned //************************************************************************* - template + template struct hash_base { private: diff --git a/include/etl/largest.h b/include/etl/largest.h index 0c52af2e1..7d5345d71 100644 --- a/include/etl/largest.h +++ b/include/etl/largest.h @@ -331,7 +331,7 @@ namespace etl ///\ingroup largest //*************************************************************************** template - struct largest + struct largest { using type = typename etl::largest_type::type; From 53b7acffe98a48933cd11cf4f1a1758f682ebb92 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:21:14 +0100 Subject: [PATCH 159/216] Added largest.h include to algorithm.h to allow C++03 compatibiity to four parameter copy. --- include/etl/algorithm.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index db5c3a2a5..80c4a2633 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -43,6 +43,7 @@ SOFTWARE. #include "iterator.h" #include "functional.h" #include "utility.h" +#include "largest.h" #include "gcd.h" #include "error_handler.h" #include "exception.h" @@ -2280,14 +2281,19 @@ namespace etl ETL_CONSTEXPR14 typename etl::enable_if::value && etl::is_random_iterator::value, TOutputIterator>::type - copy_s(TInputIterator i_begin, - TInputIterator i_end, - TOutputIterator o_begin, - TOutputIterator o_end) + copy_s(TInputIterator i_begin, + TInputIterator i_end, + TOutputIterator o_begin, + TOutputIterator o_end) { - using s_size_type = typename iterator_traits::difference_type; - using d_size_type = typename iterator_traits::difference_type; - using min_size_type = typename etl::common_type::type; + typedef typename iterator_traits::difference_type s_size_type; + typedef typename iterator_traits::difference_type d_size_type; + +#if ETL_USING_CPP11 + typedef typename etl::common_type::type min_size_type; +#else + typedef typename etl::largest_type::type min_size_type; +#endif s_size_type s_size = etl::distance(i_begin, i_end); ETL_ASSERT(s_size >= 0, ETL_ERROR(algorithm_error)); From 708c8c0d3a440e039c52932e50f40ae8b800d955 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:23:07 +0100 Subject: [PATCH 160/216] Added largest.h include to algorithm.h to allow C++03 compatibiity to four parameter copy. --- include/etl/generators/largest_generator.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/generators/largest_generator.h b/include/etl/generators/largest_generator.h index a8cb40837..20288b273 100644 --- a/include/etl/generators/largest_generator.h +++ b/include/etl/generators/largest_generator.h @@ -379,7 +379,7 @@ namespace etl ///\ingroup largest //*************************************************************************** template - struct largest + struct largest { using type = typename etl::largest_type::type; From 5094a0a9e180da97a6fc8777102a304b47248330 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:23:26 +0100 Subject: [PATCH 161/216] Added C++03 etl::is_enum --- .../etl/generators/type_traits_generator.h | 2 +- include/etl/type_traits.h | 28 ++++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 021d58a09..35e5c8eee 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2364,7 +2364,7 @@ typedef integral_constant true_type; struct underlying_type { // Static assertion to ensure this is only used with enums - static_assert(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); + ETL_STATIC_ASSERT(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); }; #if ETL_USING_BUILTIN_UNDERLYING_TYPE diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 8ef010f0d..5e1654393 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -739,7 +739,29 @@ namespace etl template inline constexpr bool is_enum_v = etl::is_enum::value; #endif +#else + namespace private_type_traits + { + // Helper to detect if a type is convertible to an integer + template + struct is_convertible_to_int + { + static char test(int); // Match if T is convertible to int + static double test(...); // Fallback for other types + + static const bool value = sizeof(test(static_cast(0))) == sizeof(char); + }; + } + // Implementation of is_enum + template + struct is_enum + { + static const bool value = private_type_traits::is_convertible_to_int::value && + !is_class::value && + !is_arithmetic::value && + !is_reference::value; + }; #endif //*************************************************************************** @@ -2267,8 +2289,7 @@ typedef integral_constant true_type; struct common_type : etl::conditional::type>::value&& etl::is_same::type>::value, private_common_type::common_type_2_impl, - common_type::type, - typename etl::decay::type>>::type + common_type::type, typename etl::decay::type>>::type { }; @@ -2347,7 +2368,6 @@ typedef integral_constant true_type; //********************************************* // underlying_type - #if ETL_USING_BUILTIN_UNDERLYING_TYPE // Primary template for etl::underlying_type template ::value> @@ -2358,7 +2378,7 @@ typedef integral_constant true_type; struct underlying_type { // Static assertion to ensure this is only used with enums - static_assert(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); + ETL_STATIC_ASSERT(etl::is_enum::value, "etl::underlying_type can only be used with enumeration types."); }; template From b6300d97ff6594cd69dc413eb87295a1be50bb98 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:24:39 +0100 Subject: [PATCH 162/216] C++03 compatibiity to to_underlying --- include/etl/utility.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/utility.h b/include/etl/utility.h index 00ba8ca8b..81c8c5620 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -138,9 +138,9 @@ namespace etl // Gets the underlying type of an enum. //*********************************** template - ETL_CONSTEXPR underlying_type_t to_underlying(T value) ETL_NOEXCEPT + ETL_CONSTEXPR typename underlying_type::type to_underlying(T value) ETL_NOEXCEPT { - return static_cast>(value); + return static_cast::type>(value); } // We can't have std::swap and etl::swap templates coexisting in the unit tests From 1d19ac22cd580fc43825aec3b7c52dc6cc5fc325 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:25:41 +0100 Subject: [PATCH 163/216] Added licence text to tuple header Removed redundant include --- include/etl/tuple.h | 57 +++++++++++++++++++++++++++++++++++++++------ test/test_tuple.cpp | 1 - 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/include/etl/tuple.h b/include/etl/tuple.h index 2b15e017e..6b4edbdb1 100644 --- a/include/etl/tuple.h +++ b/include/etl/tuple.h @@ -1,16 +1,57 @@ -#pragma once +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Documentation: https://www.etlcpp.com/algorithm.html + +Copyright(c) 2024 John Wellbelove + +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_TUPLE_INCLUDED +#define ETL_TUPLE_INCLUDED + +#include "platform.h" + +#if ETL_NOT_USING_CPP11 + #if !defined(ETL_IN_UNIT_TEST) + #error NOT SUPPORTED FOR C++03 OR BELOW + #endif +#else #if ETL_USING_STL #include #endif -#include "etl/nth_type.h" -#include "etl/type_traits.h" -#include "etl/utility.h" -#include "etl/functional.h" +#include "nth_type.h" +#include "type_traits.h" +#include "utility.h" +#include "functional.h" -#include "etl/private/tuple_element.h" -#include "etl/private/tuple_size.h" +#include "private/tuple_element.h" +#include "private/tuple_size.h" namespace etl { @@ -1257,3 +1298,5 @@ namespace std using type = typename etl::nth_type_t; }; } +#endif +#endif diff --git a/test/test_tuple.cpp b/test/test_tuple.cpp index f4af43f33..b79e25dc4 100644 --- a/test/test_tuple.cpp +++ b/test/test_tuple.cpp @@ -31,7 +31,6 @@ SOFTWARE. #include "data.h" #include "etl/tuple.h" -#include "etl/private/tuple_size.h" #include #include From 524ebf9b9f3eae1415ccd873639bd60b1c80388e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 7 May 2025 07:26:26 +0100 Subject: [PATCH 164/216] Small style changes to etl::span take() --- include/etl/span.h | 2 ++ test/test_span_dynamic_extent.cpp | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 32bf118b6..9d34c0e63 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -948,6 +948,7 @@ namespace etl etl::span result = reinterpret_as().first(n); advance(sizeof(TRet) / sizeof(element_type) * n); + return result; } @@ -966,6 +967,7 @@ namespace etl TRet& result = *reinterpret_cast(data()); advance(sizeof(TRet) / sizeof(element_type)); + return result; } diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 9707dd1d6..4b842c6df 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -1380,7 +1380,7 @@ namespace } //************************************************************************* - TEST(test_take_span) + TEST(test_take_span_take_uint8_tuint32_t_then_no_data_then_excess_data) { uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05 }; etl::span data0 = src; @@ -1406,10 +1406,10 @@ namespace } //************************************************************************* - TEST(test_take_span_2) + TEST(test_take_span_take_be_uint32_t_twice_then_uint8_t) { - uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }; etl::span data0 = src; etl::span data1 = data0.take(2); @@ -1424,12 +1424,13 @@ namespace CHECK_EQUAL(data0.size(), 1); CHECK_EQUAL(data2.size(), 1); CHECK_EQUAL(data2[0], 0x09); + CHECK_EQUAL(data0[0], 0x0A); } //************************************************************************* TEST(test_take_span_const) { - const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }; etl::span data0 = src; etl::span data1 = data0.take(2); @@ -1452,9 +1453,9 @@ namespace } //************************************************************************* - TEST(test_take_value) + TEST(test_take_single_value) { - uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }; etl::span data0 = src; uint8_t& data1 = data0.take(); @@ -1471,7 +1472,7 @@ namespace uint8_t& data4 = data0.take(); CHECK_EQUAL(data0.size(), 0); - CHECK_EQUAL(data4, 0x0a); + CHECK_EQUAL(data4, 0x0A); CHECK_THROW({uint8_t& data5 = data0.take(); (void) data5;}, etl::span_size_mismatch); } @@ -1479,7 +1480,7 @@ namespace //************************************************************************* TEST(test_take_value_const) { - const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a }; + const uint8_t src[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A }; etl::span data0 = src; const uint8_t& data1 = data0.take(); @@ -1496,7 +1497,7 @@ namespace const uint8_t& data4 = data0.take(); CHECK_EQUAL(data0.size(), 0); - CHECK_EQUAL(data4, 0x0a); + CHECK_EQUAL(data4, 0x0A); CHECK_THROW({const uint8_t& data5 = data0.take(); (void) data5;}, etl::span_size_mismatch); } From 12328670ddd851d6bc9c0b89492157971e9d2e20 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 11 May 2025 14:11:22 +0100 Subject: [PATCH 165/216] Work in progress --- include/etl/chrono.h | 9 +- .../etl/generators/type_traits_generator.h | 15 + include/etl/platform.h | 10 +- include/etl/private/chrono/clocks.h | 187 +++++++++ include/etl/private/chrono/day.h | 48 +-- include/etl/private/chrono/duration.h | 178 ++++++--- include/etl/private/chrono/hh_mm_ss.h | 50 ++- include/etl/private/chrono/last_spec.h | 6 +- include/etl/private/chrono/month.h | 56 +-- include/etl/private/chrono/month_day.h | 24 +- include/etl/private/chrono/month_weekday.h | 32 +- include/etl/private/chrono/system_clock.h | 51 --- include/etl/private/chrono/time_point.h | 103 +++-- include/etl/private/chrono/weekday.h | 76 ++-- include/etl/private/chrono/year.h | 50 +-- include/etl/private/chrono/year_month.h | 12 +- include/etl/private/chrono/year_month_day.h | 77 ++-- .../etl/private/chrono/year_month_weekday.h | 46 +-- include/etl/type_traits.h | 18 +- test/CMakeLists.txt | 31 +- test/etl_profile.h | 6 + test/test_chrono_clocks.cpp | 170 ++++++++ test/test_chrono_duration.cpp | 82 +++- test/test_chrono_time_point.cpp | 362 ++++++++++++++++++ test/test_chrono_year_month_day.cpp | 9 + test/test_ratio.cpp | 12 +- test/test_type_traits.cpp | 23 ++ test/vs2022/etl.vcxproj | 4 +- test/vs2022/etl.vcxproj.filters | 12 +- 29 files changed, 1351 insertions(+), 408 deletions(-) create mode 100644 include/etl/private/chrono/clocks.h delete mode 100644 include/etl/private/chrono/system_clock.h create mode 100644 test/test_chrono_clocks.cpp create mode 100644 test/test_chrono_time_point.cpp diff --git a/include/etl/chrono.h b/include/etl/chrono.h index fbc0b47d9..62bbac183 100644 --- a/include/etl/chrono.h +++ b/include/etl/chrono.h @@ -44,6 +44,7 @@ SOFTWARE. #include "hash.h" #include +#include namespace etl { @@ -59,12 +60,15 @@ namespace etl constexpr bool treat_as_floating_point_v = treat_as_floating_point::value; #endif } + + // Use the same type as defined in time.h. + using time_t = ::time_t; } -#include "private/chrono/time_point.h" #include "private/chrono/last_spec.h" #include "private/chrono/duration.h" -#include "private/chrono/system_clock.h" +#include "private/chrono/time_point.h" +#include "private/chrono/clocks.h" #include "private/chrono/day.h" #include "private/chrono/weekday.h" #include "private/chrono/month.h" @@ -77,6 +81,7 @@ namespace etl #include "private/chrono/hh_mm_ss.h" #include "private/chrono/operators.h" #include "private/chrono/time_zone.h" + #endif #undef ETL_IN_CHRONO_H diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index ac421eb95..fd1fb891f 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2394,6 +2394,21 @@ typedef integral_constant true_type; template inline constexpr size_t count_of_v = etl::count_of::value; #endif + +#if ETL_USING_CPP11 + //********************************************* + /// is_specialization + template class Template> + struct is_specialization : etl::false_type {}; + + template