Make functions for containers

This commit is contained in:
John Wellbelove 2021-11-13 13:19:52 +00:00
parent 792cc0b57d
commit e296bd24f7
27 changed files with 162 additions and 59 deletions

View File

@ -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.

View File

@ -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 <initializer_list>

View File

@ -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 <initializer_list>

View File

@ -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 <initializer_list>

View File

@ -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 <initializer_list>

View File

@ -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"

View File

@ -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"

View File

@ -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"

66
include/etl/nth_type.h Normal file
View File

@ -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 <size_t N, typename T1, typename... TRest>
struct nth_type_helper
{
using type = typename nth_type_helper<N - 1U, TRest...>::type;
};
template <size_t N, typename T1>
struct nth_type_helper<N, T1>
{
using type = T1;
};
}
template <size_t N, typename... TTypes>
struct nth_type
{
using type = typename private_nth_type::nth_type_helper<N, TTypes...>::type;
};
template <size_t N, typename... TTypes>
using nth_type_t = typename nth_type<N, TTypes...>::type;
#endif
}
#endif

View File

@ -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"

View File

@ -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
{

View File

@ -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"

View File

@ -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"

View File

@ -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 <initializer_list>

View File

@ -213,33 +213,6 @@ namespace etl
using type_from_type_t = typename type_from_type<T>::type;
};
//***************************************************************************
// nth_type
//***************************************************************************
namespace private_nth_type
{
template <size_t N, typename T1, typename... TRest>
struct nth_type_helper
{
using type = typename nth_type_helper<N - 1U, TRest...>::type;
};
template <size_t N, typename T1>
struct nth_type_helper<N, T1>
{
using type = T1;
};
}
template <size_t N, typename... TTypes>
struct nth_type
{
using type = typename private_nth_type::nth_type_helper<N, TTypes...>::type;
};
template <size_t N, typename... TTypes>
using nth_type_t = typename nth_type<N, TTypes...>::type;
#else
//***************************************************************************

View File

@ -79,12 +79,16 @@ namespace etl
using type = typename type_select_helper<ID, 0, TTypes...>::type;
};
#if ETL_CPP11_SUPPORTED
template <size_t ID>
using select_t = typename select<ID>::type;
#endif
};
//***************************************************************************
// Select type alias
//***************************************************************************
template <size_t N, typename... TTypes>
using type_select_t = typename etl::type_select<TTypes...>:: template select_t<N>;
#else
//***************************************************************************

View File

@ -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 <b>true</b> if the arrays are equal, otherwise <b>false</b>
///\ingroup unordered_map
//***************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare>
bool operator ==(const etl::iunordered_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iunordered_map<TKey, TMapped, TKeyCompare>& rhs)
template <typename TKey, typename T, typename TKeyCompare>
bool operator ==(const etl::iunordered_map<TKey, T, TKeyCompare>& lhs, const etl::iunordered_map<TKey, T, TKeyCompare>& rhs)
{
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
}
@ -1504,8 +1504,8 @@ namespace etl
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
///\ingroup unordered_map
//***************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare>
bool operator !=(const etl::iunordered_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iunordered_map<TKey, TMapped, TKeyCompare>& rhs)
template <typename TKey, typename T, typename TKeyCompare>
bool operator !=(const etl::iunordered_map<TKey, T, TKeyCompare>& lhs, const etl::iunordered_map<TKey, T, TKeyCompare>& rhs)
{
return !(lhs == rhs);
}
@ -1643,8 +1643,8 @@ namespace etl
/// Make
//*************************************************************************
#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST
template <typename TKey, typename TMapped, typename... TPairs>
constexpr auto make_unordered_map(TPairs&&... pairs) -> etl::unordered_map<TKey, TMapped, sizeof...(TPairs)>
template <typename TKey, typename T, typename THash = etl::hash<TKey>, typename TKeyEqual = etl::equal_to<TKey>, typename... TPairs>
constexpr auto make_unordered_map(TPairs&&... pairs) -> etl::unordered_map<TKey, T, sizeof...(TPairs), sizeof...(TPairs), THash, TKeyEqual>
{
return { {etl::forward<TPairs>(pairs)...} };
}

