From d4813dff86c725072385dda9bc98cd8e4fea5151 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 9 Mar 2025 10:41:15 +0100 Subject: [PATCH 1/7] Add traits to type_list (#1044) --- include/etl/type_list.h | 91 +++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_type_list.cpp | 172 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 test/test_type_list.cpp diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 533ae761..556787ab 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -30,7 +30,10 @@ SOFTWARE. #define ETL_TYPE_LIST_INCLUDED #include "platform.h" + +#include "algorithm.h" #include "nth_type.h" +#include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" @@ -38,6 +41,9 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { + + static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** /// Type list forward declaration. //*************************************************************************** @@ -61,6 +67,18 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; + namespace private_type_list + { + + // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition + template + struct recursion_helper + { + using type = type_list; + }; + + } + //*************************************************************************** /// Recursive type list implementation for multiple types. //*************************************************************************** @@ -68,6 +86,7 @@ namespace etl struct type_list : type_list { using type = THead; + using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -87,6 +106,7 @@ namespace etl struct type_list : type_list<> { using type = THead; + using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -180,6 +200,77 @@ namespace etl { using type = typename type_list_cat, TTail...>::type; }; + + template + struct type_list_contains + : public etl::integral_constant::value ? true : type_list_contains::value> + { + }; + + template + struct type_list_contains, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; +#endif + + template + struct type_list_index_of + : public etl::integral_constant::value ? 0 : + (type_list_index_of::value == type_list_npos ? + type_list_npos : type_list_index_of::value + 1)> + { + }; + + template + struct type_list_index_of, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; +#endif + + template + struct type_list_max_sizeof_type + : public etl::integral_constant::value)> + { + }; + + template<> + struct type_list_max_sizeof_type> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; +#endif + + template + struct type_list_max_alignment + : public etl::integral_constant::value, + type_list_max_alignment::value)> + { + }; + + template<> + struct type_list_max_alignment> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; +#endif } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bcc8a0da..d2641ab5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -286,6 +286,7 @@ add_executable(etl_tests test_to_u8string.cpp test_to_wstring.cpp test_type_def.cpp + test_type_list.cpp test_type_lookup.cpp test_type_select.cpp test_type_traits.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp new file mode 100644 index 00000000..44f197f8 --- /dev/null +++ b/test/test_type_list.cpp @@ -0,0 +1,172 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 BMW AG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include "etl/type_list.h" + +#include + +namespace +{ +#if ETL_USING_CPP11 + SUITE(test_type_list) + { + //************************************************************************* + TEST(test_nth_type) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type, char>::value)); + CHECK_TRUE((std::is_same::type, int>::value)); + CHECK_TRUE((std::is_same::type, uint32_t>::value)); + } + + //************************************************************************* + TEST(test_type_list_select) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_TRUE((std::is_same::type, t2>::value)); + } + + //************************************************************************* + TEST(test_type_list_size) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + CHECK_EQUAL(etl::type_list_size::value, 3); + CHECK_EQUAL(etl::type_list_size::value, 2); + } + + //************************************************************************* + TEST(test_type_list_cat) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + + typedef etl::type_list t_cat1; + typedef etl::type_list t_cat2; + + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + } + + //************************************************************************* + TEST(test_type_list_contains) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + CHECK_FALSE((etl::type_list_contains::value)); + +#if ETL_USING_CPP17 + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); + CHECK_FALSE((etl::type_list_contains_v)); +#endif + } + + //************************************************************************* + TEST(test_type_list_index_of) + { + typedef etl::type_list t1; + typedef etl::type_list<> t2; + + CHECK_EQUAL((etl::type_list_index_of::value), 0); + CHECK_EQUAL((etl::type_list_index_of::value), 1); + CHECK_EQUAL((etl::type_list_index_of::value), 2); + CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_index_of_v), 0); + CHECK_EQUAL((etl::type_list_index_of_v), 1); + CHECK_EQUAL((etl::type_list_index_of_v), 2); + CHECK_EQUAL((etl::type_list_index_of_v), etl::type_list_npos); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_sizeof_type) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); + CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); + CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); +#endif + } + + //************************************************************************* + TEST(test_type_list_max_alignment) + { + typedef etl::type_list t1; + typedef etl::type_list t2; + typedef etl::type_list t3; + typedef etl::type_list<> t4; + + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, std::alignment_of::value); + CHECK_EQUAL(etl::type_list_max_alignment::value, 1); + +#if ETL_USING_CPP17 + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), std::alignment_of::value); + CHECK_EQUAL((etl::type_list_max_alignment_v), 1); +#endif + } + + }; +#endif +} From f1d5b16d38603c9709d8541c3418ceb825d46bca Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 9 Mar 2025 10:47:24 +0000 Subject: [PATCH 2/7] Added etl::type_list_type_at_index --- include/etl/type_list.h | 46 +++++++++++++++++++++++++++------ test/test_type_list.cpp | 14 ++++++++++ test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 5 +++- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 556787ab..f4607dc9 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -41,8 +41,10 @@ SOFTWARE. #if ETL_USING_CPP11 namespace etl { - - static ETL_CONSTEXPR size_t type_list_npos = etl::integral_limits::max; + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t type_list_npos = etl::integral_limits::max; //*************************************************************************** /// Type list forward declaration. @@ -69,14 +71,12 @@ namespace etl namespace private_type_list { - // helper to solve the issue that recursed-rest can't be put directly in type_list::tail definition template struct recursion_helper { using type = type_list; }; - } //*************************************************************************** @@ -201,6 +201,9 @@ namespace etl using type = typename type_list_cat, TTail...>::type; }; + //*************************************************************************** + /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. + //*************************************************************************** template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> @@ -218,17 +221,21 @@ namespace etl inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif + //*************************************************************************** + /// Defines an integral constant that is the index of the specified type in the type_list. + /// If the type is not in the type_list, then defined as etl::type_list_npos. + //*************************************************************************** template struct type_list_index_of : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == type_list_npos ? - type_list_npos : type_list_index_of::value + 1)> + (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of::value + 1)> { }; template struct type_list_index_of, T> - : public etl::integral_constant + : public etl::integral_constant { }; @@ -237,6 +244,25 @@ namespace etl inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; #endif + //*************************************************************************** + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. + //*************************************************************************** + template + struct type_list_type_at_index + { + ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); + + using type = nth_type_t; + }; + + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; + + //*************************************************************************** + /// Defines an integral constant that is maximum sizeof all types in the type_list. + /// If the type_list is empty, then defined as 0. + //*************************************************************************** template struct type_list_max_sizeof_type : public etl::integral_constant::value)> @@ -254,10 +280,14 @@ namespace etl inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif + //*************************************************************************** + /// Defines an integral constant that is maximum alignment all types in the type_list. + /// If the type_list is empty, then defined as 1. + //*************************************************************************** template struct type_list_max_alignment : public etl::integral_constant::value, - type_list_max_alignment::value)> + type_list_max_alignment::value)> { }; diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 44f197f8..49641e6f 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -125,6 +125,20 @@ namespace #endif } + //************************************************************************* + TEST(test_type_list_type_at_index) + { + typedef etl::type_list t1; + + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + CHECK_TRUE((std::is_same::type>::value)); + + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + CHECK_TRUE((std::is_same>::value)); + } + //************************************************************************* TEST(test_type_list_max_sizeof_type) { diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index dfa03400..b796f072 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9453,6 +9453,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 5251ef8b..d5ff0eef 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1429,7 +1429,7 @@ UnitTest++\Header Files - UnitTest++\Header Files + ETL\Utilities @@ -3431,6 +3431,9 @@ Tests\Syntax Checks\Source + + Tests\Types + From 53887fa105c5d9e1bb73e4c46ff1e262741dd19d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 14 Mar 2025 15:46:25 +0000 Subject: [PATCH 3/7] Renamed type_list_index_of to type_list_index_of_type --- include/etl/type_list.h | 38 +++++++++++++++++++------------------- test/test_type_list.cpp | 10 +++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index f4607dc9..21ee103c 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -204,20 +204,20 @@ namespace etl //*************************************************************************** /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template + template struct type_list_contains : public etl::integral_constant::value ? true : type_list_contains::value> { }; - template + template struct type_list_contains, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif @@ -225,30 +225,30 @@ namespace etl /// Defines an integral constant that is the index of the specified type in the type_list. /// If the type is not in the type_list, then defined as etl::type_list_npos. //*************************************************************************** - template - struct type_list_index_of + template + struct type_list_index_of_type : public etl::integral_constant::value ? 0 : - (type_list_index_of::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of::value + 1)> + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> { }; - template - struct type_list_index_of, T> + template + struct type_list_index_of_type, T> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of::value; + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; #endif //*************************************************************************** /// Defines type as the type found at Index in the type_list. /// Static asserts if Index is out of range. //*************************************************************************** - template + template struct type_list_type_at_index { ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); @@ -256,27 +256,27 @@ namespace etl using type = nth_type_t; }; - template + template using type_list_type_at_index_t = typename type_list_type_at_index::type; //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template + template struct type_list_max_sizeof_type : public etl::integral_constant::value)> { }; - template<> + template <> struct type_list_max_sizeof_type> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; #endif @@ -284,21 +284,21 @@ namespace etl /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template + template struct type_list_max_alignment : public etl::integral_constant::value, type_list_max_alignment::value)> { }; - template<> + template <> struct type_list_max_alignment> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template + template inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif } diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 49641e6f..75c8f322 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -107,15 +107,15 @@ namespace } //************************************************************************* - TEST(test_type_list_index_of) + TEST(test_type_list_index_of_type) { typedef etl::type_list t1; typedef etl::type_list<> t2; - CHECK_EQUAL((etl::type_list_index_of::value), 0); - CHECK_EQUAL((etl::type_list_index_of::value), 1); - CHECK_EQUAL((etl::type_list_index_of::value), 2); - CHECK_EQUAL((etl::type_list_index_of::value), etl::type_list_npos); + CHECK_EQUAL((etl::type_list_index_of_type::value), 0); + CHECK_EQUAL((etl::type_list_index_of_type::value), 1); + CHECK_EQUAL((etl::type_list_index_of_type::value), 2); + CHECK_EQUAL((etl::type_list_index_of_type::value), etl::type_list_npos); #if ETL_USING_CPP17 CHECK_EQUAL((etl::type_list_index_of_v), 0); From 36b4d51bafc13dcdfbeeb23be7e12bb03a9e98d0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:06:34 +0000 Subject: [PATCH 4/7] Added etl::index_of_type as a complement to etl::nth_type --- include/etl/index_of_type.h | 80 +++++++++++++++++++++++++++++++++++++ test/test_index_of_type.cpp | 58 +++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 include/etl/index_of_type.h create mode 100644 test/test_index_of_type.cpp diff --git a/include/etl/index_of_type.h b/include/etl/index_of_type.h new file mode 100644 index 00000000..5546ad53 --- /dev/null +++ b/include/etl/index_of_type.h @@ -0,0 +1,80 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_INDEX_OF_TYPE_INCLUDED +#define ETL_INDEX_OF_TYPE_INCLUDED + +#include "platform.h" +#include "static_assert.h" +#include "integral_limits.h" + +namespace etl +{ +#if ETL_USING_CPP11 + + //*************************************************************************** + /// Defines a no-position constant. + //*************************************************************************** + static ETL_CONSTANT size_t index_of_type_npos = etl::integral_limits::max; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant::value ? 0 : + (etl::index_of_type::value == etl::index_of_type_npos ? etl::index_of_type_npos : + etl::index_of_type::value + 1)> + { + }; + + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + /// No types left. + //*************************************************************************** + template + struct index_of_type : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + //*************************************************************************** + /// Finds the index of a type in a variadic type parameter. + //*************************************************************************** + template + inline constexpr size_t index_of_type_v = etl::index_of_type::value; +#endif +#endif +} + +#endif diff --git a/test/test_index_of_type.cpp b/test/test_index_of_type.cpp new file mode 100644 index 00000000..60d211e8 --- /dev/null +++ b/test/test_index_of_type.cpp @@ -0,0 +1,58 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include "etl/index_of_type.h" +#include + +namespace +{ + SUITE(test_index_of_type) + { + //************************************************************************* + TEST(test_index_of_type) + { + CHECK_EQUAL(0, (etl::index_of_type::value)); + CHECK_EQUAL(1, (etl::index_of_type::value)); + CHECK_EQUAL(2, (etl::index_of_type::value)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type::value)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_index_of_type_v) + { + CHECK_EQUAL(0, (etl::index_of_type_v)); + CHECK_EQUAL(1, (etl::index_of_type_v)); + CHECK_EQUAL(2, (etl::index_of_type_v)); + CHECK_EQUAL(etl::index_of_type_npos, (etl::index_of_type_v)); + } +#endif + } +} From 495ea2b9433bb24a0ed9d0d6ba74a4d1841b9e84 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:07:25 +0000 Subject: [PATCH 5/7] Attempt to fix some sanitizer issues for tests --- include/etl/intrusive_forward_list.h | 5 ++++- test/test_map.cpp | 7 ++++--- test/test_multi_span.cpp | 14 ++------------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/include/etl/intrusive_forward_list.h b/include/etl/intrusive_forward_list.h index d1a024fc..5ba16248 100644 --- a/include/etl/intrusive_forward_list.h +++ b/include/etl/intrusive_forward_list.h @@ -304,7 +304,10 @@ namespace etl if (p_next != &this->terminator) { link_type* p_unlinked = etl::unlink_after(link); - p_unlinked->clear(); + if (p_unlinked != ETL_NULLPTR) + { + p_unlinked->clear(); + } --current_size; } } diff --git a/test/test_map.cpp b/test/test_map.cpp index bd8817ce..2c19e4e4 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -37,6 +37,7 @@ SOFTWARE. #include #include "etl/map.h" +#include "etl/string.h" #include "data.h" @@ -1575,7 +1576,7 @@ namespace #if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST_FIXTURE(SetupFixture, test_map_template_deduction) { - using Pair = std::pair; + using Pair = std::pair, int>; etl::map data { Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5} }; @@ -1596,9 +1597,9 @@ namespace #if ETL_HAS_INITIALIZER_LIST TEST_FIXTURE(SetupFixture, test_make_map) { - using Pair = ETL_OR_STD::pair; + using Pair = ETL_OR_STD::pair, int>; - auto data = etl::make_map>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); + auto data = etl::make_map, int, std::less>>(Pair{ "0", 0 }, Pair{ "1", 1 }, Pair{ "2", 2 }, Pair{ "3", 3 }, Pair{ "4", 4 }, Pair{ "5", 5 }); auto v = *data.begin(); using Type = decltype(v); diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 11c77196..c3e20a6e 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -341,14 +341,7 @@ namespace etl::multi_span::iterator ms_itr = ms_int.begin(); etl::multi_span::iterator ms_end_itr = ms_int.end(); - while (ms_itr != ms_end_itr) - { - // Fill the multi span - *ms_itr++ = *exp_itr++; - } - - ms_itr = ms_int.begin(); - exp_itr = expected.begin(); + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { @@ -554,10 +547,7 @@ namespace multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); - while (ms_itr != ms_end_itr) - { - *ms_itr++ = *exp_itr++; - } + std::copy(ms_itr, ms_end_itr, exp_itr); while (ms_itr != ms_end_itr) { From 03ca499e5ec7cb53c525f70e77c1fe5051d848f5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:08:55 +0000 Subject: [PATCH 6/7] Refactored and simplified some features of etl::type_list Removed nth_type specialisation for etl::type_list --- include/etl/type_list.h | 220 +++++++++++++++----------------- test/CMakeLists.txt | 1 + test/test_type_list.cpp | 57 ++++----- test/vs2022/etl.vcxproj | 2 + test/vs2022/etl.vcxproj.filters | 6 + 5 files changed, 140 insertions(+), 146 deletions(-) diff --git a/include/etl/type_list.h b/include/etl/type_list.h index 21ee103c..4dbc66ec 100644 --- a/include/etl/type_list.h +++ b/include/etl/type_list.h @@ -32,11 +32,12 @@ SOFTWARE. #include "platform.h" #include "algorithm.h" -#include "nth_type.h" +#include "index_of_type.h" #include "integral_limits.h" #include "static_assert.h" #include "type_traits.h" #include "utility.h" +#include "largest.h" #if ETL_USING_CPP11 namespace etl @@ -85,7 +86,7 @@ namespace etl template struct type_list : type_list { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper::type; static constexpr size_t size = sizeof...(TTail) + 1U; @@ -105,7 +106,7 @@ namespace etl template struct type_list : type_list<> { - using type = THead; + using head = THead; using tail = typename private_type_list::recursion_helper<>::type; static constexpr size_t size = 1U; @@ -119,50 +120,10 @@ namespace etl type_list& operator =(const type_list&) ETL_DELETE; }; - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list - //*************************************************************************** - template - struct nth_type> - { - ETL_STATIC_ASSERT(N <= sizeof...(TTail), "etl::nth_type out of range for etl::type_list"); - - using type = typename nth_type>::type; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for etl::type_list with index of 0 - //*************************************************************************** - template - struct nth_type<0, type_list> - { - using type = THead; - }; - - //*************************************************************************** - /// Specialisation of etl::nth_type for empty etl::type_list - //*************************************************************************** - template - struct nth_type> - { - }; - - //*************************************************************************** - /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. - //*************************************************************************** - template - struct type_list_select - { - using type = type_list...>; - }; - - template - using type_list_select_t = typename type_list_select::type; - //*************************************************************************** /// Type list size. //*************************************************************************** - template + template struct type_list_size; template @@ -176,37 +137,60 @@ namespace etl #endif //*************************************************************************** - /// Concatenates two or more type_lists. + /// Defines type as the type found at Index in the type_list. + /// Static asserts if Index is out of range. //*************************************************************************** - template - struct type_list_cat; - - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for a single type_list (base case) - //*************************************************************************** - template - struct type_list_cat + template + struct type_list_type_at_index { - using type = TypeList; + ETL_STATIC_ASSERT(Index < type_list_size::value, "etl::type_list_type_at_index out of range"); + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = typename type_list_type_at_index::type; }; - //*************************************************************************** - /// Concatenates two or more type_lists. - /// Specialisation for two or more type_lists - //*************************************************************************** - template - struct type_list_cat, etl::type_list, TTail...> + template + struct type_list_type_at_index { - using type = typename type_list_cat, TTail...>::type; + using type = typename TTypeList::head; }; + template + using type_list_type_at_index_t = typename type_list_type_at_index::type; + + //*************************************************************************** + /// Defines an integral constant that is the index of the specified type in the type_list. + /// If the type is not in the type_list, then defined as etl::type_list_npos. + //*************************************************************************** + template + struct type_list_index_of_type + : public etl::integral_constant::value ? 0 : + (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : + type_list_index_of_type::value + 1)> + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + }; + + template + struct type_list_index_of_type, T> + : public etl::integral_constant + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; +#endif + //*************************************************************************** /// Defines a bool constant that is true if the type_list contains the specified type, otherwise false. //*************************************************************************** - template - struct type_list_contains - : public etl::integral_constant::value ? true : type_list_contains::value> + template + struct type_list_contains; + + template + struct type_list_contains, T> + : public etl::integral_constant::value> { }; @@ -217,77 +201,44 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr bool type_list_contains_v = etl::type_list_contains::value; + template + inline constexpr bool type_list_contains_v = etl::type_list_contains::value; #endif - //*************************************************************************** - /// Defines an integral constant that is the index of the specified type in the type_list. - /// If the type is not in the type_list, then defined as etl::type_list_npos. - //*************************************************************************** - template - struct type_list_index_of_type - : public etl::integral_constant::value ? 0 : - (type_list_index_of_type::value == etl::type_list_npos ? etl::type_list_npos : - type_list_index_of_type::value + 1)> - { - }; - - template - struct type_list_index_of_type, T> - : public etl::integral_constant - { - }; - -#if ETL_USING_CPP17 - template - inline constexpr size_t type_list_index_of_v = etl::type_list_index_of_type::value; -#endif - - //*************************************************************************** - /// Defines type as the type found at Index in the type_list. - /// Static asserts if Index is out of range. - //*************************************************************************** - template - struct type_list_type_at_index - { - ETL_STATIC_ASSERT(Index <= type_list_size::value, "etl::type_list_type_at_index out of range"); - - using type = nth_type_t; - }; - - template - using type_list_type_at_index_t = typename type_list_type_at_index::type; - //*************************************************************************** /// Defines an integral constant that is maximum sizeof all types in the type_list. /// If the type_list is empty, then defined as 0. //*************************************************************************** - template - struct type_list_max_sizeof_type - : public etl::integral_constant::value)> + template + struct type_list_max_size; + + template + struct type_list_max_size> + : public etl::integral_constant::size> { }; template <> - struct type_list_max_sizeof_type> + struct type_list_max_size> : public etl::integral_constant { }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_sizeof_type_v = etl::type_list_max_sizeof_type::value; + template + inline constexpr size_t type_list_max_size_v = etl::type_list_max_size::value; #endif //*************************************************************************** /// Defines an integral constant that is maximum alignment all types in the type_list. /// If the type_list is empty, then defined as 1. //*************************************************************************** - template - struct type_list_max_alignment - : public etl::integral_constant::value, - type_list_max_alignment::value)> + template + struct type_list_max_alignment; + + template + struct type_list_max_alignment> + : public etl::integral_constant::alignment> { }; @@ -298,9 +249,44 @@ namespace etl }; #if ETL_USING_CPP17 - template - inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; + template + inline constexpr size_t type_list_max_alignment_v = etl::type_list_max_alignment::value; #endif + + //*************************************************************************** + /// Declares a new type_list by selecting types from a given type_list, according to an index sequence. + //*************************************************************************** + template + struct type_list_select + { + ETL_STATIC_ASSERT((etl::is_base_of, TTypeList>::value), "TTypeList must be an etl::type_list"); + + using type = type_list...>; + }; + + template + using type_list_select_t = typename type_list_select::type; + + //*************************************************************************** + /// Concatenates two or more type_lists. + //*************************************************************************** + template + struct type_list_cat; + + template + struct type_list_cat, etl::type_list, TTail...> + { + using type = typename type_list_cat, TTail...>::type; + }; + + template + struct type_list_cat + { + using type = T; + }; + + template + using type_list_cat_t = typename type_list_cat::type; } #endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2641ab5..498fa7db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,6 +149,7 @@ add_executable(etl_tests test_hfsm.cpp test_hfsm_recurse_to_inner_state_on_start.cpp test_histogram.cpp + test_index_of_type.cpp test_indirect_vector.cpp test_indirect_vector_external_buffer.cpp test_instance_count.cpp diff --git a/test/test_type_list.cpp b/test/test_type_list.cpp index 75c8f322..de9be9fc 100644 --- a/test/test_type_list.cpp +++ b/test/test_type_list.cpp @@ -37,16 +37,6 @@ namespace #if ETL_USING_CPP11 SUITE(test_type_list) { - //************************************************************************* - TEST(test_nth_type) - { - typedef etl::type_list t1; - - CHECK_TRUE((std::is_same::type, char>::value)); - CHECK_TRUE((std::is_same::type, int>::value)); - CHECK_TRUE((std::is_same::type, uint32_t>::value)); - } - //************************************************************************* TEST(test_type_list_select) { @@ -54,6 +44,7 @@ namespace typedef etl::type_list t2; CHECK_TRUE((std::is_same::type, t2>::value)); + CHECK_TRUE((std::is_same, t2>::value)); } //************************************************************************* @@ -61,46 +52,54 @@ namespace { typedef etl::type_list t1; typedef etl::type_list t2; + typedef etl::type_list<> t3; CHECK_EQUAL(etl::type_list_size::value, 3); CHECK_EQUAL(etl::type_list_size::value, 2); + CHECK_EQUAL(etl::type_list_size::value, 0); } //************************************************************************* TEST(test_type_list_cat) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; + typedef etl::type_list<> t3; typedef etl::type_list t_cat1; - typedef etl::type_list t_cat2; + typedef etl::type_list t_cat2; - CHECK_TRUE((std::is_same::type, t_cat1>::value)); - CHECK_FALSE((std::is_same::type, t_cat2>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_TRUE((std::is_same::type, t_cat1>::value)); + CHECK_FALSE((std::is_same::type, t_cat2>::value)); + + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_TRUE((std::is_same, t_cat1>::value)); + CHECK_FALSE((std::is_same, t_cat2>::value)); } //************************************************************************* TEST(test_type_list_contains) { typedef etl::type_list t1; - typedef etl::type_list t2; + typedef etl::type_list t2; typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); - CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); + CHECK_TRUE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); CHECK_FALSE((etl::type_list_contains::value)); #if ETL_USING_CPP17 - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); - CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); + CHECK_TRUE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); CHECK_FALSE((etl::type_list_contains_v)); #endif @@ -147,16 +146,16 @@ namespace typedef etl::type_list t3; typedef etl::type_list<> t4; - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 2); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 4); - CHECK_EQUAL(etl::type_list_max_sizeof_type::value, 0); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 2); + CHECK_EQUAL(etl::type_list_max_size::value, 4); + CHECK_EQUAL(etl::type_list_max_size::value, 0); #if ETL_USING_CPP17 - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 2); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 4); - CHECK_EQUAL((etl::type_list_max_sizeof_type_v), 0); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 2); + CHECK_EQUAL((etl::type_list_max_size_v), 4); + CHECK_EQUAL((etl::type_list_max_size_v), 0); #endif } diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index b796f072..808b085a 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3169,6 +3169,7 @@ + @@ -8477,6 +8478,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index d5ff0eef..f778794a 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1431,6 +1431,9 @@ ETL\Utilities + + ETL\Utilities + @@ -3434,6 +3437,9 @@ Tests\Types + + Tests\Types + From 3360eae62d8a9a352c9e704453d11a6a9d56f876 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Mar 2025 19:09:41 +0000 Subject: [PATCH 7/7] Modified etl::variant_variadic to use etl::type_list in place of etl::parameter_pack --- include/etl/private/variant_variadic.h | 121 +++++-------------------- 1 file changed, 23 insertions(+), 98 deletions(-) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 44334669..6874f7f9 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -31,13 +31,14 @@ SOFTWARE. #include "../platform.h" #include "../utility.h" #include "../largest.h" +#include "../nth_type.h" #include "../exception.h" #include "../type_traits.h" #include "../integral_limits.h" #include "../static_assert.h" #include "../alignment.h" #include "../error_handler.h" -#include "../parameter_pack.h" +#include "../type_list.h" #include "../placement_new.h" #include "../visitor.h" #include "../memory.h" @@ -66,82 +67,6 @@ namespace etl { namespace private_variant { - //*************************************************************************** - // This is a copy of the normal etl::parameter_pack, but without the static_assert - // so that the C++11 versions of do_visitor() & do_operator() do not throw a compile time error. - //*************************************************************************** - template - class parameter_pack - { - public: - - static constexpr size_t size = sizeof...(TTypes); - - //*************************************************************************** - /// index_of_type - //*************************************************************************** - template - class index_of_type - { - private: - - using type = etl::remove_cvref_t; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_type_helper::value; - }; - - //*********************************** - template - struct index_of_type_helper - { - static constexpr size_t value = 1UL; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in parameter pack"); - - /// The index value. - static constexpr size_t value = index_of_type_helper::value - 1; - }; - - //*************************************************************************** - /// type_from_index - //*************************************************************************** - template - class type_from_index - { - private: - - //*********************************** - template - struct type_from_index_helper - { - using type = typename etl::conditional::type>::type; - }; - - //*********************************** - template - struct type_from_index_helper - { - using type = T1; - }; - - public: - - /// Template alias - using type = typename type_from_index_helper::type; - }; - - //*********************************** - template - using type_from_index_t = typename type_from_index::type; - }; - //******************************************* // The traits an object may have. //******************************************* @@ -327,7 +252,7 @@ namespace etl template struct variant_alternative> { - using type = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type = nth_type_t; }; template @@ -529,13 +454,13 @@ namespace etl // Get the index of a type. //******************************************* template - using index_of_type = typename etl::private_variant::parameter_pack::template index_of_type>; + using index_of_type = etl::type_list_index_of_type, etl::remove_cvref_t>; //******************************************* // Get the type from the index. //******************************************* template - using type_from_index = typename etl::private_variant::parameter_pack::template type_from_index::type; + using type_from_index = typename etl::type_list_type_at_index, Index>::type; public: @@ -546,7 +471,7 @@ namespace etl #include "diagnostic_uninitialized_push.h" ETL_CONSTEXPR14 variant() { - using type = typename etl::private_variant::parameter_pack::template type_from_index<0U>::type; + using type = type_from_index<0U>; default_construct_in_place(data); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; @@ -592,7 +517,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, etl::forward(args)...); @@ -625,7 +550,7 @@ namespace etl ETL_CONSTEXPR14 explicit variant(etl::in_place_index_t, std::initializer_list init, TArgs&&... args) : type_id(Index) { - using type = typename private_variant::parameter_pack:: template type_from_index_t; + using type = type_from_index; static_assert(etl::is_one_of ::value, "Unsupported type"); construct_in_place_args(data, init, etl::forward(args)...); @@ -715,7 +640,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -737,7 +662,7 @@ namespace etl operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *static_cast(data); } @@ -747,9 +672,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(TArgs&&... args) + typename etl::variant_alternative>::type& emplace(TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -769,9 +694,9 @@ namespace etl /// Emplace by index with variadic constructor parameters. //*************************************************************************** template - typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) + typename etl::variant_alternative>::type& emplace(std::initializer_list il, TArgs&&... args) { - static_assert(Index < etl::private_variant::parameter_pack::size, "Index out of range"); + static_assert(Index < sizeof...(TTypes), "Index out of range"); using type = type_from_index; @@ -803,7 +728,7 @@ namespace etl construct_in_place(data, etl::forward(value)); operation = operation_type::value, etl::is_move_constructible::value>::do_operation; - type_id = etl::private_variant::parameter_pack::template index_of_type::value; + type_id = index_of_type::value; return *this; } @@ -896,7 +821,7 @@ namespace etl template (), int> = 0> constexpr bool is_type() const noexcept { - return (type_id == etl::private_variant::parameter_pack::template index_of_type::value); + return (type_id == index_of_type::value); } //*************************************************************************** @@ -1469,7 +1394,7 @@ namespace etl template ETL_CONSTEXPR14 bool holds_alternative(const etl::variant& v) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return (Index == variant_npos) ? false : (v.index() == Index); } @@ -1560,7 +1485,7 @@ namespace etl template ETL_CONSTEXPR14 T& get(etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1569,7 +1494,7 @@ namespace etl template ETL_CONSTEXPR14 T&& get(etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1578,7 +1503,7 @@ namespace etl template ETL_CONSTEXPR14 const T& get(const etl::variant& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(v); } @@ -1587,7 +1512,7 @@ namespace etl template ETL_CONSTEXPR14 const T&& get(const etl::variant&& v) { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; return get(etl::move(v)); } @@ -1628,7 +1553,7 @@ namespace etl template< class T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) { @@ -1644,7 +1569,7 @@ namespace etl template< typename T, typename... TTypes > ETL_CONSTEXPR14 etl::add_pointer_t get_if(const etl::variant* pv) noexcept { - constexpr size_t Index = etl::private_variant::parameter_pack::template index_of_type::value; + constexpr size_t Index = etl::type_list_index_of_type, T>::value; if ((pv != nullptr) && (pv->index() == Index)) {