From aaac4ba97cdf9e4a269e1aca8ddf2a0f676090e5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 5 Sep 2021 14:59:17 +0100 Subject: [PATCH 1/3] Updated version Modified etl::result test --- include/etl/version.h | 4 +- library.json | 2 +- library.properties | 2 +- meson.build | 2 +- support/Release notes.txt | 14 ++- test/test_result.cpp | 238 ++++++++++++++++++++++++-------------- 6 files changed, 168 insertions(+), 94 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index 4fbd4ed3..ea28f9f2 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 20 -#define ETL_VERSION_MINOR 16 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_MINOR 17 +#define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index c067cc0a..22c9a9fa 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "20.16.2", + "version": "20.17.0", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 473dcc72..66e518ba 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.16.2 +version=20.17.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/meson.build b/meson.build index b0554ef6..c44833a9 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ project('PROJECT_NAME', 'cpp_std=c++17', 'build.cpp_std=c++17', ], meson_version: '>=0.54.0', - version: '20.16.2' + version: '20.17.0' ) ###################### diff --git a/support/Release notes.txt b/support/Release notes.txt index c37cee44..b161fe65 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,5 +1,17 @@ =============================================================================== -20.16.2 Fixed incomplete template specialisations in type_traits.h for C++11 +20.17.0 +Added etl::result type +Added etl::byte_stream +Added denominated etl::to_string overloads +Added etl::remove_cvref to type traits +Replaced etl::remove_reference_t with etl::remove_cvref_t in variadic etl::variant +Added call_if and call_or member functions to etl::delegate +Improved compliance with MISRA rules +Extended 'successor' handling for all derived message router types + +=============================================================================== +20.16.2 +Fixed incomplete template specialisations in type_traits.h for C++11 =============================================================================== 20.16.1 diff --git a/test/test_result.cpp b/test/test_result.cpp index 8d6597c5..85d740d3 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -29,101 +29,154 @@ SOFTWARE. #include "unit_test_framework.h" #include "etl/result.h" +#include "etl/type_traits.h" #include +namespace +{ + struct Value + { + std::string v; + }; + + struct ValueM + { + ValueM() + { + } + + ValueM(const std::string& v_) : v(v_) + { + } + + ValueM(ValueM&& other) + : v(etl::move(other.v)) + { + } + + ValueM& operator =(ValueM&& rhs) + { + v = etl::move(rhs.v); + return *this; + } + + //ValueM(const ValueM&) = delete; + //ValueM& operator =(const ValueM&) = delete; + + ValueM(const ValueM& other) + : v(other.v) + { + } + + ValueM& operator =(const ValueM& rhs) + { + v = rhs.v; + return *this; + } + + std::string v; + }; + + struct Error + { + std::string e; + }; + + struct ErrorM + { + ErrorM() + { + } + + ErrorM(const std::string& e_) + : e(e_) + { + } + + ErrorM(ErrorM&& other) + : e(etl::move(other.e)) + { + } + + ErrorM& operator =(ErrorM&& rhs) + { + e = etl::move(rhs.e); + return *this; + } + + ErrorM(const ErrorM& other) + : e(other.e) + { + } + + ErrorM& operator =(const ErrorM& rhs) + { + e = rhs.e; + return *this; + } + + std::string e; + }; + + using Result = etl::result; + using ResultV = etl::result; + using ResultM = etl::result; +} + +// Definitions for when the STL and compiler built-ins are not avalable. +#if ETL_NOT_USING_STL && !defined(ETL_USE_TYPE_TRAITS_BUILTINS) + +using etl::is_copy_constructible; +using etl::is_move_constructible; + +//************************* +template <> +struct etl::is_copy_constructible : public etl::true_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::true_type +{ +}; + +template <> +struct etl::is_copy_constructible : public etl::true_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::true_type +{ +}; + +//************************* +template <> +struct etl::is_copy_constructible : public etl::false_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::false_type +{ +}; + +template <> +struct etl::is_copy_constructible : public etl::false_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::false_type +{ +}; +#endif + namespace { SUITE(test_result) { - struct Value - { - std::string v; - }; - - struct ValueM - { - ValueM() - { - } - - ValueM(const std::string& v_) : v(v_) - { - } - - ValueM(ValueM&& other) - : v(etl::move(other.v)) - { - } - - ValueM& operator =(ValueM&& rhs) - { - v = etl::move(rhs.v); - return *this; - } - - //ValueM(const ValueM&) = delete; - //ValueM& operator =(const ValueM&) = delete; - - ValueM(const ValueM& other) - : v(other.v) - { - } - - ValueM& operator =(const ValueM& rhs) - { - v = rhs.v; - return *this; - } - - std::string v; - }; - - struct Error - { - std::string e; - }; - - struct ErrorM - { - ErrorM() - { - } - - ErrorM(const std::string& e_) - : e(e_) - { - } - - ErrorM(ErrorM&& other) - : e(etl::move(other.e)) - { - } - - ErrorM& operator =(ErrorM&& rhs) - { - e = etl::move(rhs.e); - return *this; - } - - ErrorM(const ErrorM& other) - : e(other.e) - { - } - - ErrorM& operator =(const ErrorM& rhs) - { - e = rhs.e; - return *this; - } - - std::string e; - }; - - using Result = etl::result; - using ResultV = etl::result; - using ResultM = etl::result; - //************************************************************************* TEST(test_constructor_for_result_with_value) { @@ -283,6 +336,15 @@ namespace //************************************************************************* TEST(test_copy_construct_result) { + bool b1 = etl::is_copy_constructible_v; + bool b2 = etl::is_copy_constructible_v; + bool b3 = etl::is_copy_constructible_v; + + bool b4 = etl::is_move_constructible_v; + bool b5 = etl::is_move_constructible_v; + bool b6 = etl::is_move_constructible_v; + + Value input = { "value 1" }; Result result(input); From d55b84212f0474dbcff2722532eadbcba064e01e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 5 Sep 2021 14:59:17 +0100 Subject: [PATCH 2/3] Updated version Modified etl::result test --- test/test_result.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/test/test_result.cpp b/test/test_result.cpp index 85d740d3..cd906671 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -336,15 +336,6 @@ namespace //************************************************************************* TEST(test_copy_construct_result) { - bool b1 = etl::is_copy_constructible_v; - bool b2 = etl::is_copy_constructible_v; - bool b3 = etl::is_copy_constructible_v; - - bool b4 = etl::is_move_constructible_v; - bool b5 = etl::is_move_constructible_v; - bool b6 = etl::is_move_constructible_v; - - Value input = { "value 1" }; Result result(input); From e6c13c75e742e9080175bc7f29449aaf5b31ad51 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 5 Sep 2021 17:39:56 +0100 Subject: [PATCH 3/3] Added result type --- include/etl/result.h | 4 +-- test/test_result.cpp | 80 ++++++-------------------------------------- 2 files changed, 12 insertions(+), 72 deletions(-) diff --git a/include/etl/result.h b/include/etl/result.h index f0c8c7d8..ffb700ad 100644 --- a/include/etl/result.h +++ b/include/etl/result.h @@ -191,7 +191,7 @@ namespace etl //******************************************* TValue&& value() { - return etl::get(etl::move(data)); + return etl::move(etl::get(etl::move(data))); } //******************************************* @@ -209,7 +209,7 @@ namespace etl //******************************************* TError&& error() { - return etl::get(etl::move(data)); + return etl::move(etl::get(etl::move(data))); } private: diff --git a/test/test_result.cpp b/test/test_result.cpp index cd906671..4e953fd1 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -46,34 +46,16 @@ namespace { } - ValueM(const std::string& v_) : v(v_) + ValueM(const std::string& v_) + : v(v_) { } - ValueM(ValueM&& other) - : v(etl::move(other.v)) - { - } + ValueM(ValueM&&) = default; + ValueM& operator =(ValueM&&) = default; - ValueM& operator =(ValueM&& rhs) - { - v = etl::move(rhs.v); - return *this; - } - - //ValueM(const ValueM&) = delete; - //ValueM& operator =(const ValueM&) = delete; - - ValueM(const ValueM& other) - : v(other.v) - { - } - - ValueM& operator =(const ValueM& rhs) - { - v = rhs.v; - return *this; - } + ValueM(const ValueM&) = delete; + ValueM& operator =(const ValueM&) = delete; std::string v; }; @@ -94,27 +76,11 @@ namespace { } - ErrorM(ErrorM&& other) - : e(etl::move(other.e)) - { - } + ErrorM(ErrorM&& other) = default; + ErrorM& operator =(ErrorM&& rhs) = default; - ErrorM& operator =(ErrorM&& rhs) - { - e = etl::move(rhs.e); - return *this; - } - - ErrorM(const ErrorM& other) - : e(other.e) - { - } - - ErrorM& operator =(const ErrorM& rhs) - { - e = rhs.e; - return *this; - } + ErrorM(const ErrorM& other) = delete; + ErrorM& operator =(const ErrorM& rhs) = delete; std::string e; }; @@ -216,19 +182,6 @@ namespace CHECK(output.v == std::string("value 1")); } - //************************************************************************* - TEST(test_constructor_for_moveable_const_result_with_value) - { - ValueM input = { "value 1" }; - const ResultM result(etl::move(input)); - - ValueM output = etl::move(result.value()); - - CHECK(result.is_value()); - CHECK(!result.is_error()); - CHECK(output.v == std::string("value 1")); - } - //************************************************************************* TEST(test_constructor_for_result_with_error) { @@ -268,19 +221,6 @@ namespace CHECK(output.e == std::string("error 1")); } - //************************************************************************* - TEST(test_constructor_for_moveable_const_result_with_error) - { - ErrorM input = { "error 1" }; - const ResultM result(etl::move(input)); - - ErrorM output = etl::move(result.error()); - - CHECK(!result.is_value()); - CHECK(result.is_error()); - CHECK(output.e == std::string("error 1")); - } - //************************************************************************* TEST(test_constructor_for_result_void_value_with_error) {