View File

@ -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 <typename TKey, typename TMapped, typename... TPairs>
constexpr auto make_unordered_multimap(TPairs&&... pairs) -> etl::unordered_multimap<TKey, TMapped, sizeof...(TPairs)>
template <typename TKey, typename T, typename THash = etl::hash<TKey>, typename TKeyEqual = etl::equal_to<TKey>, typename... TPairs>
constexpr auto make_unordered_multimap(TPairs&&... pairs) -> etl::unordered_multimap<TKey, T, sizeof...(TPairs), sizeof...(TPairs), THash, TKeyEqual>
{
return { {etl::forward<TPairs>(pairs)...} };
}

View File

@ -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 <typename TKey, typename... T>
constexpr auto make_unordered_multiset(T&&... keys) -> etl::unordered_multiset<TKey, sizeof...(T)>
template <typename TKey, typename THash = etl::hash<TKey>, typename TKeyEqual = etl::equal_to<TKey>, typename... T>
constexpr auto make_unordered_multiset(T&&... keys) -> etl::unordered_multiset<TKey, sizeof...(T), sizeof...(T), THash, TKeyEqual>
{
return { {etl::forward<T>(keys)...} };
}

View File

@ -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 <typename TKey, typename... T>
constexpr auto make_unordered_set(T&&... keys) -> etl::unordered_set<TKey, sizeof...(T)>
template <typename TKey, typename THash = etl::hash<TKey>, typename TKeyEqual = etl::equal_to<TKey>, typename... T>
constexpr auto make_unordered_set(T&&... keys) -> etl::unordered_set<TKey, sizeof...(T), sizeof...(T), THash, TKeyEqual>
{
return { {etl::forward<T>(keys)...} };
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <etl/nth_type.h>

View File

@ -1822,6 +1822,7 @@
<ClInclude Include="..\..\include\etl\mutex\mutex_cmsis_os2.h" />
<ClInclude Include="..\..\include\etl\mutex\mutex_freertos.h" />
<ClInclude Include="..\..\include\etl\negative.h" />
<ClInclude Include="..\..\include\etl\nth_type.h" />
<ClInclude Include="..\..\include\etl\overload.h" />
<ClInclude Include="..\..\include\etl\placement_new.h" />
<ClInclude Include="..\..\include\etl\null_type.h" />
@ -5634,6 +5635,26 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sanity-check\nth_type.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Small Strings|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - Appveyor|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MSVC Debug - No STL - Appveyor|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No Unit Tests|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug64|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - String Truncation Is Error|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug - No STL - Force No Advanced|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force cpp03|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No Checks|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - Force C++03|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\sanity-check\nullptr.h.t.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC - No STL - Built-ins|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug LLVM|Win32'">true</ExcludedFromBuild>

View File

@ -1161,6 +1161,9 @@
<ClInclude Include="..\..\include\etl\multi_span.h">
<Filter>ETL\Containers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\nth_type.h">
<Filter>ETL\Utilities</Filter>
</ClInclude>
<ClInclude Include="..\..\include\etl\profiles\determine_builtin_support.h">
<Filter>ETL\Profiles</Filter>
</ClInclude>
@ -3044,6 +3047,9 @@
<ClCompile Include="..\sanity-check\multi_span.h.t.cpp">
<Filter>Source Files\Sanity Checks</Filter>
</ClCompile>
<ClCompile Include="..\sanity-check\nth_type.h.t.cpp">
<Filter>Source Files\Sanity Checks</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\library.properties">
@ -3197,4 +3203,4 @@
<Filter>Resource Files</Filter>
</Natvis>
</ItemGroup>
</Project>
</Project>