diff --git a/.gitignore b/.gitignore index b5c756a6..4bb62e0c 100644 --- a/.gitignore +++ b/.gitignore @@ -255,3 +255,4 @@ unittest-cpp build-test-Desktop_x86_windows_msvc2017_pe_32bit-Debug test/Logs build-test-Desktop_x86_windows_msvc2019_pe_32bit-Debug +test/vs2019/.vs diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index a7520b8b..81196e02 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1555,42 +1555,6 @@ namespace etl #if ETL_CPP17_SUPPORTED template inline constexpr size_t size_of_v = etl::size_of::value; -#endif - - //*************************************************************************** - /// index_of - //*************************************************************************** -#if ETL_CPP11_SUPPORTED - template - class index_of - { - private: - - //*********************************** - template - struct index_of_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_helper::value; - }; - - //*********************************** - template - struct index_of_helper - { - static constexpr size_t value = 1; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in typelist"); - - static constexpr size_t value = index_of_helper::value - 1; - }; - -#if ETL_CPP17_SUPPORTED - template - inline constexpr size_t index_of_v = index_of::value; -#endif #endif } diff --git a/include/etl/parameter_pack.h b/include/etl/parameter_pack.h new file mode 100644 index 00000000..ab155aaf --- /dev/null +++ b/include/etl/parameter_pack.h @@ -0,0 +1,124 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2017 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_PARAMETER_PACK +#define ETL_PARAMETER_PACK + +#include + +#include "platform.h" +#include "type_traits.h" + +#if ETL_CPP11_NOT_SUPPORTED + #error NOT SUPPORTED FOR C++03 OR BELOW +#else + +namespace etl +{ + //*************************************************************************** + /// parameter_pack + //*************************************************************************** + template + class parameter_pack + { + public: + + static constexpr size_t size = sizeof...(TTypes); + + //*************************************************************************** + /// index_of_type + //*************************************************************************** + template + class index_of_type + { + private: + + //*********************************** + template + struct index_of_type_helper + { + static constexpr size_t value = std::is_same::value ? 1 : 1 + index_of_type_helper::value; + }; + + //*********************************** + template + struct index_of_type_helper + { + static constexpr size_t value = 1; + }; + + public: + + static_assert(etl::is_one_of::value, "T is not in parameter pack"); + + /// The idex value. + static constexpr size_t value = index_of_type_helper::value - 1; + }; + +#if ETL_CPP17_SUPPORTED + template + static constexpr size_t index_of_type_v = index_of_type::value; +#endif + + //*************************************************************************** + /// type_from_index + //*************************************************************************** + template + class type_from_index + { + private: + + //*********************************** + template + struct type_from_index_helper + { + using type = typename std::conditional::type>::type; + }; + + //*********************************** + template + struct type_from_index_helper + { + using type = T1; + }; + + public: + + static_assert(I < sizeof...(TTypes), "Index out of bounds of parameter pack"); + + /// Template alias + using type = typename type_from_index_helper::type; + }; + + //*********************************** + template + using type_from_index_t = typename type_from_index::type; + }; +} +#endif +#endif diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index bf83e968..b4475a5a 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -1548,42 +1548,6 @@ namespace etl #if ETL_CPP17_SUPPORTED template inline constexpr size_t size_of_v = etl::size_of::value; -#endif - - //*************************************************************************** - /// index_of - //*************************************************************************** -#if ETL_CPP11_SUPPORTED - template - class index_of - { - private: - - //*********************************** - template - struct index_of_helper - { - static constexpr size_t value = etl::is_same::value ? 1 : 1 + index_of_helper::value; - }; - - //*********************************** - template - struct index_of_helper - { - static constexpr size_t value = 1; - }; - - public: - - static_assert(etl::is_one_of::value, "T is not in typelist"); - - static constexpr size_t value = index_of_helper::value - 1; - }; - -#if ETL_CPP17_SUPPORTED - template - inline constexpr size_t index_of_v = index_of::value; -#endif #endif } diff --git a/include/etl/version.h b/include/etl/version.h index e52d6e29..129be118 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 2 +#define ETL_VERSION_MINOR 3 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index e6e741bb..3cc77423 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.2.0", + "version": "18.3.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index a2c2b42f..50f72707 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.2.0 +version=18.3.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 3db2bbef..8c07ddce 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +18.3.0 +Added etl::parameter_pack to easily extract information about the types in a +template parameter pack. + =============================================================================== 18.2.0 Variadic versions of etl::type_id_lookup and etl::type_type_lookup for C++11 and above. diff --git a/test/test_parameter_pack.cpp b/test/test_parameter_pack.cpp new file mode 100644 index 00000000..078a1cf7 --- /dev/null +++ b/test/test_parameter_pack.cpp @@ -0,0 +1,64 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++/UnitTest++.h" +#include "ExtraCheckMacros.h" + +#include "etl/parameter_pack.h" + +#include + +namespace +{ + using Pack = etl::parameter_pack; + + SUITE(test_type_lookup) + { + //************************************************************************* + TEST(test_index_of_type) + { + CHECK_EQUAL(0U, Pack::index_of_type_v); + CHECK_EQUAL(1U, Pack::index_of_type_v); + CHECK_EQUAL(2U, Pack::index_of_type_v); + + // Static assert + //CHECK_EQUAL(0U, Pack::index_of_type_v); + } + + //************************************************************************* + TEST(test_type_from_index) + { + CHECK((std::is_same_v>)); + CHECK((std::is_same_v>)); + CHECK((std::is_same_v>)); + + // Static assert + //CHECK((std::is_same_v>)); + } + }; +} diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index c2ab7677..f980b3da 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1054,6 +1054,7 @@ + @@ -1582,6 +1583,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index aba45339..c727bd0d 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -852,6 +852,9 @@ ETL\Containers\Generators + + ETL\Utilities + @@ -1325,6 +1328,9 @@ Source Files + + Source Files +