From e296bd24f720918d3150f074ae22e41cbd854b83 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 13 Nov 2021 13:19:52 +0000 Subject: [PATCH] Make functions for containers --- include/etl/array.h | 2 +- include/etl/flat_map.h | 2 +- include/etl/flat_multimap.h | 2 +- include/etl/flat_multiset.h | 2 +- include/etl/flat_set.h | 2 +- include/etl/map.h | 2 +- include/etl/multimap.h | 2 +- include/etl/multiset.h | 2 +- include/etl/nth_type.h | 66 ++++++++++++++++++++++++++ include/etl/reference_flat_map.h | 2 +- include/etl/reference_flat_multimap.h | 2 +- include/etl/reference_flat_multiset.h | 2 +- include/etl/reference_flat_set.h | 2 +- include/etl/set.h | 2 +- include/etl/type_lookup.h | 27 ----------- include/etl/type_select.h | 8 +++- include/etl/unordered_map.h | 14 +++--- include/etl/unordered_multimap.h | 6 +-- include/etl/unordered_multiset.h | 6 +-- include/etl/unordered_set.h | 6 +-- test/sanity-check/c++03/CMakeLists.txt | 1 + test/sanity-check/c++11/CMakeLists.txt | 1 + test/sanity-check/c++14/CMakeLists.txt | 1 + test/sanity-check/c++17/CMakeLists.txt | 1 + test/sanity-check/nth_type.h.t.cpp | 29 +++++++++++ test/vs2019/etl.vcxproj | 21 ++++++++ test/vs2019/etl.vcxproj.filters | 8 +++- 27 files changed, 162 insertions(+), 59 deletions(-) create mode 100644 include/etl/nth_type.h create mode 100644 test/sanity-check/nth_type.h.t.cpp diff --git a/include/etl/array.h b/include/etl/array.h index 23ce5d7b..9906b6ef 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -43,7 +43,7 @@ SOFTWARE. #include "parameter_type.h" #include "static_assert.h" #include "error_handler.h" -#include "type_lookup.h" +#include "nth_type.h" ///\defgroup array array /// A replacement for std::array if you haven't got C++0x11. diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index ee15d842..14f469ac 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_map.h" #include "pool.h" #include "placement_new.h" -#include "type_lookup.h" +#include "nth_type.h" #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL #include diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index e1f8fcf7..17be8d52 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -36,7 +36,7 @@ SOFTWARE. #include "pool.h" #include "utility.h" #include "placement_new.h" -#include "type_lookup.h" +#include "nth_type.h" #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL #include diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index cbfcb8d6..956f3e3f 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_multiset.h" #include "pool.h" #include "placement_new.h" -#include "type_lookup.h" +#include "nth_type.h" #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL #include diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index 83a15b56..32844f0a 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -35,7 +35,7 @@ SOFTWARE. #include "reference_flat_set.h" #include "pool.h" #include "placement_new.h" -#include "type_lookup.h" +#include "nth_type.h" #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL #include diff --git a/include/etl/map.h b/include/etl/map.h index 94f27d9c..4398de9e 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -43,7 +43,7 @@ SOFTWARE. #include "debug_count.h" #include "nullptr.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "iterator.h" #include "utility.h" diff --git a/include/etl/multimap.h b/include/etl/multimap.h index 17e06b19..5d049adb 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -43,7 +43,7 @@ SOFTWARE. #include "debug_count.h" #include "nullptr.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "iterator.h" #include "utility.h" diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 7841fecb..15d84251 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -44,7 +44,7 @@ SOFTWARE. #include "debug_count.h" #include "nullptr.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "utility.h" #include "placement_new.h" diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h new file mode 100644 index 00000000..95e8d4f7 --- /dev/null +++ b/include/etl/nth_type.h @@ -0,0 +1,66 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2021 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_NTH_TYPE_INCLUDED +#define ETL_NTH_TYPE_INCLUDED + +#include "platform.h" + +namespace etl +{ +#if ETL_CPP11_SUPPORTED + //*************************************************************************** + // nth_type + //*************************************************************************** + namespace private_nth_type + { + template + struct nth_type_helper + { + using type = typename nth_type_helper::type; + }; + + template + struct nth_type_helper + { + using type = T1; + }; + } + + template + struct nth_type + { + using type = typename private_nth_type::nth_type_helper::type; + }; + + template + using nth_type_t = typename nth_type::type; +#endif +} + +#endif diff --git a/include/etl/reference_flat_map.h b/include/etl/reference_flat_map.h index 5e5d1efa..c3a1b45c 100644 --- a/include/etl/reference_flat_map.h +++ b/include/etl/reference_flat_map.h @@ -38,7 +38,7 @@ SOFTWARE. #include "error_handler.h" #include "debug_count.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "exception.h" #include "static_assert.h" diff --git a/include/etl/reference_flat_multimap.h b/include/etl/reference_flat_multimap.h index 0e4c2643..de67f5c6 100644 --- a/include/etl/reference_flat_multimap.h +++ b/include/etl/reference_flat_multimap.h @@ -39,7 +39,7 @@ SOFTWARE. #include "debug_count.h" #include "vector.h" #include "iterator.h" -#include "type_lookup.h" +#include "nth_type.h" namespace etl { diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 3aa3dff9..1343c994 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -40,7 +40,7 @@ SOFTWARE. #include "functional.h" #include "utility.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "vector.h" #include "pool.h" #include "error_handler.h" diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index 1e75f15c..08585415 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -40,7 +40,7 @@ SOFTWARE. #include "functional.h" #include "utility.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "pool.h" #include "error_handler.h" #include "exception.h" diff --git a/include/etl/set.h b/include/etl/set.h index ded5d553..a06adff4 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -47,7 +47,7 @@ SOFTWARE. #include "iterator.h" #include "functional.h" #include "placement_new.h" -#include "type_lookup.h" +#include "nth_type.h" #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL #include diff --git a/include/etl/type_lookup.h b/include/etl/type_lookup.h index 7f20826f..f870f22d 100644 --- a/include/etl/type_lookup.h +++ b/include/etl/type_lookup.h @@ -213,33 +213,6 @@ namespace etl using type_from_type_t = typename type_from_type::type; }; - //*************************************************************************** - // nth_type - //*************************************************************************** - namespace private_nth_type - { - template - struct nth_type_helper - { - using type = typename nth_type_helper::type; - }; - - template - struct nth_type_helper - { - using type = T1; - }; - } - - template - struct nth_type - { - using type = typename private_nth_type::nth_type_helper::type; - }; - - template - using nth_type_t = typename nth_type::type; - #else //*************************************************************************** diff --git a/include/etl/type_select.h b/include/etl/type_select.h index 3044f5e6..6e32603b 100644 --- a/include/etl/type_select.h +++ b/include/etl/type_select.h @@ -79,12 +79,16 @@ namespace etl using type = typename type_select_helper::type; }; -#if ETL_CPP11_SUPPORTED template using select_t = typename select::type; -#endif }; + //*************************************************************************** + // Select type alias + //*************************************************************************** + template + using type_select_t = typename etl::type_select:: template select_t; + #else //*************************************************************************** diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 428c9ef9..37c74d2f 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -43,7 +43,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "hash.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "nullptr.h" #include "vector.h" @@ -1491,8 +1491,8 @@ namespace etl ///\return true if the arrays are equal, otherwise false ///\ingroup unordered_map //*************************************************************************** - template - bool operator ==(const etl::iunordered_map& lhs, const etl::iunordered_map& rhs) + template + bool operator ==(const etl::iunordered_map& lhs, const etl::iunordered_map& rhs) { return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); } @@ -1504,8 +1504,8 @@ namespace etl ///\return true if the arrays are not equal, otherwise false ///\ingroup unordered_map //*************************************************************************** - template - bool operator !=(const etl::iunordered_map& lhs, const etl::iunordered_map& rhs) + template + bool operator !=(const etl::iunordered_map& lhs, const etl::iunordered_map& rhs) { return !(lhs == rhs); } @@ -1643,8 +1643,8 @@ namespace etl /// Make //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST - template - constexpr auto make_unordered_map(TPairs&&... pairs) -> etl::unordered_map + template , typename TKeyEqual = etl::equal_to, typename... TPairs> + constexpr auto make_unordered_map(TPairs&&... pairs) -> etl::unordered_map { return { {etl::forward(pairs)...} }; } diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 33e67851..d6c8c213 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -43,7 +43,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "hash.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "nullptr.h" #include "pool.h" @@ -1554,8 +1554,8 @@ namespace etl /// Make //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST - template - constexpr auto make_unordered_multimap(TPairs&&... pairs) -> etl::unordered_multimap + template , typename TKeyEqual = etl::equal_to, typename... TPairs> + constexpr auto make_unordered_multimap(TPairs&&... pairs) -> etl::unordered_multimap { return { {etl::forward(pairs)...} }; } diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index f5642fc8..af2f64c2 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -43,7 +43,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "hash.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "nullptr.h" #include "error_handler.h" @@ -1538,8 +1538,8 @@ namespace etl /// Make //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST - template - constexpr auto make_unordered_multiset(T&&... keys) -> etl::unordered_multiset + template , typename TKeyEqual = etl::equal_to, typename... T> + constexpr auto make_unordered_multiset(T&&... keys) -> etl::unordered_multiset { return { {etl::forward(keys)...} }; } diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 739745a4..5aecc5e2 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -43,7 +43,7 @@ SOFTWARE. #include "intrusive_forward_list.h" #include "hash.h" #include "type_traits.h" -#include "type_lookup.h" +#include "nth_type.h" #include "parameter_type.h" #include "nullptr.h" #include "error_handler.h" @@ -1536,8 +1536,8 @@ namespace etl /// Make //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST - template - constexpr auto make_unordered_set(T&&... keys) -> etl::unordered_set + template , typename TKeyEqual = etl::equal_to, typename... T> + constexpr auto make_unordered_set(T&&... keys) -> etl::unordered_set { return { {etl::forward(keys)...} }; } diff --git a/test/sanity-check/c++03/CMakeLists.txt b/test/sanity-check/c++03/CMakeLists.txt index 138bcd3b..a4508648 100644 --- a/test/sanity-check/c++03/CMakeLists.txt +++ b/test/sanity-check/c++03/CMakeLists.txt @@ -186,6 +186,7 @@ target_sources(t98 PRIVATE etl_profile.h ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp + ../nth_type.h.t.cpp ../nullptr.h.t.cpp ../null_type.h.t.cpp ../numeric.h.t.cpp diff --git a/test/sanity-check/c++11/CMakeLists.txt b/test/sanity-check/c++11/CMakeLists.txt index 5dbe8524..36e7aab4 100644 --- a/test/sanity-check/c++11/CMakeLists.txt +++ b/test/sanity-check/c++11/CMakeLists.txt @@ -186,6 +186,7 @@ target_sources(t11 PRIVATE etl_profile.h ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp + ../nth_type.h.t.cpp ../nullptr.h.t.cpp ../null_type.h.t.cpp ../numeric.h.t.cpp diff --git a/test/sanity-check/c++14/CMakeLists.txt b/test/sanity-check/c++14/CMakeLists.txt index 6ff4a4cd..1db39c6c 100644 --- a/test/sanity-check/c++14/CMakeLists.txt +++ b/test/sanity-check/c++14/CMakeLists.txt @@ -186,6 +186,7 @@ target_sources(t14 PRIVATE etl_profile.h ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp + ../nth_type.h.t.cpp ../nullptr.h.t.cpp ../null_type.h.t.cpp ../numeric.h.t.cpp diff --git a/test/sanity-check/c++17/CMakeLists.txt b/test/sanity-check/c++17/CMakeLists.txt index b4ebe927..28452df4 100644 --- a/test/sanity-check/c++17/CMakeLists.txt +++ b/test/sanity-check/c++17/CMakeLists.txt @@ -186,6 +186,7 @@ target_sources(t17 PRIVATE etl_profile.h ../murmur3.h.t.cpp ../mutex.h.t.cpp ../negative.h.t.cpp + ../nth_type.h.t.cpp ../nullptr.h.t.cpp ../null_type.h.t.cpp ../numeric.h.t.cpp diff --git a/test/sanity-check/nth_type.h.t.cpp b/test/sanity-check/nth_type.h.t.cpp new file mode 100644 index 00000000..6a52bdfa --- /dev/null +++ b/test/sanity-check/nth_type.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) 2021 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/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 247bc8bb..12d12b00 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1822,6 +1822,7 @@ + @@ -5634,6 +5635,26 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true + true true diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index ec435238..ab977681 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1161,6 +1161,9 @@ ETL\Containers + + ETL\Utilities + ETL\Profiles @@ -3044,6 +3047,9 @@ Source Files\Sanity Checks + + Source Files\Sanity Checks + @@ -3197,4 +3203,4 @@ Resource Files - \ No newline at end of file +