From 18ab6457631100472039d8b49c2d75966a7e08b8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 15 Oct 2022 14:28:58 +0100 Subject: [PATCH 1/7] Work-In-Progress --- .gitignore | 8 + include/etl/expected.h | 479 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 487 insertions(+) create mode 100644 include/etl/expected.h diff --git a/.gitignore b/.gitignore index dd68c7525..d9577b4cb 100644 --- a/.gitignore +++ b/.gitignore @@ -360,3 +360,11 @@ test/etl_error_handler/build-exceptions_and_log_errors-GCC-Debug test/etl_error_handler/build-exceptions-GCC-Debug test/etl_error_handler/exceptions_and_log_errors/.vs examples/ArmTimerCallbacks - C++/ArmTimerCallbacks.uvoptx +test/vs2022/.vs +test/vs2022/random_clcg.csv +test/vs2022/random_hash.csv +test/vs2022/random_lsfr.csv +test/vs2022/random_lcg.csv +test/vs2022/random_mwc.csv +test/vs2022/random_pcg.csv +test/vs2022/random_xorshift.csv diff --git a/include/etl/expected.h b/include/etl/expected.h new file mode 100644 index 000000000..991625b73 --- /dev/null +++ b/include/etl/expected.h @@ -0,0 +1,479 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 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_EXPECTED_INCLUDED +#define ETL_EXPECTED_INCLUDED + +///\defgroup expected expected +///\ingroup utilities + +#include "platform.h" +#include "utility.h" + +namespace etl +{ + //*************************************************************************** + /// Unexpected type. + /// etl::unexpected represents an unexpected value stored in etl::expected. + //*************************************************************************** + template + class unexpected + { + public: + + //******************************************* + /// Copy constructor. + //******************************************* + ETL_CONSTEXPR unexpected(const unexpected& other) + : error_value(other.error_value) + { + } + + //******************************************* + /// Move constructor. + //******************************************* + ETL_CONSTEXPR unexpected(unexpected&& other) + : error_value(etl::move(other.error_value)) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from argument. + //******************************************* + template ::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type> + constexpr explicit unexpected(E&& e) + : error_value(etl::forward(e)) + { + } +#else + //******************************************* + /// Construct from argument. + //******************************************* + template + explicit unexpected(const E& e, typename etl::enable_if::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) + : error_value(e) + { + } +#endif + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, Args&&... args) + : error_value(etl::forward(args)...) + { + } + +#if ETL_HAS_INITIALIZER_LIST + //******************************************* + /// Construct from initializer_list and arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, std::initializer_list init, Args&&... args) + : error_value(init, etl::forward(args)...) + { + } +#endif + + //******************************************* + /// Assign from etl::unexpected. + //******************************************* + unexpected& operator =(const etl::unexpected& rhs) + { + error_value = rhs.error_value; + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move assign from etl::unexpected. + //******************************************* + unexpected& operator =(etl::unexpected&& rhs) + { + error_value = etl::move(rhs.error_value); + } +#endif + + //******************************************* + /// Get the error. + //******************************************* + const TError& error() const + { + return error_type; + } + + //******************************************* + /// Swap with another etl::unexpected. + //******************************************* + swap(etl::unexpected& other) + { + using ETL_OR_STD::swap; + + swap(error_value, other.error_value); + } + + private: + + TError error_value; + }; + + //******************************************* + /// Equivalence operator. + //******************************************* + template + bool operator ==(const etl::unexpected& lhs, const etl::unexpected& rhs) + { + return lhs.error_value == rhs.error_value; + } + + //******************************************* + /// Swap etl::unexpected. + //******************************************* + template + void swap(etl::unexpected& lhs, etl::unexpected& rhs) + { + lhs.swap(rhs); + } + + //***************************************************************************** + /// unexpect_t + //***************************************************************************** + struct unexpect_t + { + explicit unexpect_t() + { + } + }; + + inline ETL_CONSTEXPR14 unexpect_t unexpect{}; + + //***************************************************************************** + /// Expected type. + //***************************************************************************** + template + class expected + { + public: + + typename TValue value_type; + typename TError error_type; + typename etl::unexpected unexpected_type; + +#if ETL_CPP11_SUPPORTED + template + using rebind = etl::expected; +#endif + + //******************************************* + /// Default constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT + : data(TValue()) + { + } + + //******************************************* + /// Copy constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) + : data(other.data) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move constructor + //******************************************* + ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT + : data(etl::move(other.data)) + { + } +#endif + + template + constexpr explicit() expected(const expected& other) + { + } + + template + constexpr explicit(expected(expected&& other) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(U&& v) + { + } +#endif + + template + constexpr explicit expected(const etl::unexpected& e) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(etl::unexpected&& e) + { + } +#endif + + constexpr explicit expected(etl::in_place_t) noexcept + { + } + + template + constexpr explicit expected(etl::in_place_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) + { + } + +// //******************************************* +// // Construct from a value +// //******************************************* +// expected(const TValue& value) +// : data(value) +// { +// } +// +//#if ETL_CPP11_SUPPORTED +// //******************************************* +// // Move construct from a value +// //******************************************* +// expected(TValue&& value) +// : data(etl::move(value)) +// { +// } +//#endif + + ////******************************************* + ///// Construct from error + ////******************************************* + //expected(const TError& error) + // : data(error) + //{ + //} + + ////******************************************* + ///// Move construct from error + ////******************************************* + //expected(TError&& error) + // : data(etl::move(error)) + //{ + //} + + //******************************************* + /// Copy assign + //******************************************* + expected& operator =(const expected& other) + { + data = other.data; + return *this; + } + + //******************************************* + /// Move assign + //******************************************* + expected& operator =(expected&& other) + { + data = etl::move(other.data); + return *this; + } + + //******************************************* + /// Copy assign from value + //******************************************* + expected& operator =(const TValue& value) + { + data = value; + return *this; + } + + //******************************************* + /// Move assign from value + //******************************************* + expected& operator =(TValue&& value) + { + data = etl::move(value); + return *this; + } + + //******************************************* + /// Copy assign from error + //******************************************* + expected& operator =(const TError& error) + { + data = error; + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + expected& operator =(TError&& error) + { + data = etl::move(error); + return *this; + } + + //******************************************* + /// Returns a const reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 const TValue& value() const + { + return etl::get(data); + } + + //******************************************* + /// Returns an rvalue reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 TValue&& value() + { + return etl::move(etl::get(etl::move(data))); + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) const& + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } + + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) && + { + if (has_value()) + { + return etl::move(value()); + } + else + { + return etl::move(default_value); + } + } +#else + //******************************************* + /// + //******************************************* + template + TValue value_or(const U& default_value) const + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } +#endif + + //******************************************* + /// Returns a const reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 const TError& error() const + { + return etl::get(data); + } + +#if (ETL_CPP11_SUPPORTED) + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() && + { + return etl::move(etl::get(data)); + } + + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() const && + { + return etl::move(etl::get(data)); + } +#endif + + private: + + etl::variant data; + }; + + //***************************************************************************** + /// Result type. + /// Specialisation for void value type. + //***************************************************************************** + template + class expected + { + +} + + +#endif + From ddca5f554166906feb2551b7acd54b90b12d351e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 15 Oct 2022 14:28:58 +0100 Subject: [PATCH 2/7] Work-In-Progress --- include/etl/expected.h | 479 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 include/etl/expected.h diff --git a/include/etl/expected.h b/include/etl/expected.h new file mode 100644 index 000000000..991625b73 --- /dev/null +++ b/include/etl/expected.h @@ -0,0 +1,479 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 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_EXPECTED_INCLUDED +#define ETL_EXPECTED_INCLUDED + +///\defgroup expected expected +///\ingroup utilities + +#include "platform.h" +#include "utility.h" + +namespace etl +{ + //*************************************************************************** + /// Unexpected type. + /// etl::unexpected represents an unexpected value stored in etl::expected. + //*************************************************************************** + template + class unexpected + { + public: + + //******************************************* + /// Copy constructor. + //******************************************* + ETL_CONSTEXPR unexpected(const unexpected& other) + : error_value(other.error_value) + { + } + + //******************************************* + /// Move constructor. + //******************************************* + ETL_CONSTEXPR unexpected(unexpected&& other) + : error_value(etl::move(other.error_value)) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from argument. + //******************************************* + template ::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type> + constexpr explicit unexpected(E&& e) + : error_value(etl::forward(e)) + { + } +#else + //******************************************* + /// Construct from argument. + //******************************************* + template + explicit unexpected(const E& e, typename etl::enable_if::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) + : error_value(e) + { + } +#endif + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, Args&&... args) + : error_value(etl::forward(args)...) + { + } + +#if ETL_HAS_INITIALIZER_LIST + //******************************************* + /// Construct from initializer_list and arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, std::initializer_list init, Args&&... args) + : error_value(init, etl::forward(args)...) + { + } +#endif + + //******************************************* + /// Assign from etl::unexpected. + //******************************************* + unexpected& operator =(const etl::unexpected& rhs) + { + error_value = rhs.error_value; + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move assign from etl::unexpected. + //******************************************* + unexpected& operator =(etl::unexpected&& rhs) + { + error_value = etl::move(rhs.error_value); + } +#endif + + //******************************************* + /// Get the error. + //******************************************* + const TError& error() const + { + return error_type; + } + + //******************************************* + /// Swap with another etl::unexpected. + //******************************************* + swap(etl::unexpected& other) + { + using ETL_OR_STD::swap; + + swap(error_value, other.error_value); + } + + private: + + TError error_value; + }; + + //******************************************* + /// Equivalence operator. + //******************************************* + template + bool operator ==(const etl::unexpected& lhs, const etl::unexpected& rhs) + { + return lhs.error_value == rhs.error_value; + } + + //******************************************* + /// Swap etl::unexpected. + //******************************************* + template + void swap(etl::unexpected& lhs, etl::unexpected& rhs) + { + lhs.swap(rhs); + } + + //***************************************************************************** + /// unexpect_t + //***************************************************************************** + struct unexpect_t + { + explicit unexpect_t() + { + } + }; + + inline ETL_CONSTEXPR14 unexpect_t unexpect{}; + + //***************************************************************************** + /// Expected type. + //***************************************************************************** + template + class expected + { + public: + + typename TValue value_type; + typename TError error_type; + typename etl::unexpected unexpected_type; + +#if ETL_CPP11_SUPPORTED + template + using rebind = etl::expected; +#endif + + //******************************************* + /// Default constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT + : data(TValue()) + { + } + + //******************************************* + /// Copy constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) + : data(other.data) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move constructor + //******************************************* + ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT + : data(etl::move(other.data)) + { + } +#endif + + template + constexpr explicit() expected(const expected& other) + { + } + + template + constexpr explicit(expected(expected&& other) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(U&& v) + { + } +#endif + + template + constexpr explicit expected(const etl::unexpected& e) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(etl::unexpected&& e) + { + } +#endif + + constexpr explicit expected(etl::in_place_t) noexcept + { + } + + template + constexpr explicit expected(etl::in_place_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) + { + } + +// //******************************************* +// // Construct from a value +// //******************************************* +// expected(const TValue& value) +// : data(value) +// { +// } +// +//#if ETL_CPP11_SUPPORTED +// //******************************************* +// // Move construct from a value +// //******************************************* +// expected(TValue&& value) +// : data(etl::move(value)) +// { +// } +//#endif + + ////******************************************* + ///// Construct from error + ////******************************************* + //expected(const TError& error) + // : data(error) + //{ + //} + + ////******************************************* + ///// Move construct from error + ////******************************************* + //expected(TError&& error) + // : data(etl::move(error)) + //{ + //} + + //******************************************* + /// Copy assign + //******************************************* + expected& operator =(const expected& other) + { + data = other.data; + return *this; + } + + //******************************************* + /// Move assign + //******************************************* + expected& operator =(expected&& other) + { + data = etl::move(other.data); + return *this; + } + + //******************************************* + /// Copy assign from value + //******************************************* + expected& operator =(const TValue& value) + { + data = value; + return *this; + } + + //******************************************* + /// Move assign from value + //******************************************* + expected& operator =(TValue&& value) + { + data = etl::move(value); + return *this; + } + + //******************************************* + /// Copy assign from error + //******************************************* + expected& operator =(const TError& error) + { + data = error; + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + expected& operator =(TError&& error) + { + data = etl::move(error); + return *this; + } + + //******************************************* + /// Returns a const reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 const TValue& value() const + { + return etl::get(data); + } + + //******************************************* + /// Returns an rvalue reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 TValue&& value() + { + return etl::move(etl::get(etl::move(data))); + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) const& + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } + + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) && + { + if (has_value()) + { + return etl::move(value()); + } + else + { + return etl::move(default_value); + } + } +#else + //******************************************* + /// + //******************************************* + template + TValue value_or(const U& default_value) const + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } +#endif + + //******************************************* + /// Returns a const reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 const TError& error() const + { + return etl::get(data); + } + +#if (ETL_CPP11_SUPPORTED) + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() && + { + return etl::move(etl::get(data)); + } + + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() const && + { + return etl::move(etl::get(data)); + } +#endif + + private: + + etl::variant data; + }; + + //***************************************************************************** + /// Result type. + /// Specialisation for void value type. + //***************************************************************************** + template + class expected + { + +} + + +#endif + From 3892a45eeccfe514c23acc54a647217fd6194dea Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 15 Oct 2022 14:28:58 +0100 Subject: [PATCH 3/7] Work-In-Progress --- include/etl/expected.h | 479 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 479 insertions(+) create mode 100644 include/etl/expected.h diff --git a/include/etl/expected.h b/include/etl/expected.h new file mode 100644 index 000000000..991625b73 --- /dev/null +++ b/include/etl/expected.h @@ -0,0 +1,479 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 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_EXPECTED_INCLUDED +#define ETL_EXPECTED_INCLUDED + +///\defgroup expected expected +///\ingroup utilities + +#include "platform.h" +#include "utility.h" + +namespace etl +{ + //*************************************************************************** + /// Unexpected type. + /// etl::unexpected represents an unexpected value stored in etl::expected. + //*************************************************************************** + template + class unexpected + { + public: + + //******************************************* + /// Copy constructor. + //******************************************* + ETL_CONSTEXPR unexpected(const unexpected& other) + : error_value(other.error_value) + { + } + + //******************************************* + /// Move constructor. + //******************************************* + ETL_CONSTEXPR unexpected(unexpected&& other) + : error_value(etl::move(other.error_value)) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from argument. + //******************************************* + template ::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type> + constexpr explicit unexpected(E&& e) + : error_value(etl::forward(e)) + { + } +#else + //******************************************* + /// Construct from argument. + //******************************************* + template + explicit unexpected(const E& e, typename etl::enable_if::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) + : error_value(e) + { + } +#endif + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Construct from arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, Args&&... args) + : error_value(etl::forward(args)...) + { + } + +#if ETL_HAS_INITIALIZER_LIST + //******************************************* + /// Construct from initializer_list and arguments. + //******************************************* + template + constexpr explicit unexpected(etl::in_place_t, std::initializer_list init, Args&&... args) + : error_value(init, etl::forward(args)...) + { + } +#endif + + //******************************************* + /// Assign from etl::unexpected. + //******************************************* + unexpected& operator =(const etl::unexpected& rhs) + { + error_value = rhs.error_value; + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move assign from etl::unexpected. + //******************************************* + unexpected& operator =(etl::unexpected&& rhs) + { + error_value = etl::move(rhs.error_value); + } +#endif + + //******************************************* + /// Get the error. + //******************************************* + const TError& error() const + { + return error_type; + } + + //******************************************* + /// Swap with another etl::unexpected. + //******************************************* + swap(etl::unexpected& other) + { + using ETL_OR_STD::swap; + + swap(error_value, other.error_value); + } + + private: + + TError error_value; + }; + + //******************************************* + /// Equivalence operator. + //******************************************* + template + bool operator ==(const etl::unexpected& lhs, const etl::unexpected& rhs) + { + return lhs.error_value == rhs.error_value; + } + + //******************************************* + /// Swap etl::unexpected. + //******************************************* + template + void swap(etl::unexpected& lhs, etl::unexpected& rhs) + { + lhs.swap(rhs); + } + + //***************************************************************************** + /// unexpect_t + //***************************************************************************** + struct unexpect_t + { + explicit unexpect_t() + { + } + }; + + inline ETL_CONSTEXPR14 unexpect_t unexpect{}; + + //***************************************************************************** + /// Expected type. + //***************************************************************************** + template + class expected + { + public: + + typename TValue value_type; + typename TError error_type; + typename etl::unexpected unexpected_type; + +#if ETL_CPP11_SUPPORTED + template + using rebind = etl::expected; +#endif + + //******************************************* + /// Default constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT + : data(TValue()) + { + } + + //******************************************* + /// Copy constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) + : data(other.data) + { + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// Move constructor + //******************************************* + ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT + : data(etl::move(other.data)) + { + } +#endif + + template + constexpr explicit() expected(const expected& other) + { + } + + template + constexpr explicit(expected(expected&& other) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(U&& v) + { + } +#endif + + template + constexpr explicit expected(const etl::unexpected& e) + { + } + +#if ETL_CPP11_SUPPORTED + template + constexpr explicit expected(etl::unexpected&& e) + { + } +#endif + + constexpr explicit expected(etl::in_place_t) noexcept + { + } + + template + constexpr explicit expected(etl::in_place_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, Args&&... args) + { + } + + template + constexpr explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) + { + } + +// //******************************************* +// // Construct from a value +// //******************************************* +// expected(const TValue& value) +// : data(value) +// { +// } +// +//#if ETL_CPP11_SUPPORTED +// //******************************************* +// // Move construct from a value +// //******************************************* +// expected(TValue&& value) +// : data(etl::move(value)) +// { +// } +//#endif + + ////******************************************* + ///// Construct from error + ////******************************************* + //expected(const TError& error) + // : data(error) + //{ + //} + + ////******************************************* + ///// Move construct from error + ////******************************************* + //expected(TError&& error) + // : data(etl::move(error)) + //{ + //} + + //******************************************* + /// Copy assign + //******************************************* + expected& operator =(const expected& other) + { + data = other.data; + return *this; + } + + //******************************************* + /// Move assign + //******************************************* + expected& operator =(expected&& other) + { + data = etl::move(other.data); + return *this; + } + + //******************************************* + /// Copy assign from value + //******************************************* + expected& operator =(const TValue& value) + { + data = value; + return *this; + } + + //******************************************* + /// Move assign from value + //******************************************* + expected& operator =(TValue&& value) + { + data = etl::move(value); + return *this; + } + + //******************************************* + /// Copy assign from error + //******************************************* + expected& operator =(const TError& error) + { + data = error; + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + expected& operator =(TError&& error) + { + data = etl::move(error); + return *this; + } + + //******************************************* + /// Returns a const reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 const TValue& value() const + { + return etl::get(data); + } + + //******************************************* + /// Returns an rvalue reference to the value. + /// Undefined if the expected does not contain an value. + //******************************************* + ETL_CONSTEXPR14 TValue&& value() + { + return etl::move(etl::get(etl::move(data))); + } + +#if ETL_CPP11_SUPPORTED + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) const& + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } + + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 TValue value_or(U&& default_value) && + { + if (has_value()) + { + return etl::move(value()); + } + else + { + return etl::move(default_value); + } + } +#else + //******************************************* + /// + //******************************************* + template + TValue value_or(const U& default_value) const + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } +#endif + + //******************************************* + /// Returns a const reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 const TError& error() const + { + return etl::get(data); + } + +#if (ETL_CPP11_SUPPORTED) + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() && + { + return etl::move(etl::get(data)); + } + + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the expected does not contain an error. + //******************************************* + ETL_CONSTEXPR14 TError&& error() const && + { + return etl::move(etl::get(data)); + } +#endif + + private: + + etl::variant data; + }; + + //***************************************************************************** + /// Result type. + /// Specialisation for void value type. + //***************************************************************************** + template + class expected + { + +} + + +#endif + From a1ee6deec594ee3a071bce3bd75de4bdd5b12b8a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 24 Oct 2022 17:15:25 +0100 Subject: [PATCH 4/7] Work-In-Progress --- include/etl/expected.h | 12 +++++++++++- test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/etl/expected.h b/include/etl/expected.h index 991625b73..252008f2e 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -95,6 +95,7 @@ namespace etl : error_value(etl::forward(args)...) { } +#endif #if ETL_HAS_INITIALIZER_LIST //******************************************* @@ -171,12 +172,14 @@ namespace etl //***************************************************************************** struct unexpect_t { - explicit unexpect_t() + ETL_CONSTEXPR14 explicit unexpect_t() { } }; +#if ETL_CPP14_SUPPORTED inline ETL_CONSTEXPR14 unexpect_t unexpect{}; +#endif //***************************************************************************** /// Expected type. @@ -471,7 +474,14 @@ namespace etl template class expected { + public: + + + private: + + TError error; + }; } diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 63d366d51..c855b06b2 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -2439,6 +2439,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index bb5c004eb..fffd334eb 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1341,6 +1341,9 @@ ETL\Strings + + ETL\Utilities + From a1bf74009f10fc9cefb3d6f57db58bb51076e8a1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Oct 2022 09:52:39 +0100 Subject: [PATCH 5/7] Work-In-Progress --- include/etl/expected.h | 302 ++++++++++++++++++++----------- include/etl/file_error_numbers.h | 2 +- include/etl/optional.h | 6 +- include/etl/result.h | 20 +- test/vs2019/etl.vcxproj.filters | 12 +- 5 files changed, 226 insertions(+), 116 deletions(-) diff --git a/include/etl/expected.h b/include/etl/expected.h index 252008f2e..9b8d86e86 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -35,10 +35,56 @@ SOFTWARE. ///\ingroup utilities #include "platform.h" +#include "exception.h" +#include "error_handler.h" #include "utility.h" +#include "variant.h" namespace etl { + //*************************************************************************** + /// Base exception for et::expected + //*************************************************************************** + class expected_exception : public etl::exception + { + public: + + expected_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /// expected_invalid + //*************************************************************************** + template + class expected_invalid; + + //******************************************* + template<> + class expected_invalid : public etl::expected_exception + { + public: + + expected_invalid(string_type file_name_, numeric_type line_number_) + : expected_exception(ETL_ERROR_TEXT("expected:invalid", ETL_EXPECTED_FILE_ID"A"), file_name_, line_number_) + { + } + }; + + //******************************************* + template + class expected_invalid : etl::expected_invalid + { + public: + + expected_invalid(string_type file_name_, numeric_type line_number_) + : expected_invalid(file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Unexpected type. /// etl::unexpected represents an unexpected value stored in etl::expected. @@ -56,6 +102,7 @@ namespace etl { } +#if ETL_CPP11_SUPPORTED //******************************************* /// Move constructor. //******************************************* @@ -63,24 +110,25 @@ namespace etl : error_value(etl::move(other.error_value)) { } +#endif #if ETL_CPP11_SUPPORTED //******************************************* /// Construct from argument. //******************************************* - template ::type, etl::unexpected>::value && - !etl::is_same::type, etl::in_place_t>::value, int>::type> - constexpr explicit unexpected(E&& e) - : error_value(etl::forward(e)) + template ::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type> + constexpr explicit unexpected(TErr&& e) + : error_value(etl::forward(e)) { } #else //******************************************* /// Construct from argument. //******************************************* - template - explicit unexpected(const E& e, typename etl::enable_if::type, etl::unexpected>::value && - !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) + template + explicit unexpected(const TErr& e, typename etl::enable_if::type, etl::unexpected>::value && + !etl::is_same::type, etl::in_place_t>::value, int>::type = 0) : error_value(e) { } @@ -111,7 +159,7 @@ namespace etl //******************************************* /// Assign from etl::unexpected. //******************************************* - unexpected& operator =(const etl::unexpected& rhs) + unexpected& operator =(const etl::unexpected& rhs) { error_value = rhs.error_value; } @@ -120,7 +168,7 @@ namespace etl //******************************************* /// Move assign from etl::unexpected. //******************************************* - unexpected& operator =(etl::unexpected&& rhs) + unexpected& operator =(etl::unexpected&& rhs) { error_value = etl::move(rhs.error_value); } @@ -137,7 +185,7 @@ namespace etl //******************************************* /// Swap with another etl::unexpected. //******************************************* - swap(etl::unexpected& other) + void swap(etl::unexpected& other) { using ETL_OR_STD::swap; @@ -195,13 +243,13 @@ namespace etl #if ETL_CPP11_SUPPORTED template - using rebind = etl::expected; + using rebind = etl::expected; #endif //******************************************* /// Default constructor //******************************************* - ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT + ETL_CONSTEXPR14 expected() ETL_NOEXCEPT : data(TValue()) { } @@ -209,7 +257,7 @@ namespace etl //******************************************* /// Copy constructor //******************************************* - ETL_CONSTEXPR14 expected(const expected& other) + ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT : data(other.data) { } @@ -224,109 +272,47 @@ namespace etl } #endif - template - constexpr explicit() expected(const expected& other) - { - } - - template - constexpr explicit(expected(expected&& other) - { - } - -#if ETL_CPP11_SUPPORTED - template - constexpr explicit expected(U&& v) - { - } -#endif - template - constexpr explicit expected(const etl::unexpected& e) + ETL_CONSTEXPR14 explicit expected(const etl::unexpected& ue) + : data(ue) { } #if ETL_CPP11_SUPPORTED template - constexpr explicit expected(etl::unexpected&& e) + ETL_CONSTEXPR14 explicit expected(etl::unexpected&& ue) + : data(etl::move(ue)) { } #endif - constexpr explicit expected(etl::in_place_t) noexcept + ETL_CONSTEXPR14 explicit expected(etl::in_place_t) ETL_NOEXCEPT + : data(TValue()) { } template - constexpr explicit expected(etl::in_place_t, Args&&... args) + ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args) + : data(etl::forward(args)...) { } template - constexpr explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + : data(il, etl::forward(args)...) { } template - constexpr explicit expected(etl::unexpect_t, Args&&... args) + ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, Args&&... args) + : data(etl::unexpected(args...)) { } template - constexpr explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) - { - } - -// //******************************************* -// // Construct from a value -// //******************************************* -// expected(const TValue& value) -// : data(value) -// { -// } -// -//#if ETL_CPP11_SUPPORTED -// //******************************************* -// // Move construct from a value -// //******************************************* -// expected(TValue&& value) -// : data(etl::move(value)) -// { -// } -//#endif - - ////******************************************* - ///// Construct from error - ////******************************************* - //expected(const TError& error) - // : data(error) - //{ - //} - - ////******************************************* - ///// Move construct from error - ////******************************************* - //expected(TError&& error) - // : data(etl::move(error)) - //{ - //} - - //******************************************* - /// Copy assign - //******************************************* - expected& operator =(const expected& other) - { - data = other.data; - return *this; - } - - //******************************************* - /// Move assign - //******************************************* - expected& operator =(expected&& other) + ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) + : data(etl::unexpected(il, args...)) { - data = etl::move(other.data); - return *this; } //******************************************* @@ -365,23 +351,48 @@ namespace etl return *this; } +#if ETL_CPP11_SUPPORTED //******************************************* - /// Returns a const reference to the value. - /// Undefined if the expected does not contain an value. + /// //******************************************* - ETL_CONSTEXPR14 const TValue& value() const + ETL_CONSTEXPR14 T& value() & { return etl::get(data); } //******************************************* - /// Returns an rvalue reference to the value. + /// + //******************************************* + ETL_CONSTEXPR14 const T& value() const& + { + return etl::get(data); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 T&& value() && + { + return etl::move(etl::get(data)); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 const T&& value() const&& + { + return etl::move(etl::get(data)); + } +#else + //******************************************* + /// Returns a const reference to the value. /// Undefined if the expected does not contain an value. //******************************************* - ETL_CONSTEXPR14 TValue&& value() + ETL_CONSTEXPR14 const TValue& value() const { - return etl::move(etl::get(etl::move(data))); + return etl::get(data); } +#endif #if ETL_CPP11_SUPPORTED //******************************************* @@ -433,6 +444,39 @@ namespace etl } #endif +#if ETL_CPP11_SUPPORTED + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 const TError& error() const& ETL_NOEXCEPT + { + return etl::get(data); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 TError& error() & ETL_NOEXCEPT + { + return etl::get(data); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 const TError&& error() const&& ETL_NOEXCEPT + { + return etl::move(etl::get(data)); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 TError&& error() && ETL_NOEXCEPT + { + return etl::move(etl::get(data)); + } +#else //******************************************* /// Returns a const reference to the error. /// Undefined if the expected does not contain an error. @@ -441,34 +485,82 @@ namespace etl { return etl::get(data); } +#endif -#if (ETL_CPP11_SUPPORTED) +#if ETL_CPP11_SUPPORTED //******************************************* - /// Returns an rvalue reference to the error. - /// Undefined if the expected does not contain an error. + /// + //******************************************* + template + ETL_CONSTEXPR14 T& emplace(Args&&... args) ETL_NOEXCEPT + { + data.emplace(args...); + } + + //******************************************* + /// //******************************************* - ETL_CONSTEXPR14 TError&& error() && + template + ETL_CONSTEXPR14 T& emplace(std::initializer_list& il, Args&&... args) ETL_NOEXCEPT { - return etl::move(etl::get(data)); + data.emplace(il, args...); } +#endif //******************************************* - /// Returns an rvalue reference to the error. - /// Undefined if the expected does not contain an error. + /// //******************************************* - ETL_CONSTEXPR14 TError&& error() const && + TValue* operator ->() { - return etl::move(etl::get(data)); +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return etl::addressof(data.get()); } + + //******************************************* + /// + //******************************************* + const TValue* operator ->() const + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); #endif + return etl::addressof(data.get()); + } + + //******************************************* + /// + //******************************************* + TValue& operator *() + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return data.get(); + } + + //******************************************* + /// + //******************************************* + const TValue& operator *() const + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return data.get(); + } + private: etl::variant data; }; //***************************************************************************** - /// Result type. /// Specialisation for void value type. //***************************************************************************** template diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 7d6a0e1a7..b0500c481 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -100,5 +100,5 @@ SOFTWARE. #define ETL_BIP_BUFFER_SPSC_ATOMIC_FILE_ID "67" #define ETL_REFERENCE_COUNTED_OBJECT_FILE_ID "68" #define ETL_TO_ARITHMETIC_FILE_ID "69" - +#define ETL_EXPECTED_FILE_ID "70" #endif diff --git a/include/etl/optional.h b/include/etl/optional.h index 9370b5368..8de5197a1 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -91,7 +91,7 @@ namespace etl public: optional_invalid(string_type file_name_, numeric_type line_number_) - : optional_exception("optional: invalid", file_name_, line_number_) + : optional_exception("optional:invalid", file_name_, line_number_) { } }; @@ -100,7 +100,7 @@ namespace etl /// An optional type. /// If the optional type is not initialised then a type is not constructed. /// See http://en.cppreference.com/w/cpp/utility/optional - ///\tparam The type to store. + ///\tparam T The type to store. ///\ingroup utilities //***************************************************************************** template ::value> @@ -516,6 +516,8 @@ namespace etl //***************************************************************************** /// For POD types. + ///\tparam T The type to store. + ///\ingroup utilities //***************************************************************************** template class optional diff --git a/include/etl/result.h b/include/etl/result.h index 9d79dbf4e..33653c664 100644 --- a/include/etl/result.h +++ b/include/etl/result.h @@ -49,7 +49,7 @@ namespace etl /// Result type. //***************************************************************************** template - class result + class ETL_DEPRECATED result { public: @@ -66,6 +66,7 @@ namespace etl { } +#if ETL_CPP11_SUPPORTED //******************************************* /// Move constructor //******************************************* @@ -73,6 +74,7 @@ namespace etl : data(etl::move(other.data)) { } +#endif //******************************************* // Construct from a value @@ -85,7 +87,7 @@ namespace etl //******************************************* // Move construct from a value //******************************************* - result(TValue&& value) + result(TValue&& value) : data(etl::move(value)) { } @@ -101,10 +103,12 @@ namespace etl //******************************************* /// Move construct from error //******************************************* +#if ETL_CPP11_SUPPORTED result(TError&& error) : data(etl::move(error)) { } +#endif //******************************************* /// Copy assign @@ -136,11 +140,13 @@ namespace etl //******************************************* /// Move assign from value //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TValue&& value) { data = etl::move(value); return *this; } +#endif //******************************************* /// Copy assign from error @@ -154,11 +160,13 @@ namespace etl //******************************************* /// Move assign from error //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TError&& error) { data = etl::move(error); return *this; } +#endif //******************************************* /// true if result contains a value @@ -215,10 +223,12 @@ namespace etl /// Returns an rvalue reference to the error. /// Undefined if the result does not contain an error. //******************************************* +#if ETL_CPP11_SUPPORTED TError&& error() { return etl::move(etl::get(etl::move(data))); } +#endif private: @@ -269,10 +279,12 @@ namespace etl //******************************************* /// Move construct from error //******************************************* +#if ETL_CPP11_SUPPORTED result(TError&& err_) : err(etl::move(err_)) { } +#endif //******************************************* /// Copy assign from error @@ -286,11 +298,13 @@ namespace etl //******************************************* /// Move assign from error //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TError&& err_) { err = etl::move(err_); return *this; } +#endif //******************************************* /// true if result contains a value @@ -321,10 +335,12 @@ namespace etl /// Returns an rvalue reference to the error. /// Undefined if the result does not contain an error. //******************************************* +#if ETL_CPP11_SUPPORTED TError&& error() { return etl::move(err); } +#endif private: diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index fffd334eb..f3bb0187f 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -345,9 +345,6 @@ ETL\Utilities - - ETL\Containers - ETL\Containers @@ -1344,6 +1341,9 @@ ETL\Utilities + + ETL\Utilities + @@ -2192,9 +2192,6 @@ Tests\Maths - - Tests\Containers - Tests\Errors @@ -3392,6 +3389,9 @@ Tests\Sanity Checks\Source + + Tests\Misc + From e9a13b8c9b9c29dc7f5ab75255d2cefc548cf2cc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Oct 2022 09:52:39 +0100 Subject: [PATCH 6/7] Work-In-Progress --- include/etl/file_error_numbers.h | 2 +- include/etl/optional.h | 6 ++++-- include/etl/result.h | 20 ++++++++++++++++++-- test/vs2019/etl.vcxproj.filters | 12 ++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/etl/file_error_numbers.h b/include/etl/file_error_numbers.h index 7d6a0e1a7..b0500c481 100644 --- a/include/etl/file_error_numbers.h +++ b/include/etl/file_error_numbers.h @@ -100,5 +100,5 @@ SOFTWARE. #define ETL_BIP_BUFFER_SPSC_ATOMIC_FILE_ID "67" #define ETL_REFERENCE_COUNTED_OBJECT_FILE_ID "68" #define ETL_TO_ARITHMETIC_FILE_ID "69" - +#define ETL_EXPECTED_FILE_ID "70" #endif diff --git a/include/etl/optional.h b/include/etl/optional.h index 9370b5368..8de5197a1 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -91,7 +91,7 @@ namespace etl public: optional_invalid(string_type file_name_, numeric_type line_number_) - : optional_exception("optional: invalid", file_name_, line_number_) + : optional_exception("optional:invalid", file_name_, line_number_) { } }; @@ -100,7 +100,7 @@ namespace etl /// An optional type. /// If the optional type is not initialised then a type is not constructed. /// See http://en.cppreference.com/w/cpp/utility/optional - ///\tparam The type to store. + ///\tparam T The type to store. ///\ingroup utilities //***************************************************************************** template ::value> @@ -516,6 +516,8 @@ namespace etl //***************************************************************************** /// For POD types. + ///\tparam T The type to store. + ///\ingroup utilities //***************************************************************************** template class optional diff --git a/include/etl/result.h b/include/etl/result.h index 9d79dbf4e..33653c664 100644 --- a/include/etl/result.h +++ b/include/etl/result.h @@ -49,7 +49,7 @@ namespace etl /// Result type. //***************************************************************************** template - class result + class ETL_DEPRECATED result { public: @@ -66,6 +66,7 @@ namespace etl { } +#if ETL_CPP11_SUPPORTED //******************************************* /// Move constructor //******************************************* @@ -73,6 +74,7 @@ namespace etl : data(etl::move(other.data)) { } +#endif //******************************************* // Construct from a value @@ -85,7 +87,7 @@ namespace etl //******************************************* // Move construct from a value //******************************************* - result(TValue&& value) + result(TValue&& value) : data(etl::move(value)) { } @@ -101,10 +103,12 @@ namespace etl //******************************************* /// Move construct from error //******************************************* +#if ETL_CPP11_SUPPORTED result(TError&& error) : data(etl::move(error)) { } +#endif //******************************************* /// Copy assign @@ -136,11 +140,13 @@ namespace etl //******************************************* /// Move assign from value //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TValue&& value) { data = etl::move(value); return *this; } +#endif //******************************************* /// Copy assign from error @@ -154,11 +160,13 @@ namespace etl //******************************************* /// Move assign from error //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TError&& error) { data = etl::move(error); return *this; } +#endif //******************************************* /// true if result contains a value @@ -215,10 +223,12 @@ namespace etl /// Returns an rvalue reference to the error. /// Undefined if the result does not contain an error. //******************************************* +#if ETL_CPP11_SUPPORTED TError&& error() { return etl::move(etl::get(etl::move(data))); } +#endif private: @@ -269,10 +279,12 @@ namespace etl //******************************************* /// Move construct from error //******************************************* +#if ETL_CPP11_SUPPORTED result(TError&& err_) : err(etl::move(err_)) { } +#endif //******************************************* /// Copy assign from error @@ -286,11 +298,13 @@ namespace etl //******************************************* /// Move assign from error //******************************************* +#if ETL_CPP11_SUPPORTED result& operator =(TError&& err_) { err = etl::move(err_); return *this; } +#endif //******************************************* /// true if result contains a value @@ -321,10 +335,12 @@ namespace etl /// Returns an rvalue reference to the error. /// Undefined if the result does not contain an error. //******************************************* +#if ETL_CPP11_SUPPORTED TError&& error() { return etl::move(err); } +#endif private: diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index e6c75e07a..1f0ab436f 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -345,9 +345,6 @@ ETL\Utilities - - ETL\Containers - ETL\Containers @@ -1344,6 +1341,9 @@ ETL\Containers + + ETL\Utilities + @@ -2192,9 +2192,6 @@ Tests\Maths - - Tests\Containers - Tests\Errors @@ -3392,6 +3389,9 @@ Tests\Sanity Checks\Source + + Tests\Misc + From 5fb3e4c2e6049b05ec49653925780f6bef9a8f6b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 2 Nov 2022 11:54:21 +0000 Subject: [PATCH 7/7] Work-In-Progress for full implementation of etl::expected fix set of ETL_NO_STL flag (#628) Co-authored-by: Sergey Skorokhod Removed duplicate include unique_ptr updates - Work in progress Updated versions & memory.h Fix duplicate function Fixed incorrect 'valid' flag in assignment operator for arithmetic specialisation Updated version and release notes Fix bug #636 in optional emplace for pod types (#638) Updated version info Updated generator test script Only build tests if top level project (#639) Removed trailing spaces Updated version info Incorrect C++03 enable_if syntax Updated version info Don't use `push_macro` and `pull_macro` with Tasking compiler (#643) * Autodetect Tasking compiler #642 * Don't use `push_macro` and `pop_macro` for Tasking compiler #642 Co-authored-by: Todd Snider #643 Don't use push_macro and pull_macro with Tasking compiler Updated etl::delgate to handle const functors correctly Updated version info Fixed functor delegate enable_if Updated release notes Avoid 'missing return statement at end of non-void function' in `etl::visit<>()`. (#645) * Avoid 'missing return statement at end of non-void function' in `etl::visit<>()`. For some definitions of `ETL_ASSERT()` there may be no return statement in case of an invalid type. This results in undefined behavior. Warning[Pe940]: missing return statement at end of non-void function "etl::visit(TVisitor &, TVariant const &) include\etl\private\variant_legacy.h 976 * Use more self-explaining code. Substitute ET_ASSERT() and return by dedicated macro. This moves the responsibility of how to handle errors to the dedicated place. improve is_constructible, is_copy_constructible, is_move_constructible for type traits with default definitions (#648) Removed unused ETL_USE_MEM_BUILTINS option Updated version info Updated release notes Added etl::result specialisation Reverted code for etl::result specialisation Added etl::result specialisation Reverted code for etl::result specialisation Fixed perfect forwarding for make_xxx helper functions Don't warn on tag missing when subproject (#653) (#655) Different solution than proposed in the issue, since that proposed solution would given unexpected results when an intermediate (untagged) commit is checked out. This change simply skips warning about a missing git version when this is a subproject, and uses the original version calculation logic. I've also renamed `determine_version` to `determine_version_with_file`. I'd originally done this in an intermediate version of this PR, but I think that keeping the renaming is clearer code. Removed superfluous semicolons Updated version and release notes Removed testing for 18.04 Added testing for 22.04 Updated Github Actions for Clang Updated version and release notes clang updates for Github Actions Added missing notes emplace member functions return reference to emplaced value (#659) emplace_front, emplace_back updates Updated version and release info Improved emplace testing Changed unit test macro CHECK_FALSE_EQUAL to CHECK_NOT_EQUAL Improved emplace testing Changed unit test macro CHECK_FALSE_EQUAL to CHECK_NOT_EQUAL Improved emplace testing Work-In-Progress Work-In-Progress Added indexed emplace More typedefs for etl::result Work in progress Work in progress Work in progress Changed default constructor Added function comments --- .github/workflows/clang.yml | 38 +- .github/workflows/gcc.yml | 6 +- CMakeLists.txt | 12 +- arduino/library-arduino.json | 2 +- arduino/library-arduino.properties | 2 +- cmake/helpers.cmake | 8 +- include/etl/array_view.h | 9 +- include/etl/binary.h | 4 +- include/etl/delegate.h | 2 +- include/etl/deque.h | 30 +- include/etl/expected.h | 691 ++++++++++++++++-- include/etl/forward_list.h | 17 +- .../etl/generators/type_traits_generator.h | 40 +- include/etl/indirect_vector.h | 17 +- include/etl/list.h | 30 +- include/etl/memory.h | 128 +++- include/etl/optional.h | 23 +- include/etl/private/delegate_cpp03.h | 159 +++- include/etl/private/delegate_cpp11.h | 64 +- include/etl/private/ivectorpointer.h | 4 +- include/etl/private/minmax_pop.h | 2 +- include/etl/private/minmax_push.h | 2 +- include/etl/private/variant_legacy.h | 32 +- include/etl/private/variant_variadic.h | 23 +- include/etl/profiles/determine_compiler.h | 13 + .../etl/profiles/determine_compiler_version.h | 3 + include/etl/result.h | 165 ++++- include/etl/span.h | 16 +- include/etl/type_traits.h | 40 +- include/etl/vector.h | 17 +- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- meson.build | 6 +- scripts/generator_test.py | 7 +- support/Release notes.txt | 49 ++ test/CMakeLists.txt | 7 +- test/UnitTest++/CheckMacros.h | 14 +- test/runsanitychecks.sh | 158 +--- test/runtests.sh | 54 +- test/sanity-check/c++03/CMakeLists.txt | 6 +- test/sanity-check/c++11/CMakeLists.txt | 6 +- test/sanity-check/c++14/CMakeLists.txt | 6 +- test/sanity-check/c++17/CMakeLists.txt | 6 +- test/sanity-check/expected.h.t.cpp | 29 + test/test_delegate.cpp | 187 +++-- test/test_delegate_cpp03.cpp | 125 ++-- test/test_deque.cpp | 20 + test/test_expected.cpp | 446 +++++++++++ test/test_forward_list.cpp | 10 + test/test_indirect_vector.cpp | 12 + test/test_list.cpp | 20 + test/test_memory.cpp | 43 ++ test/test_optional.cpp | 35 + test/test_result.cpp | 192 ++--- test/test_type_traits.cpp | 15 - test/test_vector.cpp | 60 +- test/test_vector_external_buffer.cpp | 35 + test/test_vector_non_trivial.cpp | 56 +- test/test_vector_pointer.cpp | 11 + test/test_vector_pointer_external_buffer.cpp | 11 + test/vs2019/etl.vcxproj | 29 + test/vs2019/etl.vcxproj.filters | 15 +- version.txt | 2 +- 64 files changed, 2530 insertions(+), 747 deletions(-) create mode 100644 test/sanity-check/expected.h.t.cpp create mode 100644 test/test_expected.cpp diff --git a/.github/workflows/clang.yml b/.github/workflows/clang.yml index 7dfaf5049..bcb3722fc 100644 --- a/.github/workflows/clang.yml +++ b/.github/workflows/clang.yml @@ -6,12 +6,12 @@ on: branches: [ master ] jobs: - build-clang-9-linux-stl: - name: Clang-9 Linux - STL + build-clang-linux-stl: + name: Clang Linux - STL runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 @@ -19,9 +19,9 @@ jobs: - name: Build run: | sudo apt-get update - sudo apt-get install -y "clang-9" "lldb-9" "lld-9" "clang-format-9" - export CC=clang-9 - export CXX=clang++-9 + sudo apt-get install -y "clang" "lldb" "lld" "clang-format" + export CC=clang + export CXX=clang++ export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0 git fetch --tags cmake -D BUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF ./ @@ -31,12 +31,12 @@ jobs: - name: Run tests run: ./test/etl_tests - build-clang-9-linux-no-stl: - name: Clang-9 Linux - No STL + build-clang-linux-no-stl: + name: Clang Linux - No STL runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 @@ -44,26 +44,24 @@ jobs: - name: Build run: | sudo apt-get update - sudo apt-get install -y "clang-9" "lldb-9" "lld-9" "clang-format-9" - export CC=clang-9 - export CXX=clang++-9 + sudo apt-get install -y "clang" "lldb" "lld" "clang-format" + export CC=clang + export CXX=clang++ export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0 git fetch --tags cmake -DBUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF ./ - gcc --version - cmake -D BUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=OFF ./ clang --version make - name: Run tests run: ./test/etl_tests - build-clang-9-linux-stl-force-cpp03: - name: Clang-9 Linux - STL - Force C++03 + build-clang-linux-stl-force-cpp03: + name: Clang Linux - STL - Force C++03 runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 @@ -71,9 +69,9 @@ jobs: - name: Build run: | sudo apt-get update - sudo apt-get install -y "clang-9" "lldb-9" "lld-9" "clang-format-9" - export CC=clang-9 - export CXX=clang++-9 + sudo apt-get install -y "clang" "lldb" "lld" "clang-format" + export CC=clang + export CXX=clang++ export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0 git fetch --tags cmake -D BUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03=ON ./ diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 2042fbeba..701719eff 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 @@ -32,7 +32,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 @@ -53,7 +53,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, ubuntu-20.04] + os: [ubuntu-20.04, ubuntu-22.04] steps: - uses: actions/checkout@v2 diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b86b613..1ce02e57d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake) set(MSG_PREFIX "etl |") determine_version_with_git(${GIT_DIR_LOOKUP_POLICY}) if(NOT ETL_VERSION) - determine_version("version.txt") + determine_version_with_file("version.txt") endif() project(etl VERSION ${ETL_VERSION} LANGUAGES CXX) @@ -73,9 +73,9 @@ if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME}) "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake) install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/etl DESTINATION include) -endif() - -if (BUILD_TESTS) - enable_testing() - add_subdirectory(test) + + if (BUILD_TESTS) + enable_testing() + add_subdirectory(test) + endif() endif() diff --git a/arduino/library-arduino.json b/arduino/library-arduino.json index 3a6fb90aa..42bd6fba6 100644 --- a/arduino/library-arduino.json +++ b/arduino/library-arduino.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library - Arduino", - "version": "20.35.0", + "version": "20.35.10", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/arduino/library-arduino.properties b/arduino/library-arduino.properties index 6935809b8..abbd8bb98 100644 --- a/arduino/library-arduino.properties +++ b/arduino/library-arduino.properties @@ -1,5 +1,5 @@ name=Embedded Template Library - Arduino -version=20.35.0 +version=20.35.10 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/cmake/helpers.cmake b/cmake/helpers.cmake index f27189d9e..9249fb4e4 100644 --- a/cmake/helpers.cmake +++ b/cmake/helpers.cmake @@ -1,4 +1,4 @@ -function(determine_version VER_FILE_NAME) +function(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) @@ -13,7 +13,11 @@ function(determine_version_with_git) git_describe(VERSION ${ARGN}) string(FIND ${VERSION} "." VALID_VERSION) if(VALID_VERSION EQUAL -1) - message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") + if(PROJECT_IS_TOP_LEVEL) + # only warn if this is the top-level project, since we may be + # building from a tarball as a subproject + message(WARNING "Version string ${VERSION} retrieved with git describe is invalid") + endif() return() endif() message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}") diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 5f367618d..84ceeeabe 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -40,7 +40,6 @@ SOFTWARE. #include "nullptr.h" #include "hash.h" #include "algorithm.h" -#include "memory.h" #include "type_traits.h" #if ETL_USING_STL && ETL_USING_CPP11 @@ -155,7 +154,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR array_view(etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR array_view(etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : mbegin(a.data()) , mend(a.data() + a.size()) { @@ -165,7 +164,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR array_view(const etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR array_view(const etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : mbegin(a.data()) , mend(a.data() + a.size()) { @@ -215,7 +214,7 @@ namespace etl template ETL_CONSTEXPR array_view(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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : mbegin(a.data()) , mend(a.data() + a.size()) { @@ -228,7 +227,7 @@ namespace etl template ETL_CONSTEXPR array_view(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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : mbegin(a.data()) , mend(a.data() + a.size()) { diff --git a/include/etl/binary.h b/include/etl/binary.h index 658d41bed..5d5a61286 100644 --- a/include/etl/binary.h +++ b/include/etl/binary.h @@ -2198,7 +2198,7 @@ namespace etl return (nbits == etl::integral_limits::bits) ? static_cast(etl::integral_limits::max) : static_cast((static_cast(1U) << nbits) - 1U); - }; + } //*********************************** template @@ -2214,7 +2214,7 @@ namespace etl ETL_CONSTEXPR T make_msb_mask(size_t nbits) { return static_cast(etl::reverse_bits(make_lsb_mask(nbits))); - }; + } //*************************************************************************** /// 8 bit binary byte constants. diff --git a/include/etl/delegate.h b/include/etl/delegate.h index 4220b65f4..d03119279 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -33,7 +33,7 @@ SOFTWARE. #include "platform.h" -#if ETL_USING_CPP11 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION) +#if ETL_USING_CPP11 && !defined(ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION) #include "private/delegate_cpp11.h" #else #include "private/delegate_cpp03.h" diff --git a/include/etl/deque.h b/include/etl/deque.h index 8a514e277..aa075ac74 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -1742,7 +1742,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_back(Args && ... args) + reference emplace_back(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1752,6 +1752,7 @@ namespace etl ++_end; ++current_size; ETL_INCREMENT_DEBUG_COUNT + return back(); } #else @@ -1761,7 +1762,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_back(const T1& value1) + reference emplace_back(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1771,6 +1772,7 @@ namespace etl ++_end; ++current_size; ETL_INCREMENT_DEBUG_COUNT + return back(); } //************************************************************************* @@ -1778,7 +1780,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_back(const T1& value1, const T2& value2) + reference emplace_back(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1788,6 +1790,7 @@ namespace etl ++_end; ++current_size; ETL_INCREMENT_DEBUG_COUNT + return back(); } //************************************************************************* @@ -1795,7 +1798,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1805,6 +1808,7 @@ namespace etl ++_end; ++current_size; ETL_INCREMENT_DEBUG_COUNT + return back(); } //************************************************************************* @@ -1812,7 +1816,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1822,6 +1826,7 @@ namespace etl ++_end; ++current_size; ETL_INCREMENT_DEBUG_COUNT + return back(); } #endif @@ -1870,7 +1875,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_front(Args && ... args) + reference emplace_front(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1880,6 +1885,7 @@ namespace etl ::new (&(*_begin)) T(etl::forward(args)...); ++current_size; ETL_INCREMENT_DEBUG_COUNT + return front(); } #else @@ -1889,7 +1895,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_front(const T1& value1) + reference emplace_front(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1899,6 +1905,7 @@ namespace etl ::new (&(*_begin)) T(value1); ++current_size; ETL_INCREMENT_DEBUG_COUNT + return front(); } //************************************************************************* @@ -1906,7 +1913,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2) + reference emplace_front(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1916,6 +1923,7 @@ namespace etl ::new (&(*_begin)) T(value1, value2); ++current_size; ETL_INCREMENT_DEBUG_COUNT + return front(); } //************************************************************************* @@ -1923,7 +1931,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1933,6 +1941,7 @@ namespace etl ::new (&(*_begin)) T(value1, value2, value3); ++current_size; ETL_INCREMENT_DEBUG_COUNT + return front(); } //************************************************************************* @@ -1940,7 +1949,7 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::deque_full if the deque is already full. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1950,6 +1959,7 @@ namespace etl ::new (&(*_begin)) T(value1, value2, value3, value4); ++current_size; ETL_INCREMENT_DEBUG_COUNT + return front(); } #endif diff --git a/include/etl/expected.h b/include/etl/expected.h index 9ca6d03fb..0baf4a882 100644 --- a/include/etl/expected.h +++ b/include/etl/expected.h @@ -34,9 +34,53 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" #include "utility.h" +#include "variant.h" namespace etl { + //*************************************************************************** + /// Base exception for et::expected + //*************************************************************************** + class expected_exception : public etl::exception + { + public: + + expected_exception(string_type reason_, string_type file_name_, numeric_type line_number_) + : exception(reason_, file_name_, line_number_) + { + } + }; + + //*************************************************************************** + /// expected_invalid + //*************************************************************************** + template + class expected_invalid; + + //******************************************* + template<> + class expected_invalid : public etl::expected_exception + { + public: + + expected_invalid(string_type file_name_, numeric_type line_number_) + : expected_exception(ETL_ERROR_TEXT("expected:invalid", ETL_EXPECTED_FILE_ID"A"), file_name_, line_number_) + { + } + }; + + //******************************************* + template + class expected_invalid : etl::expected_invalid + { + public: + + expected_invalid(string_type file_name_, numeric_type line_number_) + : expected_invalid(file_name_, line_number_) + { + } + }; + //*************************************************************************** /// Unexpected type. /// etl::unexpected represents an unexpected value stored in etl::expected. @@ -46,6 +90,8 @@ namespace etl { public: + typedef TError error_type; + //******************************************* /// Copy constructor. //******************************************* @@ -114,8 +160,9 @@ namespace etl ETL_CONSTEXPR14 etl::unexpected& operator =(const etl::unexpected& rhs) { - error_value = rhs.error_value; + ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Error not copy assignable"); + error_value = rhs.error_value; return *this; } @@ -126,8 +173,9 @@ namespace etl ETL_CONSTEXPR14 etl::unexpected& operator =(etl::unexpected&& rhs) { - error_value = etl::move(rhs.error_value); + ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Error not move assignable"); + error_value = etl::move(rhs.error_value); return *this; } #endif @@ -136,7 +184,7 @@ namespace etl //******************************************* /// Get the error. //******************************************* - constexpr const TError& error() const& noexcept + constexpr TError& error() & noexcept { return error_value; } @@ -144,16 +192,7 @@ namespace etl //******************************************* /// Get the error. //******************************************* - constexpr const TError&& error() const&& noexcept - { - return etl::move(error_value); - } - -#if ETL_USING_CPP14 - //******************************************* - /// Get the error. - //******************************************* - constexpr TError& error() & noexcept + constexpr const TError& error() const& noexcept { return error_value; } @@ -165,24 +204,14 @@ namespace etl { return etl::move(error_value); } -#else - //******************************************* - /// Get the error. - //******************************************* - TError& error() & noexcept - { - return error_value; - } //******************************************* /// Get the error. //******************************************* - TError&& error() && noexcept + constexpr TError&& error() const && noexcept { return etl::move(error_value); } -#endif - #else //******************************************* /// Get the error. @@ -210,8 +239,604 @@ namespace etl #if ETL_USING_CPP17 template - unexpected(TError) -> unexpected; + bool operator ==(const etl::unexpected& lhs, const etl::unexpected& rhs) + { + return lhs.error_value == rhs.error_value; + } + + //******************************************* + /// Swap etl::unexpected. + //******************************************* + template + void swap(etl::unexpected& lhs, etl::unexpected& rhs) + { + lhs.swap(rhs); + } + + //***************************************************************************** + /// unexpect_t + //***************************************************************************** + struct unexpect_t + { + ETL_CONSTEXPR14 explicit unexpect_t() + { + } + }; +#endif + +#if ETL_USING_CPP17 + inline constexpr unexpect_t unexpect{}; +#else + static const unexpect_t unexpect; #endif + + //***************************************************************************** + /// Expected type. + //***************************************************************************** + template + class expected + { + public: + + typedef etl::expected this_type; + typedef TValue value_type; + typedef TError error_type; + typedef etl::unexpected unexpected_type; + + template + using rebind = expected; + + //******************************************* + /// Default constructor + //******************************************* + ETL_CONSTEXPR14 expected() ETL_NOEXCEPT + : storage(etl::in_place_index, value_type()) + { + } + + //******************************************* + /// Constructor + //******************************************* + ETL_CONSTEXPR14 expected(const value_type& value_) ETL_NOEXCEPT + : storage(etl::in_place_index, value_) + { + } + + //******************************************* + /// Constructor + //******************************************* + ETL_CONSTEXPR14 expected(value_type&& value_) ETL_NOEXCEPT + : storage(etl::in_place_index, etl::move(value_)) + { + } + + //******************************************* + /// Copy constructor + //******************************************* + ETL_CONSTEXPR14 expected(const expected& other) ETL_NOEXCEPT + : storage(other.storage) + { + } + + //******************************************* + /// Move constructor + //******************************************* + ETL_CONSTEXPR14 expected(expected&& other) ETL_NOEXCEPT + : storage(etl::move(other.storage)) + { + } + + //******************************************* + /// Copy construct from unexpected type. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(const etl::unexpected& ue) + : storage(etl::in_place_index, ue.error()) + { + } + + //******************************************* + /// Move construct from unexpected type. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(etl::unexpected&& ue) + : storage(etl::in_place_index, etl::move(ue.error())) + { + } + + //******************************************* + /// Construct with default value type. + //******************************************* + ETL_CONSTEXPR14 explicit expected(etl::in_place_t) ETL_NOEXCEPT + : storage(value_type()) + { + } + + //******************************************* + /// Construct value type from arguments. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(etl::in_place_t, Args&&... args) + : storage(etl::forward(args)...) + { + } + + //******************************************* + /// Construct value type from initializser_list and arguments. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(etl::in_place_t, std::initializer_list il, Args&&... args) + : storage(il, etl::forward(args)...) + { + } + + //******************************************* + /// Construct error type from arguments. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, Args&&... args) + : storage(error_type(etl::forward(args)...)) + { + } + + //******************************************* + /// Construct error type from initializser_list and arguments. + //******************************************* + template + ETL_CONSTEXPR14 explicit expected(etl::unexpect_t, std::initializer_list il, Args&&... args) + : storage(error_type(il, etl::forward(args)...)) + { + } + + //******************************************* + /// + //******************************************* + this_type& operator =(const this_type& other) + { + ETL_STATIC_ASSERT(etl::is_copy_constructible::value && etl::is_copy_constructible::value, "Not copy assignable"); + + storage = other.storage; + + return *this; + } + + //******************************************* + /// + //******************************************* + this_type& operator =(this_type&& other) + { + ETL_STATIC_ASSERT(etl::is_move_constructible::value && etl::is_move_constructible::value, "Not move assignable"); + + storage = etl::move(other.storage); + return *this; + } + + //******************************************* + /// Copy assign from value + //******************************************* + expected& operator =(const value_type& value) + { + ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Value not copy assignable"); + + storage.emplace(value); + return *this; + } + + //******************************************* + /// Move assign from value + //******************************************* + expected& operator =(value_type&& value) + { + ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Value not move assignable"); + + storage.emplace(etl::move(value)); + return *this; + } + + //******************************************* + /// Copy assign from error + //******************************************* + expected& operator =(const unexpected_type& error) + { + ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Error not copy assignable"); + + storage.emplace(error); + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + expected& operator =(unexpected_type&& error) + { + ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Error not move assignable"); + + storage.emplace(etl::move(error)); + return *this; + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 value_type& value()& + { + return etl::get(storage); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 const value_type& value() const& + { + return etl::get(storage); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 value_type&& value()&& + { + return etl::move(etl::get(storage)); + } + + //******************************************* + /// + //******************************************* + ETL_CONSTEXPR14 const value_type&& value() const&& + { + return etl::move(etl::get(storage)); + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + bool has_value() const + { + return (storage.index() == Value_Type); + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + operator bool() const + { + return has_value(); + } + + //******************************************* + /// + //******************************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + value_type value_or(U&& default_value) const& + { + if (has_value()) + { + return value(); + } + else + { + return default_value; + } + } + + //******************************************* + /// + //******************************************* + template + ETL_NODISCARD + ETL_CONSTEXPR14 + value_type value_or(U&& default_value)&& + { + if (has_value()) + { + return etl::move(value()); + } + else + { + return etl::move(default_value); + } + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + error_type& error()& ETL_NOEXCEPT + { + return etl::get(storage); + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const error_type& error() const& ETL_NOEXCEPT + { + return etl::get(storage); + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + error_type&& error() && ETL_NOEXCEPT + { + return etl::move(etl::get(storage)); + } + + //******************************************* + /// + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const error_type&& error() const&& ETL_NOEXCEPT + { + return etl::move(etl::get(storage)); + } + + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 value_type& emplace(Args&&... args) ETL_NOEXCEPT + { + storage.emplace(args...); + } + + //******************************************* + /// + //******************************************* + template + ETL_CONSTEXPR14 value_type& emplace(std::initializer_list& il, Args&&... args) ETL_NOEXCEPT + { + storage.emplace(il, args...); + } + + //******************************************* + /// + //******************************************* + value_type* operator ->() + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return etl::addressof(storage.get()); + } + + //******************************************* + /// + //******************************************* + const value_type* operator ->() const + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return etl::addressof(storage.get()); + } + + //******************************************* + /// + //******************************************* + value_type& operator *() + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return storage.get(); + } + + //******************************************* + /// + //******************************************* + const value_type& operator *() const + { +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(valid, ETL_ERROR(expected_invalid)); +#endif + + return storage.get(); + } + + private: + + enum + { + Uninitialised, + Value_Type, + Error_Type + }; + + using storage_type = etl::variant; + storage_type storage; + }; + + //***************************************************************************** + /// Specialisation for void value type. + //***************************************************************************** + template + class expected + { + public: + + typedef etl::expected this_type; + typedef void value_type; + typedef TError error_type; + typedef etl::unexpected unexpected_type; + + //******************************************* + /// Default constructor + //******************************************* + ETL_CONSTEXPR14 + expected() + { + } + + //******************************************* + /// Copy construct from unexpected + //******************************************* + ETL_CONSTEXPR14 + expected(const unexpected_type& ue_) + : storage(ue_.error()) + { + } + + //******************************************* + /// Move construct from unexpected + //******************************************* + ETL_CONSTEXPR14 + expected(unexpected_type&& ue_) + : storage(etl::move(ue_.error())) + { + } + + //******************************************* + /// Copy construct + //******************************************* + ETL_CONSTEXPR14 + expected(const this_type& other) + : storage(other.storage) + { + } + + //******************************************* + /// Move construct + //******************************************* + ETL_CONSTEXPR14 + expected(this_type&& other) + : storage(etl::move(other.storage)) + { + } + + //******************************************* + /// Copy assign + //******************************************* + this_type& operator =(const this_type& other) + { + ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Not copy assignable"); + + storage = other.storage; + return *this; + } + + //******************************************* + /// Move assign + //******************************************* + this_type& operator =(this_type&& other) + { + ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Not move assignable"); + + storage = etl::move(other.storage); + return *this; + } + + //******************************************* + /// Copy assign from error + //******************************************* + expected& operator =(const unexpected_type& error) + { + ETL_STATIC_ASSERT(etl::is_copy_constructible::value, "Error not copy assignable"); + + storage.emplace(error); + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + expected& operator =(unexpected_type&& error) + { + ETL_STATIC_ASSERT(etl::is_move_constructible::value, "Error not move assignable"); + + storage.emplace(etl::move(error)); + return *this; + } + + //******************************************* + /// Returns true if expected has a value + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + bool has_value() const + { + return (storage.index() != Error_Type); + } + + //******************************************* + /// Returns true if expected has a value + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + operator bool() const + { + return has_value(); + } + + //******************************************* + /// Returns the error + /// Undefined behaviour if an error has not been set. + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + error_type& error()& ETL_NOEXCEPT + { + return etl::get(storage); + } + + //******************************************* + /// Returns the error + /// Undefined behaviour if an error has not been set. + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const error_type& error() const& ETL_NOEXCEPT + { + return etl::get(storage); + } + + //******************************************* + /// Returns the error + /// Undefined behaviour if an error has not been set. + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + error_type&& error() && ETL_NOEXCEPT + { + return etl::move(etl::get(storage)); + } + + //******************************************* + /// Returns the error + /// Undefined behaviour if an error has not been set. + //******************************************* + ETL_NODISCARD + ETL_CONSTEXPR14 + const error_type&& error() const&& ETL_NOEXCEPT + { + return etl::move(etl::get(storage)); + } + + private: + + enum + { + Uninitialised, + Error_Type + }; + + etl::variant storage; + }; } //******************************************* @@ -234,20 +859,4 @@ void swap(etl::unexpected& lhs, etl::unexpected& rhs) lhs.swap(rhs); } -//***************************************************************************** -/// unexpect_t -//***************************************************************************** -struct unexpect_t -{ - ETL_CONSTEXPR14 explicit unexpect_t() - { - } -}; - -#if ETL_CPP17_SUPPORTED -inline constexpr unexpect_t unexpect{}; -#else -static const unexpect_t unexpect; -#endif - #endif diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 68337fc52..8d1ac9d53 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -722,7 +722,7 @@ namespace etl /// Emplaces a value to the front of the list.. //************************************************************************* template - void emplace_front(Args && ... args) + reference emplace_front(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -731,13 +731,14 @@ namespace etl ::new (&(p_data_node->value)) T(etl::forward(args)...); ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); + return front(); } #else //************************************************************************* /// Emplaces a value to the front of the list.. //************************************************************************* template - void emplace_front(const T1& value1) + reference emplace_front(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -746,13 +747,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1); ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list.. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2) + reference emplace_front(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -761,13 +763,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2); ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list.. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -776,13 +779,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3); ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list.. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -791,6 +795,7 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3, value4); ETL_INCREMENT_DEBUG_COUNT insert_node_after(start_node, *p_data_node); + return front(); } #endif // ETL_USING_CPP11 && ETL_NOT_USING_STLPORT @@ -1756,7 +1761,7 @@ namespace etl //************************************************************************* #if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST template - constexpr auto make_forward_list(T... t) -> etl::forward_list, sizeof...(T)> + constexpr auto make_forward_list(T&&... t) -> etl::forward_list, sizeof...(T)> { return { { etl::forward(t)... } }; } diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index b7e16d8d7..491ca081d 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -714,7 +714,7 @@ namespace etl //*************************************************************************** /// is_enum ///\ingroup type_traits - /// Implemented by checking if type is convertable to an integer thru static_cast + /// Implemented by checking if type is convertible to an integer through static_cast namespace private_type_traits { @@ -1988,13 +1988,40 @@ namespace etl }; #if ETL_USING_CPP11 - //********************************************* - // is_constructible - template - struct is_constructible : public etl::bool_constant::value || etl::is_pointer::value> + //*************************************************************************** + /// is_constructible + namespace private_type_traits { + template + struct is_constructible_ : etl::false_type {}; + + template + struct is_constructible_()...))>, T, Args...> : etl::true_type {}; }; -#endif + + + //********************************************* + // is_constructible + template + using is_constructible = private_type_traits::is_constructible_, T, Args...>; + + //********************************************* + // is_copy_constructible + template struct is_copy_constructible : public is_constructible::type>::type>{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + + //********************************************* + // is_move_constructible + template struct is_move_constructible: public is_constructible::type>{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + +#else //********************************************* // is_copy_constructible @@ -2009,6 +2036,7 @@ namespace etl struct is_move_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif //********************************************* // is_trivially_constructible diff --git a/include/etl/indirect_vector.h b/include/etl/indirect_vector.h index 002cad02e..78e592bf4 100644 --- a/include/etl/indirect_vector.h +++ b/include/etl/indirect_vector.h @@ -782,10 +782,11 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(Args && ... args) + reference emplace_back(Args && ... args) { T* p = storage.create(etl::forward(args)...); lookup.push_back(p); + return back(); } #else //********************************************************************* @@ -794,10 +795,11 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1) + reference emplace_back(const T1& value1) { T* p = storage.create(T(value1)); lookup.push_back(p); + return back(); } //********************************************************************* @@ -806,10 +808,11 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2) + reference emplace_back(const T1& value1, const T2& value2) { T* p = storage.create(T(value1, value2)); lookup.push_back(p); + return back(); } //********************************************************************* @@ -818,10 +821,11 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3) { T* p = storage.create(T(value1, value2, value3)); lookup.push_back(p); + return back(); } //********************************************************************* @@ -830,10 +834,11 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { T* p = storage.create(T(value1, value2, value3, value4)); lookup.push_back(p); + return back(); } #endif @@ -1433,7 +1438,7 @@ namespace etl //************************************************************************* #if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST template - constexpr auto make_indirect_vector(T... t) -> etl::indirect_vector, sizeof...(T)> + constexpr auto make_indirect_vector(T&&... t) -> etl::indirect_vector, sizeof...(T)> { return { { etl::forward(t)... } }; } diff --git a/include/etl/list.h b/include/etl/list.h index 6ba5070a9..c5e786313 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -862,7 +862,7 @@ namespace etl /// Emplaces a value to the front of the list. //************************************************************************* template - void emplace_front(Args && ... args) + reference emplace_front(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -873,13 +873,14 @@ namespace etl ::new (&(p_data_node->value)) T(etl::forward(args)...); ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); + return front(); } #else //************************************************************************* /// Emplaces a value to the front of the list. //************************************************************************* template - void emplace_front(const T1& value1) + reference emplace_front(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -890,13 +891,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1); ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2) + reference emplace_front(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -907,13 +909,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2); ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -924,13 +927,14 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3); ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); + return front(); } //************************************************************************* /// Emplaces a value to the front of the list. //************************************************************************* template - void emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_front(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -941,6 +945,7 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3, value4); ETL_INCREMENT_DEBUG_COUNT insert_node(get_head(), *p_data_node); + return front(); } #endif @@ -985,7 +990,7 @@ namespace etl //************************************************************************* #if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT template - void emplace_back(Args && ... args) + reference emplace_back(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -996,10 +1001,11 @@ namespace etl ::new (&(p_data_node->value)) T(etl::forward(args)...); ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); + return back(); } #else template - void emplace_back(const T1& value1) + reference emplace_back(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -1010,10 +1016,11 @@ namespace etl ::new (&(p_data_node->value)) T(value1); ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); + return back(); } template - void emplace_back(const T1& value1, const T2& value2) + reference emplace_back(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -1024,10 +1031,11 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2); ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); + return back(); } template - void emplace_back(const T1& value1, const T2& value2, const T3& value3) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -1038,10 +1046,11 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3); ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); + return back(); } template - void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(list_full)); @@ -1052,6 +1061,7 @@ namespace etl ::new (&(p_data_node->value)) T(value1, value2, value3, value4); ETL_INCREMENT_DEBUG_COUNT insert_node(terminal_node, *p_data_node); + return back(); } #endif diff --git a/include/etl/memory.h b/include/etl/memory.h index ec6db9a41..0725d2e68 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -39,6 +39,7 @@ SOFTWARE. #include "nullptr.h" #include "alignment.h" #include "placement_new.h" + #include "private/addressof.h" #include @@ -1231,7 +1232,19 @@ namespace etl template struct default_delete { - void operator()(T* p) const + //********************************* + ETL_CONSTEXPR default_delete() ETL_NOEXCEPT + { + } + + //********************************* + template + default_delete(const default_delete&) ETL_NOEXCEPT + { + } + + //********************************* + void operator()(T * p) const ETL_NOEXCEPT { delete p; } @@ -1246,6 +1259,18 @@ namespace etl template struct default_delete { + //********************************* + ETL_CONSTEXPR default_delete() ETL_NOEXCEPT + { + } + + //********************************* + template + default_delete(const default_delete&) ETL_NOEXCEPT + { + } + + //********************************* template void operator()(U* p) const { @@ -1282,10 +1307,23 @@ namespace etl #if ETL_USING_CPP11 //********************************* - unique_ptr(unique_ptr&& p_) ETL_NOEXCEPT - : p(p_.release()) - , deleter(etl::move(p_.deleter)) + unique_ptr(unique_ptr&& other) ETL_NOEXCEPT { + if (&other != this) + { + p = other.release(); + deleter = etl::move(other.deleter); + } + } +#else + //********************************* + unique_ptr(unique_ptr& other) ETL_NOEXCEPT + { + if (&other != this) + { + p = other.release(); + deleter = other.deleter; + } } #endif @@ -1305,6 +1343,13 @@ namespace etl , deleter(etl::move(deleter_)) { } + + template + unique_ptr(unique_ptr&& u) ETL_NOEXCEPT + : p(u.release()) + , deleter(etl::forward(u.get_deleter())) + { + } #endif //********************************* @@ -1387,9 +1432,25 @@ namespace etl #if ETL_USING_CPP11 //********************************* - unique_ptr& operator =(unique_ptr&& p_) ETL_NOEXCEPT + unique_ptr& operator =(unique_ptr&& other) ETL_NOEXCEPT + { + if (&other != this) + { + reset(other.release()); + deleter = etl::move(other.deleter); + } + + return *this; + } +#else + //********************************* + unique_ptr& operator =(unique_ptr& other) ETL_NOEXCEPT { - reset(p_.release()); + if (&other != this) + { + reset(other.release()); + deleter = other.deleter; + } return *this; } @@ -1439,7 +1500,7 @@ namespace etl typedef T& reference; //********************************* - ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT + ETL_CONSTEXPR unique_ptr() ETL_NOEXCEPT : p(ETL_NULLPTR) { } @@ -1452,17 +1513,31 @@ namespace etl #if ETL_USING_CPP11 //********************************* - unique_ptr(unique_ptr&& p_) ETL_NOEXCEPT - : p(p_.release()) - , deleter(etl::move(p_.deleter)) + unique_ptr(unique_ptr&& other) ETL_NOEXCEPT { + if (&other != this) + { + p = other.release(); + deleter = etl::move(other.deleter); + } + } +#else + //********************************* + unique_ptr(unique_ptr& other) ETL_NOEXCEPT + { + if (&other != this) + { + p = other.release(); + deleter = other.deleter; + } } #endif //********************************* - unique_ptr(pointer p_, typename etl::conditional::value, - TDeleter, - typename etl::add_lvalue_reference::type>::type deleter_) ETL_NOEXCEPT + unique_ptr(pointer p_, + typename etl::conditional::value, + TDeleter, + typename etl::add_lvalue_reference::type>::type deleter_) ETL_NOEXCEPT : p(p_) , deleter(deleter_) { @@ -1475,6 +1550,13 @@ namespace etl , deleter(etl::move(deleter_)) { } + + template + unique_ptr(unique_ptr&& u) ETL_NOEXCEPT + : p(u.release()) + , deleter(etl::forward(u.get_deleter())) + { + } #endif //********************************* @@ -1556,9 +1638,25 @@ namespace etl #if ETL_USING_CPP11 //********************************* - unique_ptr& operator =(unique_ptr&& p_) ETL_NOEXCEPT + unique_ptr& operator =(unique_ptr&& other) ETL_NOEXCEPT { - reset(p_.release()); + if (&other != this) + { + reset(other.release()); + deleter = etl::move(other.deleter); + } + + return *this; + } +#else + //********************************* + unique_ptr& operator =(unique_ptr& other) ETL_NOEXCEPT + { + if (&other != this) + { + reset(other.release()); + deleter = other.deleter; + } return *this; } diff --git a/include/etl/optional.h b/include/etl/optional.h index 8de5197a1..ebcb52a1e 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -427,7 +427,7 @@ namespace etl ///\param args The arguments to construct with. //************************************************************************* template - void emplace(Args && ... args) + T& emplace(Args && ... args) { if (valid) { @@ -437,6 +437,7 @@ namespace etl ::new (storage.template get_address()) T(ETL_OR_STD::forward(args)...); valid = true; + return storage; } #else //************************************************************************* @@ -444,7 +445,7 @@ namespace etl /// 1 parameter. //************************************************************************* template - void emplace(const T1& value1) + T& emplace(const T1& value1) { if (valid) { @@ -454,6 +455,7 @@ namespace etl ::new (storage.template get_address()) T(value1); valid = true; + return storage; } //************************************************************************* @@ -461,7 +463,7 @@ namespace etl /// 2 parameters. //************************************************************************* template - void emplace(const T1& value1, const T2& value2) + T& emplace(const T1& value1, const T2& value2) { if (valid) { @@ -471,6 +473,7 @@ namespace etl ::new (storage.template get_address()) T(value1, value2); valid = true; + return storage; } //************************************************************************* @@ -478,7 +481,7 @@ namespace etl /// 3 parameters. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3) + T& emplace(const T1& value1, const T2& value2, const T3& value3) { if (valid) { @@ -488,6 +491,7 @@ namespace etl ::new (storage.template get_address()) T(value1, value2, value3); valid = true; + return storage; } //************************************************************************* @@ -495,7 +499,7 @@ namespace etl /// 4 parameters. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + T& emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { if (valid) { @@ -505,6 +509,7 @@ namespace etl ::new (storage.template get_address()) T(value1, value2, value3, value4); valid = true; + return storage; } #endif @@ -613,7 +618,7 @@ namespace etl if (this != &other) { storage = etl::move(other.storage); - valid = true; + valid = other.valid; } return *this; @@ -766,12 +771,6 @@ namespace etl template ETL_CONSTEXPR14 void emplace(Args && ... args) { - if (valid) - { - // Destroy the old one. - storage.template get_reference().~T(); - } - storage = T(ETL_OR_STD::forward(args)...); valid = true; } diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 8afb09c9a..1116d8007 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -174,11 +174,13 @@ namespace etl template class delegate; - - template class delegate : public private_delegate::call_if_impl, TReturn, TParam> { + private: + + typedef delegate delegate_type; + public: using private_delegate::call_if_impl, TReturn, TParam>::call_if; @@ -202,11 +204,20 @@ namespace etl // Construct from a functor. //************************************************************************* template - delegate(const TFunctor& instance) + delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + // Construct from a const functor. + //************************************************************************* + template + delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -221,12 +232,23 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value, delegate>::type - create(const TFunctor& instance) + typename etl::enable_if::value &&!etl::is_same::value, delegate>::type + create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); } + //************************************************************************* + /// Create from a const Functor. + //************************************************************************* + template + static + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(const TFunctor& instance) + { + return delegate((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -273,15 +295,25 @@ namespace etl } //************************************************************************* - /// Set from Lambda or Functor. + /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value, void>::type - set(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(TFunctor& instance) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + /// Set from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -384,16 +416,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value, delegate&>::type - operator =(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); return *this; } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + return *this; + } + //************************************************************************* /// Checks equality. //************************************************************************* @@ -549,7 +592,7 @@ namespace etl } //************************************************************************* - /// Stub call for a lambda or functor function. + /// Stub call for a functor function. //************************************************************************* template static TReturn functor_stub(void* object, TParam param) @@ -558,6 +601,16 @@ namespace etl return (p->operator())(param); } + //************************************************************************* + /// Stub call for a functor function. + //************************************************************************* + template + static TReturn const_functor_stub(void* object, TParam param) + { + const TFunctor* p = static_cast(object); + return (p->operator())(param); + } + //************************************************************************* /// The invocation object. //************************************************************************* @@ -568,9 +621,12 @@ namespace etl /// Specialisation for void parameter. //************************************************************************* template - class delegate - : public private_delegate::call_if_impl, TReturn, void> + class delegate : public private_delegate::call_if_impl, TReturn, void> { + private: + + typedef delegate delegate_type; + public: using private_delegate::call_if_impl< delegate, TReturn, void>::call_if; @@ -591,14 +647,23 @@ namespace etl } //************************************************************************* - // Construct from lambda or functor. + // Construct from functor. //************************************************************************* template - delegate(const TFunctor& instance) + delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + // Construct from const functor. + //************************************************************************* + template + delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -609,16 +674,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template static - typename etl::enable_if::value, delegate>::type - create(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + static + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(const TFunctor& instance) + { + return delegate((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -665,15 +741,25 @@ namespace etl } //************************************************************************* - /// Set from Lambda or Functor. + /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value, void>::type - set(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(TFunctor& instance) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + /// Set from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -776,16 +862,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value, delegate&>::type - operator =(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); return *this; } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + return *this; + } + //************************************************************************* /// Checks equality. //************************************************************************* @@ -941,7 +1038,7 @@ namespace etl } //************************************************************************* - /// Stub call for a lambda or functor function. + /// Stub call for a functor function. //************************************************************************* template static TReturn functor_stub(void* object) @@ -950,6 +1047,16 @@ namespace etl return (p->operator())(); } + //************************************************************************* + /// Stub call for a const functor function. + //************************************************************************* + template + static TReturn const_functor_stub(void* object) + { + const TFunctor* p = static_cast(object); + return (p->operator())(); + } + //************************************************************************* /// The invocation object. //************************************************************************* diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 0b2102f16..e85cd8953 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -111,12 +111,21 @@ namespace etl //************************************************************************* // Construct from lambda or functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 delegate(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(TLambda& instance) { assign((void*)(&instance), lambda_stub); } + //************************************************************************* + // Construct from const lambda or functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -130,13 +139,23 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value, void>> + template ::value && !etl::is_same, TLambda>::value, void>> ETL_NODISCARD - static ETL_CONSTEXPR14 delegate create(const TLambda& instance) + static ETL_CONSTEXPR14 delegate create(TLambda& instance) { return delegate((void*)(&instance), lambda_stub); } + //************************************************************************* + /// Create from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_NODISCARD + static ETL_CONSTEXPR14 delegate create(const TLambda& instance) + { + return delegate((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -203,12 +222,21 @@ namespace etl //************************************************************************* /// Set from Lambda or Functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 void set(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 void set(TLambda& instance) { assign((void*)(&instance), lambda_stub); } + //************************************************************************* + /// Set from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 void set(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -347,13 +375,23 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate& operator =(TLambda& instance) { assign((void*)(&instance), lambda_stub); return *this; } + //************************************************************************* + /// Create from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + return *this; + } + //************************************************************************* /// Checks equality. //************************************************************************* @@ -517,6 +555,16 @@ namespace etl return (p->operator())(etl::forward(arg)...); } + //************************************************************************* + /// Stub call for a const lambda or functor function. + //************************************************************************* + template + static ETL_CONSTEXPR14 TReturn const_lambda_stub(void* object, TParams... arg) + { + const TLambda* p = static_cast(object); + return (p->operator())(etl::forward(arg)...); + } + //************************************************************************* /// The invocation object. //************************************************************************* diff --git a/include/etl/private/ivectorpointer.h b/include/etl/private/ivectorpointer.h index c2cffa7ff..ac1e07466 100644 --- a/include/etl/private/ivectorpointer.h +++ b/include/etl/private/ivectorpointer.h @@ -354,9 +354,11 @@ namespace etl /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. ///\param value The value to add. //********************************************************************* - void emplace_back(parameter_t value) + reference emplace_back(parameter_t value) { base_t::emplace_back(value); + + return back(); } //************************************************************************* diff --git a/include/etl/private/minmax_pop.h b/include/etl/private/minmax_pop.h index ea66ebbb4..018673e3f 100644 --- a/include/etl/private/minmax_pop.h +++ b/include/etl/private/minmax_pop.h @@ -32,7 +32,7 @@ SOFTWARE. * The header include guard has been intentionally omitted. * This file is intended to evaluated multiple times by design. */ -#if !defined(ETL_COMPILER_GREEN_HILLS) && !defined(ETL_COMPILER_IAR) +#if !defined(ETL_COMPILER_GREEN_HILLS) && !defined(ETL_COMPILER_IAR) && !defined(ETL_COMPILER_TASKING) #if !defined(ETL_COMPILER_ARM5) #pragma pop_macro("min") #pragma pop_macro("max") diff --git a/include/etl/private/minmax_push.h b/include/etl/private/minmax_push.h index 1e41bd6d4..03aafcee1 100644 --- a/include/etl/private/minmax_push.h +++ b/include/etl/private/minmax_push.h @@ -33,7 +33,7 @@ SOFTWARE. * This file is intended to evaluated multiple times by design. */ -#if !defined(ETL_COMPILER_GREEN_HILLS) && !defined(ETL_COMPILER_IAR) +#if !defined(ETL_COMPILER_GREEN_HILLS) && !defined(ETL_COMPILER_IAR) && !defined(ETL_COMPILER_TASKING) #if !defined(ETL_COMPILER_ARM5) #pragma push_macro("min") #pragma push_macro("max") diff --git a/include/etl/private/variant_legacy.h b/include/etl/private/variant_legacy.h index 9302a782d..09c1897b9 100644 --- a/include/etl/private/variant_legacy.h +++ b/include/etl/private/variant_legacy.h @@ -954,22 +954,22 @@ namespace etl return get::type>(variant); } -#define ETL_GEN_LEGACY_VISIT(VISITQUAL, VARIANTQUAL) \ - template \ - static TReturn visit(TVisitor VISITQUAL visitor, TVariant VARIANTQUAL variant) \ - { \ - switch (variant.index()) \ - { \ - case 0: return static_cast(visitor(get<0>(variant))); \ - case 1: return static_cast(visitor(get<1>(variant))); \ - case 2: return static_cast(visitor(get<2>(variant))); \ - case 3: return static_cast(visitor(get<3>(variant))); \ - case 4: return static_cast(visitor(get<4>(variant))); \ - case 5: return static_cast(visitor(get<5>(variant))); \ - case 6: return static_cast(visitor(get<6>(variant))); \ - case 7: return static_cast(visitor(get<7>(variant))); \ - default: ETL_ASSERT(false, ETL_ERROR(bad_variant_access)); \ - } \ +#define ETL_GEN_LEGACY_VISIT(VISITQUAL, VARIANTQUAL) \ + template \ + static TReturn visit(TVisitor VISITQUAL visitor, TVariant VARIANTQUAL variant) \ + { \ + switch (variant.index()) \ + { \ + case 0: return static_cast(visitor(get<0>(variant))); \ + case 1: return static_cast(visitor(get<1>(variant))); \ + case 2: return static_cast(visitor(get<2>(variant))); \ + case 3: return static_cast(visitor(get<3>(variant))); \ + case 4: return static_cast(visitor(get<4>(variant))); \ + case 5: return static_cast(visitor(get<5>(variant))); \ + case 6: return static_cast(visitor(get<6>(variant))); \ + case 7: return static_cast(visitor(get<7>(variant))); \ + default: ETL_ASSERT_FAIL_AND_RETURN_VALUE(ETL_ERROR(bad_variant_access), TReturn()); \ + } \ } ETL_GEN_LEGACY_VISIT(&, &) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index b69017a23..3630596d1 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -227,7 +227,7 @@ namespace etl default: { // This should never occur. - #if defined(ETL_IN_UNIT_TEST) + #if defined(ETL_DEBUG) assert(false); #endif break; @@ -701,6 +701,27 @@ namespace etl return *static_cast(data); } + //*************************************************************************** + /// Emplace with variadic constructor parameters. + //*************************************************************************** + template + etl::variant_alternative& emplace(TArgs&&... args) + { + static_assert(Index < etl::private_variant::parameter_pack::size, "Index of of range"); + + using type = etl::remove_cvref_t; + + operation(private_variant::Destroy, data, nullptr); + + construct_in_place_args(data, etl::forward(args)...); + + operation = operation_type::value, etl::is_move_constructible::value>::do_operation; + + type_id = Index; + + return etl::variant_alternative(*static_cast(data)); + } + //*************************************************************************** /// Move assignment operator for type. ///\param value The value to assign. diff --git a/include/etl/profiles/determine_compiler.h b/include/etl/profiles/determine_compiler.h index feb11de88..b9e919273 100644 --- a/include/etl/profiles/determine_compiler.h +++ b/include/etl/profiles/determine_compiler.h @@ -119,6 +119,13 @@ SOFTWARE. #endif #endif + #if !defined(ETL_COMPILER_TYPE_DETECTED) && !defined(ETL_COMPILER_TASKING) + #if defined(__TASKING__) + #define ETL_COMPILER_TASKING + #define ETL_COMPILER_TYPE_DETECTED + #endif + #endif + #if !defined(ETL_COMPILER_TYPE_DETECTED) #define ETL_COMPILER_GENERIC #endif @@ -187,6 +194,12 @@ SOFTWARE. #define ETL_USING_TEXAS_INSTRUMENTS_COMPILER 0 #endif +#if defined(ETL_COMPILER_TASKING) + #define ETL_USING_TASKING_COMPILER 1 +#else + #define ETL_USING_TASKING_COMPILER 0 +#endif + #if defined(ETL_COMPILER_GENERIC) #define ETL_USING_GENERIC_COMPILER 1 #else diff --git a/include/etl/profiles/determine_compiler_version.h b/include/etl/profiles/determine_compiler_version.h index 6835a75e3..6705c0581 100644 --- a/include/etl/profiles/determine_compiler_version.h +++ b/include/etl/profiles/determine_compiler_version.h @@ -64,6 +64,9 @@ SOFTWARE. #elif defined(ETL_COMPILER_TEXAS_INSTRUMENTS) #define ETL_COMPILER_VERSION __TI_COMPILER_VERSION__ #define ETL_COMPILER_FULL_VERSION __TI_COMPILER_VERSION__ + #elif defined(ETL_COMPILER_TASKING) + #define ETL_COMPILER_VERSION __REVISION__ + #define ETL_COMPILER_FULL_VERSION __VERSION__ #else #define ETL_COMPILER_VERSION 0 #define ETL_COMPILER_FULL_VERSION 0 diff --git a/include/etl/result.h b/include/etl/result.h index 33653c664..e01b6ee2f 100644 --- a/include/etl/result.h +++ b/include/etl/result.h @@ -36,6 +36,7 @@ SOFTWARE. #include "platform.h" #include "variant.h" +#include "optional.h" #if ETL_CPP11_NOT_SUPPORTED #if !defined(ETL_IN_UNIT_TEST) @@ -53,6 +54,9 @@ namespace etl { public: + typedef TValue value_type; + typedef TError error_type; + //******************************************* /// Cannot be default constructed //******************************************* @@ -181,7 +185,7 @@ namespace etl //******************************************* bool is_value() const { - return (data.index() == 0U); + return has_value(); } //******************************************* @@ -189,7 +193,7 @@ namespace etl //******************************************* bool is_error() const { - return (data.index() == 1U); + return !has_value(); } //******************************************* @@ -207,7 +211,7 @@ namespace etl //******************************************* TValue&& value() { - return etl::move(etl::get(etl::move(data))); + return etl::move(etl::get(data)); } //******************************************* @@ -226,7 +230,7 @@ namespace etl #if ETL_CPP11_SUPPORTED TError&& error() { - return etl::move(etl::get(etl::move(data))); + return etl::move(etl::get(data)); } #endif @@ -244,11 +248,13 @@ namespace etl { public: + typedef void value_type; + typedef TError error_type; + //******************************************* /// Default Constructor //******************************************* result() - : err(TError()) { } @@ -256,7 +262,7 @@ namespace etl /// Copy constructor //******************************************* result(const result& other) - : err(other.err) + : data(other.data) { } @@ -264,15 +270,15 @@ namespace etl /// Move constructor //******************************************* result(result&& other) - : err(etl::move(other.err)) + : data(etl::move(other.data)) { } //******************************************* /// Construct from error //******************************************* - result(const TError& err_) - : err(err_) + result(const TError& error) + : data(error) { } @@ -280,8 +286,8 @@ namespace etl /// Move construct from error //******************************************* #if ETL_CPP11_SUPPORTED - result(TError&& err_) - : err(etl::move(err_)) + result(TError&& error) + : data(etl::move(error)) { } #endif @@ -289,9 +295,9 @@ namespace etl //******************************************* /// Copy assign from error //******************************************* - result& operator =(const TError& err_) + result& operator =(const TError& error) { - err = err_; + data = error; return *this; } @@ -301,17 +307,25 @@ namespace etl #if ETL_CPP11_SUPPORTED result& operator =(TError&& err_) { - err = etl::move(err_); + data = etl::move(error); return *this; } #endif + //******************************************* + /// true if result contains a value + //******************************************* + bool has_value() const + { + return !data.has_value(); + } + //******************************************* /// true if result contains a value //******************************************* bool is_value() const { - return false; + return has_value(); } //******************************************* @@ -319,7 +333,7 @@ namespace etl //******************************************* bool is_error() const { - return true; + return !has_value(); } //******************************************* @@ -328,7 +342,7 @@ namespace etl //******************************************* const TError& error() const { - return err; + return data.value(); } //******************************************* @@ -338,13 +352,126 @@ namespace etl #if ETL_CPP11_SUPPORTED TError&& error() { - return etl::move(err); + return etl::move(data.value()); } #endif private: - TError err; + etl::optional data; + }; + + //***************************************************************************** + /// Result type. + /// Specialisation for void error type. + //***************************************************************************** + template + class result + { + public: + + //******************************************* + /// Default Constructor + //******************************************* + result() + { + } + + //******************************************* + /// Copy constructor + //******************************************* + result(const result& other) + : data(other.data) + { + } + + //******************************************* + /// Move constructor + //******************************************* + result(result&& other) + : data(etl::move(other.data)) + { + } + + //******************************************* + /// Construct from error + //******************************************* + result(const TValue& value) + : data(value) + { + } + + //******************************************* + /// Move construct from error + //******************************************* + result(TValue&& value) + : data(etl::move(value)) + { + } + + //******************************************* + /// Copy assign from error + //******************************************* + result& operator =(const TValue& value) + { + data = value; + return *this; + } + + //******************************************* + /// Move assign from error + //******************************************* + result& operator =(TValue&& value) + { + data = etl::move(value); + return *this; + } + + //******************************************* + /// true if result contains a value + //******************************************* + bool has_value() const + { + return data.has_value(); + } + + //******************************************* + /// true if result contains a value + //******************************************* + bool is_value() const + { + return has_value(); + } + + //******************************************* + /// true if result contains an error + //******************************************* + bool is_error() const + { + return !has_value(); + } + + //******************************************* + /// Returns a const reference to the error. + /// Undefined if the result does not contain an error. + //******************************************* + const TValue& value() const + { + return data.value(); + } + + //******************************************* + /// Returns an rvalue reference to the error. + /// Undefined if the result does not contain an error. + //******************************************* + TValue&& value() + { + return etl::move(data.value()); + } + + private: + + etl::optional data; }; } diff --git a/include/etl/span.h b/include/etl/span.h index 405a12509..32f27106d 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -134,7 +134,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR span(etl::array& a, typename etl::enable_if<(N == Extent) && etl::is_same::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(etl::array& a, typename etl::enable_if<(N == Extent) && etl::is_same::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -143,7 +143,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR span(const etl::array& a, typename etl::enable_if<(N == Extent) && etl::is_same::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::array& a, typename etl::enable_if<(N == Extent) && etl::is_same::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -189,7 +189,7 @@ namespace etl template span(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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -201,7 +201,7 @@ namespace etl 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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) { } @@ -510,7 +510,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR span(etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -520,7 +520,7 @@ namespace etl /// Construct from etl::array. //************************************************************************* template - ETL_CONSTEXPR span(const etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type) ETL_NOEXCEPT + ETL_CONSTEXPR span(const etl::array& a, typename etl::enable_if::type, typename etl::remove_cv::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -570,7 +570,7 @@ namespace etl template ETL_CONSTEXPR span(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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { @@ -583,7 +583,7 @@ namespace etl 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) ETL_NOEXCEPT + etl::is_same::type, typename etl::remove_cv::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT : pbegin(a.data()) , pend(a.data() + a.size()) { diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 3ef8d9793..80f2152ca 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -702,7 +702,7 @@ namespace etl //*************************************************************************** /// is_enum ///\ingroup type_traits - /// Implemented by checking if type is convertable to an integer thru static_cast + /// Implemented by checking if type is convertible to an integer through static_cast namespace private_type_traits { @@ -1981,13 +1981,40 @@ namespace etl }; #if ETL_USING_CPP11 - //********************************************* - // is_constructible - template - struct is_constructible : public etl::bool_constant::value || etl::is_pointer::value> + //*************************************************************************** + /// is_constructible + namespace private_type_traits { + template + struct is_constructible_ : etl::false_type {}; + + template + struct is_constructible_()...))>, T, Args...> : etl::true_type {}; }; -#endif + + + //********************************************* + // is_constructible + template + using is_constructible = private_type_traits::is_constructible_, T, Args...>; + + //********************************************* + // is_copy_constructible + template struct is_copy_constructible : public is_constructible::type>::type>{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + template <> struct is_copy_constructible : public false_type{}; + + //********************************************* + // is_move_constructible + template struct is_move_constructible: public is_constructible::type>{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + template <> struct is_move_constructible : public false_type{}; + +#else //********************************************* // is_copy_constructible @@ -2002,6 +2029,7 @@ namespace etl struct is_move_constructible : public etl::bool_constant::value || etl::is_pointer::value> { }; +#endif //********************************************* // is_trivially_constructible diff --git a/include/etl/vector.h b/include/etl/vector.h index b10c32752..b6ebec277 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -459,7 +459,7 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(Args && ... args) + reference emplace_back(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); @@ -467,6 +467,7 @@ namespace etl ::new (p_end) T(etl::forward(args)...); ++p_end; ETL_INCREMENT_DEBUG_COUNT + return back(); } #else //********************************************************************* @@ -475,7 +476,7 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1) + reference emplace_back(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); @@ -483,6 +484,7 @@ namespace etl ::new (p_end) T(value1); ++p_end; ETL_INCREMENT_DEBUG_COUNT + return back(); } //********************************************************************* @@ -491,7 +493,7 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2) + reference emplace_back(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); @@ -499,6 +501,7 @@ namespace etl ::new (p_end) T(value1, value2); ++p_end; ETL_INCREMENT_DEBUG_COUNT + return back(); } //********************************************************************* @@ -507,7 +510,7 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); @@ -515,6 +518,7 @@ namespace etl ::new (p_end) T(value1, value2, value3); ++p_end; ETL_INCREMENT_DEBUG_COUNT + return back(); } //********************************************************************* @@ -523,7 +527,7 @@ namespace etl ///\param value The value to add. //********************************************************************* template - void emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace_back(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); @@ -531,6 +535,7 @@ namespace etl ::new (p_end) T(value1, value2, value3, value4); ++p_end; ETL_INCREMENT_DEBUG_COUNT + return back(); } #endif @@ -1353,7 +1358,7 @@ namespace etl //************************************************************************* #if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST template - constexpr auto make_vector(T... t) -> etl::vector, sizeof...(T)> + constexpr auto make_vector(T&&... t) -> etl::vector, sizeof...(T)> { return { { etl::forward(t)... } }; } diff --git a/include/etl/version.h b/include/etl/version.h index bf1bf269c..79240a7e6 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -40,7 +40,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 20 #define ETL_VERSION_MINOR 35 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 10 #define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 5f517484b..e2bc28d3f 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "20.35.0", + "version": "20.35.10", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 49b54c126..1ae6a4302 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=20.35.0 +version=20.35.10 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/meson.build b/meson.build index 6bd1c8c10..fc5bad58b 100644 --- a/meson.build +++ b/meson.build @@ -12,10 +12,8 @@ project('etl', ) compile_args = [] -if get_option('use_stl') - compile_args += '-DETL_NO_STL=0' -elif - compile_args += '-DETL_NO_STL=1' +if not get_option('use_stl') + compile_args += '-DETL_NO_STL' endif etl_dep = declare_dependency( diff --git a/scripts/generator_test.py b/scripts/generator_test.py index cad66737a..14986988f 100644 --- a/scripts/generator_test.py +++ b/scripts/generator_test.py @@ -37,6 +37,9 @@ print(f"Generator for {output_name} does not match file contents") all_ok = False -if not all_ok: +if all_ok: + print(f"\nAll generator tests passed\n") + exit(0) +else: + print(f"\nGenerator tests failed\n") exit(1) -exit(0) \ No newline at end of file diff --git a/support/Release notes.txt b/support/Release notes.txt index 96a866f60..8925639bc 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,52 @@ +=============================================================================== +20.35.10 +#659 emplace member functions return reference to emplaced value + +=============================================================================== +20.35.9 +#657 -Wpedantic-failure. Removed superfluous semicolons +#653 CMake - Don't warn on tag missing when subproject +#651 result specialization +#650 Fix result default ctor +Removed Ubuntu 18.04 from Github Actions +Added Ubuntu 22.04 to Github Actions + +=============================================================================== +20.35.8 +#648 Improve is_constructible, is_copy_constructible, is_move_constructible for type traits with default definitions +#645 Avoid 'missing return statement at end of non-void function' in `etl::visit<>()`. +Removed unused ETL_USE_MEM_BUILTINS option + +=============================================================================== +20.35.7 +Updated etl::delgate to handle const functors correctly + +=============================================================================== +20.35.6 +#643 Don't use push_macro and pull_macro with Tasking compiler + +=============================================================================== +20.35.5 +#641 Wrong usage of enable_if for none C++11 compilers + +=============================================================================== +20.35.4 +#639 Only build tests if top level project + +=============================================================================== +20.35.3 +#636 Fix bug in optional emplace for pod type specialisation + +=============================================================================== +20.35.2 +#634 Strange behavior in move assignment of optional + +=============================================================================== +20.35.1 +#628 Fixed set of ETL_NO_STL flag in meson.build +#631 unique_ptr derived copy or move to base does not compile +Removed duplicate include in etl::array_view + =============================================================================== 20.35.0 #596 Helper functions to convert strings to numeric values. etl::to_arithmetic diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5503424c0..cf1df9991 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -102,6 +102,7 @@ add_executable(etl_tests 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 @@ -284,11 +285,6 @@ if (ETL_USE_TYPE_TRAITS_BUILTINS) target_compile_definitions(etl_tests PRIVATE -DETL_USE_TYPE_TRAITS_BUILTINS) endif() -if (ETL_USE_MEM_BUILTINS) - message(STATUS "Compiling for built-in memory functions") - target_compile_definitions(etl_tests PRIVATE -DETL_USE_MEM_BUILTINS) -endif() - if (ETL_USER_DEFINED_TYPE_TRAITS) message(STATUS "Compiling for user defined type traits") target_compile_definitions(etl_tests PRIVATE -DETL_USER_DEFINED_TYPE_TRAITS) @@ -329,3 +325,4 @@ add_test(etl_unit_tests etl_tests) add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose) set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17) + \ No newline at end of file diff --git a/test/UnitTest++/CheckMacros.h b/test/UnitTest++/CheckMacros.h index 23a8dca92..0ee75dfd2 100644 --- a/test/UnitTest++/CheckMacros.h +++ b/test/UnitTest++/CheckMacros.h @@ -97,7 +97,7 @@ }) \ UNITTEST_MULTILINE_MACRO_END -#define UNITTEST_CHECK_FALSE_EQUAL(expected, actual) \ +#define UNITTEST_CHECK_NOT_EQUAL(expected, actual) \ UNITTEST_MULTILINE_MACRO_BEGIN \ UNITTEST_IMPL_TRY \ ({ \ @@ -254,16 +254,16 @@ #define CHECK_EQUAL_HEX UNITTEST_CHECK_EQUAL_HEX #endif - #ifdef CHECK_FALSE_EQUAL - #error CHECK_FALSE_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FALSE_EQUAL instead + #ifdef CHECK_NOT_EQUAL + #error CHECK_NOT_EQUAL already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NOT_EQUAL instead #else - #define CHECK_FALSE_EQUAL UNITTEST_CHECK_FALSE_EQUAL + #define CHECK_NOT_EQUAL UNITTEST_CHECK_NOT_EQUAL #endif - #ifdef CHECK_FALSE_EQUAL_HEX - #error CHECK_FALSE_EQUAL_HEX already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_FALSE_EQUAL_HEX instead + #ifdef CHECK_NOT_EQUAL_HEX + #error CHECK_NOT_EQUAL_HEX already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NOT_EQUAL_HEX instead #else - #define CHECK_FALSE_EQUAL_HEX UNITTEST_CHECK_FALSE_EQUAL_HEX + #define CHECK_NOT_EQUAL_HEX UNITTEST_CHECK_NOT_EQUAL_HEX #endif #ifdef CHECK_CLOSE diff --git a/test/runsanitychecks.sh b/test/runsanitychecks.sh index d7217d0d4..5048f7861 100644 --- a/test/runsanitychecks.sh +++ b/test/runsanitychecks.sh @@ -19,7 +19,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -33,21 +33,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bgcc -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "GCC - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -75,7 +61,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -89,21 +75,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bclang -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "Clang - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -138,7 +110,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -152,7 +124,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -166,21 +138,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bgcc -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "GCC - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -208,7 +166,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -222,7 +180,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -236,21 +194,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bclang -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "Clang - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -285,7 +229,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -299,7 +243,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -313,21 +257,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bgcc -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "GCC - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -355,7 +285,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -369,7 +299,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -383,21 +313,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bclang -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "Clang - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -432,7 +348,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -446,7 +362,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -460,7 +376,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -474,21 +390,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. -cmake --build bgcc -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "GCC - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -g++ --version | head --lines=1 | tee -a ../log.txt -CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=gcc CXX=g++ cmake -E chdir bgcc cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bgcc if [ $? -eq 0 ]; then echo "Passed" @@ -516,7 +418,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -530,7 +432,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" @@ -544,21 +446,7 @@ rm -rdf bgcc rm -rdf bclang cmake -E make_directory bgcc bclang clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -cmake --build bclang -if [ $? -eq 0 ]; then - echo "Passed" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi - -{ echo ""; echo "Clang - No STL - Force Builtins"; } | tee -a ../log.txt -rm -rdf bgcc -rm -rdf bclang -cmake -E make_directory bgcc bclang -clang++ --version | head --lines=1 | tee -a ../log.txt -CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +CC=clang CXX=clang++ cmake -E chdir bclang cmake -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. cmake --build bclang if [ $? -eq 0 ]; then echo "Passed" diff --git a/test/runtests.sh b/test/runtests.sh index f49aacaf6..59695b0fe 100644 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -15,7 +15,7 @@ echo " GCC - STL" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf gcc --version | grep gcc | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" @@ -36,7 +36,7 @@ echo " GCC - STL - Force C++03" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf gcc --version | grep gcc | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" @@ -57,28 +57,7 @@ echo " GCC - No STL" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf gcc --version | grep gcc | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -make -j4 -if [ $? -eq 0 ]; then - echo "<<<< Passed Compilation >>>>" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - echo "<<<< Passed Tests >>>>" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi -echo "" -echo "-----------------------------------------------" | tee -a log.txt -echo " GCC - No STL - Force Builtins" | tee -a log.txt -echo "-----------------------------------------------" | tee -a log.txt -rm * -rf -gcc --version | grep gcc | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +cmake -DCMAKE_CXX_COMPILER="g++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" @@ -103,7 +82,7 @@ echo " Clang - STL" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf clang --version | grep clang | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" @@ -124,7 +103,7 @@ echo " Clang - STL - Force C++03" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf clang --version | grep clang | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. +cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" @@ -145,28 +124,7 @@ echo " Clang - No STL" | tee -a log.txt echo "-----------------------------------------------" | tee -a log.txt rm * -rf clang --version | grep clang | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USE_MEM_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. -make -j4 -if [ $? -eq 0 ]; then - echo "<<<< Passed Compilation >>>>" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi -./etl_tests -if [ $? -eq 0 ]; then - echo "<<<< Passed Tests >>>>" -else - echo "****************\n**** Failed ****\n****************" | tee -a ../log.txt - exit $? -fi -echo "" -echo "-----------------------------------------------" | tee -a log.txt -echo " Clang - No STL - Builtins" | tee -a log.txt -echo "-----------------------------------------------" | tee -a log.txt -rm * -rf -clang --version | grep clang | tee -a log.txt -cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=ON -DETL_USE_MEM_BUILTINS=ON -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. +cmake -DCMAKE_CXX_COMPILER="clang++" -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF .. make -j4 if [ $? -eq 0 ]; then echo "<<<< Passed Compilation >>>>" diff --git a/test/sanity-check/c++03/CMakeLists.txt b/test/sanity-check/c++03/CMakeLists.txt index 71ff85693..863f49cd4 100644 --- a/test/sanity-check/c++03/CMakeLists.txt +++ b/test/sanity-check/c++03/CMakeLists.txt @@ -17,11 +17,6 @@ if (ETL_USE_TYPE_TRAITS_BUILTINS) add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) endif() -if (ETL_USE_MEM_BUILTINS) - message(STATUS "Compiling for built-in memory functions") - add_definitions(-DETL_USE_MEM_BUILTINS) -endif() - if (ETL_USER_DEFINED_TYPE_TRAITS) message(STATUS "Compiling for user defined type traits") add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) @@ -134,6 +129,7 @@ target_sources(t98 PRIVATE etl_profile.h ../enum_type.h.t.cpp ../error_handler.h.t.cpp ../exception.h.t.cpp + ../expected.h.t.cpp ../factorial.h.t.cpp ../fibonacci.h.t.cpp ../file_error_numbers.h.t.cpp diff --git a/test/sanity-check/c++11/CMakeLists.txt b/test/sanity-check/c++11/CMakeLists.txt index e3821f3ff..65687b9a3 100644 --- a/test/sanity-check/c++11/CMakeLists.txt +++ b/test/sanity-check/c++11/CMakeLists.txt @@ -17,11 +17,6 @@ if (ETL_USE_TYPE_TRAITS_BUILTINS) add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) endif() -if (ETL_USE_MEM_BUILTINS) - message(STATUS "Compiling for built-in memory functions") - add_definitions(-DETL_USE_MEM_BUILTINS) -endif() - if (ETL_USER_DEFINED_TYPE_TRAITS) message(STATUS "Compiling for user defined type traits") add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) @@ -134,6 +129,7 @@ target_sources(t11 PRIVATE etl_profile.h ../enum_type.h.t.cpp ../error_handler.h.t.cpp ../exception.h.t.cpp + ../expected.h.t.cpp ../factorial.h.t.cpp ../fibonacci.h.t.cpp ../file_error_numbers.h.t.cpp diff --git a/test/sanity-check/c++14/CMakeLists.txt b/test/sanity-check/c++14/CMakeLists.txt index 9176d7b13..a04625555 100644 --- a/test/sanity-check/c++14/CMakeLists.txt +++ b/test/sanity-check/c++14/CMakeLists.txt @@ -17,11 +17,6 @@ if (ETL_USE_TYPE_TRAITS_BUILTINS) add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) endif() -if (ETL_USE_MEM_BUILTINS) - message(STATUS "Compiling for built-in memory functions") - add_definitions(-DETL_USE_MEM_BUILTINS) -endif() - if (ETL_USER_DEFINED_TYPE_TRAITS) message(STATUS "Compiling for user defined type traits") add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) @@ -134,6 +129,7 @@ target_sources(t14 PRIVATE etl_profile.h ../enum_type.h.t.cpp ../error_handler.h.t.cpp ../exception.h.t.cpp + ../expected.h.t.cpp ../factorial.h.t.cpp ../fibonacci.h.t.cpp ../file_error_numbers.h.t.cpp diff --git a/test/sanity-check/c++17/CMakeLists.txt b/test/sanity-check/c++17/CMakeLists.txt index f6a00b141..abaabd551 100644 --- a/test/sanity-check/c++17/CMakeLists.txt +++ b/test/sanity-check/c++17/CMakeLists.txt @@ -17,11 +17,6 @@ if (ETL_USE_TYPE_TRAITS_BUILTINS) add_definitions(-DETL_USE_TYPE_TRAITS_BUILTINS) endif() -if (ETL_USE_MEM_BUILTINS) - message(STATUS "Compiling for built-in memory functions") - add_definitions(-DETL_USE_MEM_BUILTINS) -endif() - if (ETL_USER_DEFINED_TYPE_TRAITS) message(STATUS "Compiling for user defined type traits") add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS) @@ -134,6 +129,7 @@ target_sources(t17 PRIVATE etl_profile.h ../enum_type.h.t.cpp ../error_handler.h.t.cpp ../exception.h.t.cpp + ../expected.h.t.cpp ../factorial.h.t.cpp ../fibonacci.h.t.cpp ../file_error_numbers.h.t.cpp diff --git a/test/sanity-check/expected.h.t.cpp b/test/sanity-check/expected.h.t.cpp new file mode 100644 index 000000000..2fca92c3e --- /dev/null +++ b/test/sanity-check/expected.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) 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 diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index ce0e10305..1a8509410 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -37,10 +37,35 @@ SOFTWARE. namespace { + //***************************************************************************** + enum class FunctionCalled : int + { + Not_Called, + Free_Void_Called, + Free_Int_Called, + Free_Reference_Called, + Free_Moveableonly_Called, + Normal_Called, + Normal_Returning_Void_Called, + Alternative_Called, + Member_Void_Called, + Member_Void_Const_Called, + Member_Int_Called, + Member_Int_Const_Called, + Member_Reference_Called, + Member_Reference_Const_Called, + Member_Moveableonly_Called, + Member_Static_Called, + Operator_Called, + Operator_Const_Called, + Lambda_Called + }; + + FunctionCalled function_called = FunctionCalled::Not_Called; + //***************************************************************************** const int VALUE1 = 1; const int VALUE2 = 2; - bool function_called = false; bool parameter_correct = false; //***************************************************************************** @@ -70,7 +95,7 @@ namespace //***************************************************************************** void free_void() { - function_called = true; + function_called = FunctionCalled::Free_Void_Called; } //***************************************************************************** @@ -78,7 +103,7 @@ namespace //***************************************************************************** void free_int(int i, int j) { - function_called = true; + function_called = FunctionCalled::Free_Int_Called;; parameter_correct = (i == VALUE1) && (j == VALUE2); } @@ -87,7 +112,7 @@ namespace //***************************************************************************** void free_reference(const Data& data, int j) { - function_called = true; + function_called = FunctionCalled::Free_Reference_Called; parameter_correct = (data.d == VALUE1) && (j == VALUE2); } @@ -96,7 +121,7 @@ namespace //***************************************************************************** void free_moveableonly(MoveableOnlyData&& data) { - function_called = true; + function_called = FunctionCalled::Free_Moveableonly_Called; parameter_correct = (data.d == VALUE1); } @@ -105,7 +130,7 @@ namespace //***************************************************************************** int normal(int i, int j) { - function_called = true; + function_called = FunctionCalled::Normal_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j; @@ -116,7 +141,7 @@ namespace //***************************************************************************** void normal_returning_void(int i, int j) { - function_called = true; + function_called = FunctionCalled::Normal_Returning_Void_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); } @@ -125,7 +150,7 @@ namespace //***************************************************************************** int alternative(int i, int j) { - function_called = true; + function_called = FunctionCalled::Alternative_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j + 1; @@ -142,25 +167,25 @@ namespace // void void member_void() { - function_called = true; + function_called = FunctionCalled::Member_Void_Called; } void member_void_const() const { - function_called = true; + function_called = FunctionCalled::Member_Void_Const_Called; } //******************************************* // int void member_int(int i, int j) { - function_called = true; + function_called = FunctionCalled::Member_Int_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); } void member_int_const(int i, int j) const { - function_called = true; + function_called = FunctionCalled::Member_Int_Const_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); } @@ -168,13 +193,13 @@ namespace // reference void member_reference(const Data& data, int j) { - function_called = true; + function_called = FunctionCalled::Member_Reference_Called; parameter_correct = (data.d == VALUE1) && (j == VALUE2); } void member_reference_const(const Data& data, int j) const { - function_called = true; + function_called = FunctionCalled::Member_Reference_Const_Called; parameter_correct = (data.d == VALUE1) && (j == VALUE2); } @@ -182,7 +207,7 @@ namespace // moveable only data void member_moveableonly(MoveableOnlyData&& data) { - function_called = true; + function_called = FunctionCalled::Member_Moveableonly_Called; parameter_correct = (data.d == VALUE1); } @@ -190,7 +215,7 @@ namespace // static static void member_static(const Data& data, int j) { - function_called = true; + function_called = FunctionCalled::Member_Static_Called; parameter_correct = (data.d == VALUE1) && (j == VALUE2); } @@ -198,12 +223,12 @@ namespace // operator() void operator()() { - function_called = true; + function_called = FunctionCalled::Operator_Called; } void operator()() const { - function_called = true; + function_called = FunctionCalled::Operator_Const_Called; } }; @@ -226,7 +251,7 @@ namespace { SetupFixture() { - function_called = false; + function_called = FunctionCalled::Not_Called; parameter_correct = false; } }; @@ -272,7 +297,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Void_Called); } //************************************************************************* @@ -282,7 +307,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Void_Called); } //************************************************************************* @@ -292,7 +317,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } @@ -303,7 +328,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } @@ -317,7 +342,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Reference_Called); CHECK(parameter_correct); } @@ -331,7 +356,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Reference_Called); CHECK(parameter_correct); } @@ -345,7 +370,7 @@ namespace d(std::move(data)); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); CHECK(parameter_correct); } @@ -359,31 +384,31 @@ namespace d(std::move(data)); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); CHECK(parameter_correct); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int) { - etl::delegate d([](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + etl::delegate d([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }); d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Lambda_Called); CHECK(parameter_correct); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int_create) { - auto lambda = [](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); }; + auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }; etl::delegate d(lambda); d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Lambda_Called); CHECK(parameter_correct); } @@ -396,7 +421,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -408,7 +433,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -420,7 +445,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -432,7 +457,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Const_Called); } #if !defined(ETL_COMPILER_GCC) @@ -443,7 +468,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -453,7 +478,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -463,7 +488,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Const_Called); } //************************************************************************* @@ -473,7 +498,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Const_Called); } #endif @@ -488,7 +513,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -500,7 +525,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -512,7 +537,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -524,7 +549,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -536,7 +561,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -548,7 +573,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -561,7 +586,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -574,7 +599,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -587,7 +612,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -602,7 +627,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -617,7 +642,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -632,7 +657,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -647,7 +672,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -662,7 +687,7 @@ namespace d(std::move(data)); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Moveableonly_Called); CHECK(parameter_correct); } @@ -677,7 +702,7 @@ namespace d(std::move(data)); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Moveableonly_Called); CHECK(parameter_correct); } @@ -691,7 +716,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Static_Called); CHECK(parameter_correct); } @@ -705,7 +730,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Static_Called); CHECK(parameter_correct); } @@ -717,7 +742,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -727,7 +752,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -737,7 +762,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -747,7 +772,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -757,7 +782,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -768,7 +793,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -779,7 +804,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -790,7 +815,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -804,7 +829,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -818,7 +843,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -832,7 +857,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -846,7 +871,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -859,7 +884,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } @@ -868,11 +893,11 @@ namespace { etl::delegate d; - d.set([](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + d.set([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }); d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Lambda_Called); CHECK(parameter_correct); } @@ -889,7 +914,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -906,7 +931,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -922,7 +947,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -938,7 +963,7 @@ namespace d(data, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } #endif @@ -953,7 +978,7 @@ namespace d2(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -967,7 +992,7 @@ namespace d2(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -983,7 +1008,7 @@ namespace d2(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -1090,7 +1115,7 @@ namespace bool was_called = d.call_if(VALUE1, VALUE2); CHECK(was_called); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Normal_Returning_Void_Called); CHECK(parameter_correct); } @@ -1102,7 +1127,7 @@ namespace bool was_called = d.call_if(VALUE1, VALUE2); CHECK(!was_called); - CHECK(!function_called); + CHECK(function_called == FunctionCalled::Not_Called); CHECK(!parameter_correct); } @@ -1115,7 +1140,7 @@ namespace d(VALUE1, VALUE2); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } }; diff --git a/test/test_delegate_cpp03.cpp b/test/test_delegate_cpp03.cpp index 36b291367..c6e19aa7f 100644 --- a/test/test_delegate_cpp03.cpp +++ b/test/test_delegate_cpp03.cpp @@ -35,9 +35,34 @@ SOFTWARE. namespace { + //***************************************************************************** + enum class FunctionCalled : int + { + Not_Called, + Free_Void_Called, + Free_Int_Called, + Free_Reference_Called, + Free_Moveableonly_Called, + Normal_Called, + Normal_Returning_Void_Called, + Alternative_Called, + Member_Void_Called, + Member_Void_Const_Called, + Member_Int_Called, + Member_Int_Const_Called, + Member_Reference_Called, + Member_Reference_Const_Called, + Member_Moveableonly_Called, + Member_Static_Called, + Operator_Called, + Operator_Const_Called, + Lambda_Called + }; + + FunctionCalled function_called = FunctionCalled::Not_Called; + //***************************************************************************** const int VALUE1 = 1; - bool function_called = false; bool parameter_correct = false; //***************************************************************************** @@ -53,7 +78,7 @@ namespace //***************************************************************************** void free_void() { - function_called = true; + function_called = FunctionCalled::Free_Void_Called; } //***************************************************************************** @@ -61,7 +86,7 @@ namespace //***************************************************************************** void free_int(int i) { - function_called = true; + function_called = FunctionCalled::Free_Int_Called; parameter_correct = (i == VALUE1); } @@ -70,7 +95,7 @@ namespace //***************************************************************************** void free_reference(const Data& data) { - function_called = true; + function_called = FunctionCalled::Free_Reference_Called; parameter_correct = (data.d == VALUE1); } @@ -79,7 +104,7 @@ namespace //***************************************************************************** int normal(int i) { - function_called = true; + function_called = FunctionCalled::Normal_Called; parameter_correct = (i == VALUE1); return i; @@ -90,7 +115,7 @@ namespace //***************************************************************************** void normal_returning_void(int i) { - function_called = true; + function_called = FunctionCalled::Normal_Returning_Void_Called; parameter_correct = (i == VALUE1); } @@ -99,7 +124,7 @@ namespace //***************************************************************************** int alternative(int i) { - function_called = true; + function_called = FunctionCalled::Alternative_Called; parameter_correct = (i == VALUE1); return i + 1; @@ -116,25 +141,25 @@ namespace // void void member_void() { - function_called = true; + function_called = FunctionCalled::Member_Void_Called; } void member_void_const() const { - function_called = true; + function_called = FunctionCalled::Member_Void_Const_Called; } //******************************************* // int void member_int(int i) { - function_called = true; + function_called = FunctionCalled::Member_Int_Called; parameter_correct = (i == VALUE1); } void member_int_const(int i) const { - function_called = true; + function_called = FunctionCalled::Member_Int_Const_Called; parameter_correct = (i == VALUE1); } @@ -142,13 +167,13 @@ namespace // reference void member_reference(const Data& data) { - function_called = true; + function_called = FunctionCalled::Member_Reference_Called; parameter_correct = (data.d == VALUE1); } void member_reference_const(const Data& data) const { - function_called = true; + function_called = FunctionCalled::Member_Reference_Const_Called; parameter_correct = (data.d == VALUE1); } @@ -156,7 +181,7 @@ namespace // static static void member_static(const Data& data) { - function_called = true; + function_called = FunctionCalled::Member_Static_Called; parameter_correct = (data.d == VALUE1); } @@ -164,12 +189,12 @@ namespace // operator() void operator()() { - function_called = true; + function_called = FunctionCalled::Operator_Called; } void operator()() const { - function_called = true; + function_called = FunctionCalled::Operator_Const_Called; } }; @@ -192,7 +217,7 @@ namespace { SetupFixture() { - function_called = false; + function_called = FunctionCalled::Not_Called; parameter_correct = false; } }; @@ -217,7 +242,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Void_Called); } //************************************************************************* @@ -227,7 +252,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } @@ -241,7 +266,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Reference_Called); CHECK(parameter_correct); } @@ -254,7 +279,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -266,7 +291,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -278,7 +303,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Const_Called); } #if !defined(ETL_COMPILER_GCC) @@ -289,7 +314,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -299,7 +324,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Const_Called); } #endif @@ -314,7 +339,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Operator_Called); } //************************************************************************* @@ -326,7 +351,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -338,7 +363,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -350,7 +375,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -363,7 +388,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -378,7 +403,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -393,7 +418,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -407,7 +432,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Static_Called); CHECK(parameter_correct); } @@ -419,7 +444,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Called); } //************************************************************************* @@ -429,7 +454,7 @@ namespace d(); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } //************************************************************************* @@ -439,7 +464,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -450,7 +475,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); CHECK(parameter_correct); } @@ -464,7 +489,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -478,7 +503,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -491,7 +516,7 @@ namespace d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Free_Int_Called); CHECK(parameter_correct); } @@ -500,11 +525,11 @@ namespace { etl_cpp03::delegate d; - d.set([](int i) { function_called = true; parameter_correct = (i == VALUE1); }); + d.set([](int i) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1); }); d(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Lambda_Called); CHECK(parameter_correct); } @@ -521,7 +546,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -538,7 +563,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } @@ -554,7 +579,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Called); CHECK(parameter_correct); } @@ -570,7 +595,7 @@ namespace d(data); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Reference_Const_Called); CHECK(parameter_correct); } #endif @@ -585,7 +610,7 @@ namespace d2(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -601,7 +626,7 @@ namespace d2(VALUE1); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Member_Int_Called); CHECK(parameter_correct); } @@ -708,7 +733,7 @@ namespace bool was_called = d.call_if(VALUE1); CHECK(was_called); - CHECK(function_called); + CHECK(function_called == FunctionCalled::Normal_Returning_Void_Called); CHECK(parameter_correct); } @@ -720,7 +745,7 @@ namespace bool was_called = d.call_if(VALUE1); CHECK(!was_called); - CHECK(!function_called); + CHECK(function_called == FunctionCalled::Not_Called); CHECK(!parameter_correct); } }; diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 29c0b63d0..7d58f9fd2 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -1490,6 +1490,16 @@ namespace CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST(test_emplace_back_return) + { + DataNDC data; + + data.emplace_back("24"); + auto& back = data.emplace_back("42"); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST(test_push_back_excess) { @@ -1602,6 +1612,16 @@ namespace CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST(test_emplace_front_return) + { + DataNDC data; + + data.emplace_front("24"); + auto& front = data.emplace_front("42"); + CHECK_EQUAL(front, data.front()); + } + //************************************************************************* TEST(test_push_front_excess) { diff --git a/test/test_expected.cpp b/test/test_expected.cpp new file mode 100644 index 000000000..3f67f6f8f --- /dev/null +++ b/test/test_expected.cpp @@ -0,0 +1,446 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2022 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/expected.h" +#include "etl/type_traits.h" + +#include +#include + +namespace +{ + struct Value + { + std::string v; + + Value() + { + } + + Value(const std::string v_) + : v(v_) + { + } + + operator std::string() const + { + return v; + } + }; + + struct ValueM + { + ValueM() + { + } + + ValueM(const std::string& v_) + : v(v_) + { + } + + ValueM(ValueM&&) = default; + ValueM& operator =(ValueM&&) = default; + + ValueM(const ValueM&) = delete; + ValueM& operator =(const ValueM&) = delete; + + std::string v; + }; + + struct Error + { + std::string e; + + Error() = default; + Error(const Error&) = default; + Error& operator =(const Error&) = default; + + Error(const std::string e_) + : e(e_) + { + } + + Error& operator =(const std::string e_) + { + e = e_; + } + + operator std::string() const + { + return e; + } + }; + + struct ErrorM + { + ErrorM() + { + } + + ErrorM(const std::string& e_) + : e(e_) + { + } + + ErrorM(ErrorM&&) = default; + ErrorM& operator =(ErrorM&&) = default; + + ErrorM(const ErrorM&) = delete; + ErrorM& operator =(const ErrorM&) = delete; + + std::string e; + }; + + using Expected = etl::expected; + using ExpectedV = etl::expected; + using ExpectedM = etl::expected; + using ExpectedVM = etl::expected; + + using Unexpected = etl::unexpected; + using UnexpectedV = etl::unexpected; + using UnexpectedM = etl::unexpected; +} + +namespace +{ + SUITE(test_result) + { + //************************************************************************* + TEST(test_default_constructor) + { + Expected expected; + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + } + + //************************************************************************* + TEST(test_constructor_for_result_with_value) + { + Value input = { "value 1" }; + Expected expected(input); + + Value output = expected.value(); + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + CHECK_TRUE(output.v == input.v); + } + + //************************************************************************* + TEST(test_constructor_for_const_result_with_value) + { + Value input = { "value 1" }; + const Expected expected(input); + + const Value& output = expected.value(); + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + CHECK_TRUE(output.v == input.v); + } + + //************************************************************************* + TEST(test_constructor_for_moveable_result_with_value) + { + ValueM input = { "value 1" }; + ExpectedM expected(etl::move(input)); + + ValueM output = etl::move(expected.value()); + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + CHECK_TRUE(output.v == std::string("value 1")); + } + + //************************************************************************* + TEST(test_constructor_for_result_with_error) + { + Error input = { "error 1" }; + Unexpected unexpected(input); + Expected expected(unexpected); + + Error output = expected.error(); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK(output.e == input.e); + } + + //************************************************************************* + TEST(test_constructor_for_const_result_with_error) + { + const Error input = { "error 1" }; + const Unexpected unexpected(input); + const Expected expected(unexpected); + + const Error& output = expected.error(); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK(output.e == input.e); + } + + //************************************************************************* + TEST(test_constructor_for_moveable_result_with_error) + { + ErrorM input = { "error 1" }; + UnexpectedM unexpected(etl::move(input)); + ExpectedM expected(etl::move(unexpected)); + + ErrorM output = etl::move(expected.error()); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK_TRUE(output.e == std::string("error 1")); + } + + //************************************************************************* + TEST(test_constructor_for_result_void_value_with_value) + { + ExpectedV expected; + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + } + + //************************************************************************* + TEST(test_constructor_for_const_result_void_value_with_value) + { + const ExpectedV expected; + + CHECK_TRUE(expected.has_value()); + CHECK_TRUE(bool(expected)); + } + + //************************************************************************* + TEST(test_constructor_for_result_void_value_with_error) + { + Error input = { "error 1" }; + UnexpectedV unexpected(input); + ExpectedV expected(unexpected); + + Error output = expected.error(); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK_TRUE(output.e == input.e); + } + + //************************************************************************* + TEST(test_constructor_for_const_result_void_value_with_error) + { + const Error input = { "error 1" }; + const UnexpectedV unexpected(input); + const ExpectedV expected(unexpected); + + const Error& output = expected.error(); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK_TRUE(output.e == input.e); + } + + //************************************************************************* + TEST(test_constructor_for_moveable_result_void_value_with_error) + { + ErrorM input = { "error 1" }; + UnexpectedM unexpected(etl::move(input)); + ExpectedM expected(etl::move(unexpected)); + + ErrorM output = etl::move(expected.error()); + + CHECK_FALSE(expected.has_value()); + CHECK_FALSE(bool(expected)); + CHECK(output.e == std::string("error 1")); + } + + //************************************************************************* + TEST(test_copy_construct) + { + Value input1 = { "value 1" }; + Expected expected1(input1); + Expected expected2(expected1); + + Value output1 = expected2.value(); + + CHECK_TRUE(expected1.has_value()); + CHECK_TRUE(expected2.has_value()); + CHECK(output1.v == input1.v); + } + + //************************************************************************* + TEST(test_copy_assign) + { + Value input1 = { "value 1" }; + Expected expected1(input1); + + Value input2 = { "value 2" }; + Expected expected2(input2); + + expected2 = expected1; + + Value output1 = expected1.value(); + Value output2 = expected2.value(); + + CHECK_TRUE(expected1.has_value()); + CHECK_TRUE(expected2.has_value()); + + //CHECK(output1.v != input1.v); + //CHECK(output2.v != input1.v); + + //CHECK(output1.v == input2.v); + //CHECK(output2.v == input2.v); + } + + //************************************************************************* + TEST(test_move_construct) + { + ValueM input1 = { "value 1" }; + ExpectedM expected1(etl::move(input1)); + ExpectedM expected2(etl::move(expected1)); + + ValueM output1 = etl::move(expected1.value()); + ValueM output2 = etl::move(expected2.value()); + + CHECK_TRUE(expected1.has_value()); + CHECK_TRUE(expected2.has_value()); + + CHECK_EQUAL("", output1.v); + CHECK_EQUAL("value 1", output2.v); + } + + //************************************************************************* + TEST(test_move_assign) + { + ValueM input1 = { "value 1" }; + ExpectedM expected1(etl::move(input1)); + + ValueM input2 = { "value 2" }; + ExpectedM expected2(etl::move(input2)); + + expected2 = etl::move(expected1); + + ValueM output1 = etl::move(expected1.value()); + ValueM output2 = etl::move(expected2.value()); + + CHECK_TRUE(expected1.has_value()); + CHECK_TRUE(expected2.has_value()); + + CHECK_EQUAL("", output1.v); + CHECK_EQUAL("value 1", output2.v); + } + + //************************************************************************* + TEST(test_copy_construct_void_value) + { + Error input1 = { "error 1" }; + UnexpectedV unexpected1(input1); + ExpectedV expected1(unexpected1); + ExpectedV expected2(expected1); + + CHECK_FALSE(expected1.has_value()); + CHECK_FALSE(expected2.has_value()); + + Error output1 = expected1.error(); + Error output2 = expected2.error(); + + CHECK_EQUAL(input1.e, output1.e); + CHECK_EQUAL(input1.e, output2.e); + } + + //************************************************************************* + TEST(test_copy_assign_void_value) + { + Error input1 = { "error 1" }; + UnexpectedV unexpected1(input1); + + Error input2 = { "error 2" }; + UnexpectedV unexpected2(input2); + + ExpectedV expected1(unexpected1); + ExpectedV expected2(unexpected2); + + expected2 = expected1; + + Error output1 = expected1.error(); + Error output2 = expected2.error(); + + CHECK_FALSE(expected1.has_value()); + CHECK_FALSE(expected2.has_value()); + + CHECK_EQUAL(input1.e, output1.e); + CHECK_EQUAL(input1.e, output2.e); + } + + //************************************************************************* + TEST(test_move_construct_void_value) + { + ErrorM input1 = { "error 1" }; + UnexpectedM unexpected1(etl::move(input1)); + ExpectedVM expected1(etl::move(unexpected1)); + ExpectedVM expected2(etl::move(expected1)); + + ErrorM output1 = etl::move(expected1.error()); + ErrorM output2 = etl::move(expected2.error()); + + CHECK_FALSE(expected1.has_value()); + CHECK_FALSE(expected2.has_value()); + + CHECK_EQUAL("", output1.e); + CHECK_EQUAL("error 1", output2.e); + } + + //************************************************************************* + TEST(test_move_assign_void_value) + { + ErrorM input1 = { "error 1" }; + UnexpectedM unexpected1(etl::move(input1)); + + ErrorM input2 = { "error 2" }; + UnexpectedM unexpected2(etl::move(input2)); + + ExpectedVM expected1(etl::move(unexpected1)); + ExpectedVM expected2(etl::move(unexpected2)); + + expected2 = etl::move(expected1); + + ErrorM output1 = etl::move(expected1.error()); + ErrorM output2 = etl::move(expected2.error()); + + CHECK_FALSE(expected1.has_value()); + CHECK_FALSE(expected2.has_value()); + + CHECK_EQUAL("", output1.e); + CHECK_EQUAL("error 1", output2.e); + } + }; +} diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 21356c63b..43c85bde9 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -694,6 +694,16 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_front_return) + { + DataNDC data; + + data.emplace_front("24"); + auto& front = data.emplace_front("42"); + CHECK_EQUAL(front, data.front()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_emplace_after) { diff --git a/test/test_indirect_vector.cpp b/test/test_indirect_vector.cpp index 06ba7d2b2..97dc944f0 100644 --- a/test/test_indirect_vector.cpp +++ b/test/test_indirect_vector.cpp @@ -715,6 +715,18 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + DataNDC data; + std::string value1("A"); + std::string value2("B"); + + data.emplace_back(value1); + auto& back = data.emplace_back(value2); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_unique_ptr) { diff --git a/test/test_list.cpp b/test/test_list.cpp index 5e3cfd119..d65623ce9 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -731,6 +731,16 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_front_return) + { + DataNDC data; + + data.emplace_front("24"); + auto& front = data.emplace_front("42"); + CHECK_EQUAL(front, data.front()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_front_excess) { @@ -887,6 +897,16 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + DataNDC data; + + data.emplace_back("24"); + auto& back = data.emplace_back("42"); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { diff --git a/test/test_memory.cpp b/test/test_memory.cpp index d1878d30f..9854f172e 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -41,6 +41,8 @@ SOFTWARE. #include #include +#include + namespace { @@ -1301,5 +1303,46 @@ namespace CHECK((reinterpret_cast(data) + 18) == p1); CHECK((reinterpret_cast(data) + 32) == p2); } + + //************************************************************************* + class Base + { + public: + virtual ~Base() {}; + virtual void function() = 0; + }; + + static bool function_was_called = false; + + class Derived : public Base + { + public: + Derived() + { + function_was_called = false; + } + + void function() + { + function_was_called = true; + } + }; + + void call(etl::unique_ptr ptr) + { + ptr->function(); + } + + TEST(test_derived_type) + { + CHECK(!function_was_called); + + etl::unique_ptr ptr(new Derived()); + CHECK(ptr.get() != ETL_NULLPTR); + + call(etl::move(ptr)); + CHECK(function_was_called); + CHECK(ptr.get() == ETL_NULLPTR); + } }; } diff --git a/test/test_optional.cpp b/test/test_optional.cpp index b4a743a90..9308af27d 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -127,6 +127,13 @@ namespace CHECK_EQUAL(1, DataM::get_instance_count()); } + //************************************************************************* + TEST(test_emplace_return) + { + etl::optional data; + CHECK_EQUAL(42U, data.emplace(42U).value); + } + //************************************************************************* TEST(test_moveable) { @@ -466,5 +473,33 @@ namespace data.reset(); CHECK(!bool(data)); } + + //************************************************************************* + etl::optional get_optional_test_bug_634() + { + etl::optional result = 8; + result.reset(); + + return result; + } + + TEST(test_bug_634) + { + etl::optional result; + + result = get_optional_test_bug_634(); + + CHECK_EQUAL(false, result.has_value()); + } + + //************************************************************************* + TEST(test_optional_emplace_bug_636) + { + etl::optional result = 1; + result.emplace(2); + + CHECK_TRUE(result.has_value()); + CHECK_EQUAL(2, result.value()); + } }; } diff --git a/test/test_result.cpp b/test/test_result.cpp index ad0f59086..e2af35560 100644 --- a/test/test_result.cpp +++ b/test/test_result.cpp @@ -5,7 +5,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2017 John Wellbelove +Copyright(c) 2022 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 @@ -85,69 +85,21 @@ namespace std::string e; }; - using Result = etl::result; - using ResultV = etl::result; - using ResultM = etl::result; + using ResultValueError = etl::result; + using ResultVoidError = etl::result; + using ResultValueVoid = etl::result; + using ResultM = etl::result; } -// Definitions for when the STL and compiler built-ins are not available. -#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) { //************************************************************************* - TEST(test_constructor_for_result_with_value) + TEST(test_construct_result_value_error_type_with_value) { Value input = { "value 1" }; - Result result(input); + ResultValueError result(input); Value output = result.value(); @@ -157,10 +109,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_const_result_with_value) + TEST(test_construct_const_result_value_error_type_with_value) { Value input = { "value 1" }; - const Result result(input); + const ResultValueError result(input); const Value& output = result.value(); @@ -170,7 +122,7 @@ namespace } //************************************************************************* - TEST(test_constructor_for_moveable_result_with_value) + TEST(test_construct_moveable_result_value_error_type_with_value) { ValueM input = { "value 1" }; ResultM result(etl::move(input)); @@ -183,10 +135,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_result_with_error) + TEST(test_construct_result_value_error_type_with_error) { Error input = { "error 1" }; - Result result(input); + ResultValueError result(input); Error output = result.error(); @@ -196,10 +148,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_const_result_with_error) + TEST(test_construct_const_result_value_error_type_with_error) { Error input = { "error 1" }; - const Result result(input); + const ResultValueError result(input); const Error& output = result.error(); @@ -209,7 +161,7 @@ namespace } //************************************************************************* - TEST(test_constructor_for_moveable_result_with_error) + TEST(test_construct_moveable_result_value_error_type_with_error) { ErrorM input = { "error 1" }; ResultM result(etl::move(input)); @@ -222,28 +174,28 @@ namespace } //************************************************************************* - TEST(test_constructor_for_result_void_value_with_value) + TEST(test_default_construct_result_void_error_type) { - ResultV result; + ResultVoidError result; - CHECK(!result.is_value()); - CHECK(result.is_error()); + CHECK(result.is_value()); + CHECK(!result.is_error()); } //************************************************************************* - TEST(test_constructor_for_const_result_void_value_with_value) + TEST(test_default_construct_const_result_void_error_type) { - const ResultV result; + const ResultVoidError result; - CHECK(!result.is_value()); - CHECK(result.is_error()); + CHECK(result.is_value()); + CHECK(!result.is_error()); } //************************************************************************* - TEST(test_constructor_for_result_void_value_with_error) + TEST(test_construct_result_void_error_type_with_error) { Error input = { "error 1" }; - ResultV result(input); + ResultVoidError result(input); Error output = result.error(); @@ -253,10 +205,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_const_result_void_value_with_error) + TEST(test_construct_const_result_void_error_type_with_error) { Error input = { "error 1" }; - const ResultV result(input); + const ResultVoidError result(input); const Error& output = result.error(); @@ -266,10 +218,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_moveable_result_void_value_with_error) + TEST(test_construct_moveable_result_void_error_type_with_error) { Error input = { "error 1" }; - ResultV result(etl::move(input)); + ResultVoidError result(etl::move(input)); Error output = etl::move(result.error()); @@ -279,10 +231,10 @@ namespace } //************************************************************************* - TEST(test_constructor_for_moveable_const_result_void_value_with_error) + TEST(test_construct_moveable_const_result_void_error_type_with_error) { Error input = { "error 1" }; - const ResultV result(etl::move(input)); + const ResultVoidError result(etl::move(input)); Error output = etl::move(result.error()); @@ -291,13 +243,83 @@ namespace CHECK(output.e == std::string("error 1")); } + //************************************************************************* + TEST(test_default_construct_result_value_void_type) + { + ResultValueVoid result; + + CHECK(!result.is_value()); + CHECK(result.is_error()); + } + + //************************************************************************* + TEST(test_default_construct_const_result_value_void_type) + { + const ResultValueVoid result; + + CHECK(!result.is_value()); + CHECK(result.is_error()); + } + + //************************************************************************* + TEST(test_construct_result_value_void_type_with_value) + { + Value input = { "value 1" }; + ResultValueVoid result(input); + + Value output = result.value(); + + CHECK(result.is_value()); + CHECK(!result.is_error()); + CHECK(output.v == input.v); + } + + //************************************************************************* + TEST(test_construct_const_result_value_void_type_with_value) + { + Value input = { "value 1" }; + const ResultValueVoid result(input); + + const Value output = result.value(); + + CHECK(result.is_value()); + CHECK(!result.is_error()); + CHECK(output.v == input.v); + } + + //************************************************************************* + TEST(test_construct_moveable_result_value_void_type_with_value) + { + Value input = { "value 1" }; + ResultValueVoid result(etl::move(input)); + + Value output = etl::move(result.value()); + + CHECK(result.is_value()); + CHECK(!result.is_error()); + CHECK(output.v == std::string("value 1")); + } + + //************************************************************************* + TEST(test_construct_moveable_const_result_value_void_type_with_value) + { + Value input = { "value 1" }; + const ResultValueVoid result(etl::move(input)); + + Value output = etl::move(result.value()); + + CHECK(result.is_value()); + CHECK(!result.is_error()); + CHECK(output.v == std::string("value 1")); + } + //************************************************************************* TEST(test_copy_construct_result) { Value input = { "value 1" }; - Result result(input); + ResultValueError result(input); - Result result2(result); + ResultValueError result2(result); Value output = result2.value(); @@ -312,9 +334,9 @@ namespace TEST(test_move_construct_result) { Value input = { "value 1" }; - Result result(input); + ResultValueError result(input); - Result result2(etl::move(result)); + ResultValueError result2(etl::move(result)); Value output = result.value(); Value output2 = result2.value(); @@ -331,10 +353,10 @@ namespace TEST(test_move_assign_result) { Value input = { "value 1" }; - Result result(input); + ResultValueError result(input); Value input2 = { "value 2" }; - Result result2(result); + ResultValueError result2(result); result2 = etl::move(result); diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 838487572..363d59d98 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -127,11 +127,6 @@ struct etl::is_assignable : public etl::true_type { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::true_type { @@ -148,11 +143,6 @@ struct etl::is_assignable : public etl::true_type { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::false_type { @@ -169,11 +159,6 @@ struct etl::is_assignable : public etl::true { }; -template <> -struct etl::is_constructible : public etl::true_type -{ -}; - template <> struct etl::is_copy_constructible : public etl::true_type { diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 70313f3ff..facf99cc8 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -634,31 +634,6 @@ namespace CHECK(is_equal); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_emplace_back) - { - Compare_Data compare_data; - Data data; - - for (int i = 0; i < int(SIZE); ++i) - { - compare_data.emplace_back(i); - } - - for (int i = 0; i < int(SIZE); ++i) - { - data.emplace_back(i); - } - - CHECK_EQUAL(compare_data.size(), data.size()); - - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); - - CHECK(is_equal); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_literal) { @@ -697,6 +672,41 @@ namespace CHECK_THROW(data.push_back(SIZE), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back) + { + Compare_Data compare_data; + Data data; + + for (int i = 0; i < int(SIZE); ++i) + { + compare_data.emplace_back(i); + } + + for (int i = 0; i < int(SIZE); ++i) + { + data.emplace_back(i); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + Data data; + + data.emplace_back(24); + auto back = data.emplace_back(42); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { diff --git a/test/test_vector_external_buffer.cpp b/test/test_vector_external_buffer.cpp index 117bcdb1e..f1e6e8234 100644 --- a/test/test_vector_external_buffer.cpp +++ b/test/test_vector_external_buffer.cpp @@ -685,6 +685,41 @@ namespace CHECK_THROW(data.push_back(SIZE), etl::vector_full); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back) + { + Compare_Data compare_data; + Data data(buffer1, SIZE); + + for (int i = 0; i < int(SIZE); ++i) + { + compare_data.emplace_back(i); + } + + for (int i = 0; i < int(SIZE); ++i) + { + data.emplace_back(i); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + Data data(buffer1, SIZE); + + data.emplace_back(24); + auto back = data.emplace_back(42); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 3b4efc27d..ccc58775b 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -662,29 +662,6 @@ namespace CHECK_THROW(data.push_back(NDC("Z")), etl::vector_full); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_emplace_back) - { - CompareDataNDC compare_data; - DataNDC data; - - for (size_t i = 0UL; i < SIZE; ++i) - { - std::string value(" "); - value[0] = char('A' + i); - compare_data.emplace_back(value, i); - data.emplace_back(value, i); - } - - CHECK_EQUAL(compare_data.size(), data.size()); - - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); - - CHECK(is_equal); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_unique_ptr) { @@ -711,6 +688,39 @@ namespace CHECK_EQUAL(4, *data[3]); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back) + { + CompareDataNDC compare_data; + DataNDC data; + + for (size_t i = 0UL; i < SIZE; ++i) + { + std::string value(" "); + value[0] = char('A' + i); + compare_data.emplace_back(value, i); + data.emplace_back(value, i); + } + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + DataNDC data; + + data.emplace_back("A", 24); + auto back = data.emplace_back("B", 42); + CHECK_EQUAL(back, data.back()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_int) { diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index d6aad71d5..f41528046 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -1057,6 +1057,17 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + Data data; + int d1 = 22; + int d2 = 42; + + data.emplace_back(&d1); + CHECK_EQUAL(&d2, data.emplace_back(&d2)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { diff --git a/test/test_vector_pointer_external_buffer.cpp b/test/test_vector_pointer_external_buffer.cpp index edad3ac96..97c6fe9dc 100644 --- a/test/test_vector_pointer_external_buffer.cpp +++ b/test/test_vector_pointer_external_buffer.cpp @@ -1043,6 +1043,17 @@ namespace CHECK(is_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_emplace_back_return) + { + Data data(buffer1, SIZE); + int d1 = 42; + int d2 = 24; + + data.emplace_back(&d1); + CHECK_EQUAL(&d2, data.emplace_back(&d2)); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index c855b06b2..a88a56dc5 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -5630,6 +5630,34 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -11381,6 +11409,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 1f0ab436f..693b20732 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1344,6 +1344,9 @@ ETL\Utilities + + ETL\Utilities + @@ -2228,9 +2231,6 @@ Tests\Misc - - Tests\Misc - Tests\Misc @@ -3392,6 +3392,15 @@ Tests\Misc + + Tests\Containers + + + Tests\Containers + + + Tests\Sanity Checks\Source + diff --git a/version.txt b/version.txt index 9c4538fec..afa2d91db 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -20.35.0 +20.35.10