/****************************************************************************** The MIT License(MIT) Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com Copyright(c) 2017 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_PARAMETER_PACK #define ETL_PARAMETER_PACK #include "platform.h" #include "type_traits.h" #include #if ETL_CPP11_NOT_SUPPORTED #if !defined(ETL_IN_UNIT_TEST) #error NOT SUPPORTED FOR C++03 OR BELOW #endif #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 = etl::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 index value. static constexpr size_t value = index_of_type_helper::value - 1; }; #if ETL_USING_CPP17 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 etl::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; }; //*********************************** template using parameter_pack_t = typename etl::parameter_pack::template type_from_index_t; //*********************************** template constexpr size_t parameter_pack::size; #if ETL_USING_CPP17 template inline constexpr size_t parameter_pack_v = etl::parameter_pack::template index_of_type::value; #endif #if ETL_USING_CPP17 && (!ETL_USING_GCC_COMPILER || (__GNUC__ > 7)) //*********************************** template template constexpr size_t parameter_pack::template index_of_type::value; #else //*********************************** template template constexpr size_t parameter_pack::index_of_type::value; #endif } #endif #endif