mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-16 00:46:03 +08:00
# Conflicts: # include/etl/array.h # include/etl/basic_string.h # include/etl/circular_buffer.h # include/etl/deque.h # include/etl/file_error_numbers.h # include/etl/forward_list.h # include/etl/indirect_vector.h # include/etl/intrusive_forward_list.h # include/etl/intrusive_list.h # include/etl/limits.h # include/etl/list.h # include/etl/private/minmax_pop.h # include/etl/private/minmax_push.h # include/etl/string.h # include/etl/string_view.h # include/etl/u16string.h # include/etl/u32string.h # include/etl/unordered_multimap.h # include/etl/vector.h # include/etl/version.h # include/etl/wstring.h # library.json # library.properties # support/Release notes.txt # test/test_atomic_clang_sync.cpp
126 lines
4.0 KiB
C++
126 lines
4.0 KiB
C++
/******************************************************************************
|
|
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 <stdint.h>
|
|
|
|
#include "platform.h"
|
|
#include "type_traits.h"
|
|
|
|
#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 <typename... TTypes>
|
|
class parameter_pack
|
|
{
|
|
public:
|
|
|
|
static constexpr size_t size = sizeof...(TTypes);
|
|
|
|
//***************************************************************************
|
|
/// index_of_type
|
|
//***************************************************************************
|
|
template <typename T>
|
|
class index_of_type
|
|
{
|
|
private:
|
|
|
|
//***********************************
|
|
template <typename Type, typename T1, typename... TRest>
|
|
struct index_of_type_helper
|
|
{
|
|
static constexpr size_t value = etl::is_same<Type, T1>::value ? 1 : 1 + index_of_type_helper<Type, TRest...>::value;
|
|
};
|
|
|
|
//***********************************
|
|
template <typename Type, typename T1>
|
|
struct index_of_type_helper<Type, T1>
|
|
{
|
|
static constexpr size_t value = 1;
|
|
};
|
|
|
|
public:
|
|
|
|
static_assert(etl::is_one_of<T, TTypes...>::value, "T is not in parameter pack");
|
|
|
|
/// The idex value.
|
|
static constexpr size_t value = index_of_type_helper<T, TTypes...>::value - 1;
|
|
};
|
|
|
|
#if ETL_CPP17_SUPPORTED
|
|
template <typename T>
|
|
static constexpr size_t index_of_type_v = index_of_type<T>::value;
|
|
#endif
|
|
|
|
//***************************************************************************
|
|
/// type_from_index
|
|
//***************************************************************************
|
|
template <size_t I>
|
|
class type_from_index
|
|
{
|
|
private:
|
|
|
|
//***********************************
|
|
template <size_t II, size_t N, typename T1, typename... TRest>
|
|
struct type_from_index_helper
|
|
{
|
|
using type = typename etl::conditional<II == N, T1, typename type_from_index_helper<II, N + 1, TRest...>::type>::type;
|
|
};
|
|
|
|
//***********************************
|
|
template <size_t II, size_t N, typename T1>
|
|
struct type_from_index_helper<II, N, T1>
|
|
{
|
|
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<I, 0, TTypes...>::type;
|
|
};
|
|
|
|
//***********************************
|
|
template <size_t I>
|
|
using type_from_index_t = typename type_from_index<I>::type;
|
|
};
|
|
}
|
|
#endif
|
|
#endif
|