Core/TypeList: Add Apply, Empty and Size operations
This commit is contained in:
parent
1a1e16e9df
commit
7cd772a254
|
|
@ -18,6 +18,9 @@ namespace Nz
|
|||
template<typename, typename>
|
||||
struct ListAppend;
|
||||
|
||||
template<typename, template<typename> typename>
|
||||
struct ListApply;
|
||||
|
||||
template<typename, std::size_t>
|
||||
struct ListAt;
|
||||
|
||||
|
|
@ -33,6 +36,9 @@ namespace Nz
|
|||
template<typename, typename>
|
||||
struct ListPrepend;
|
||||
|
||||
template<typename>
|
||||
struct ListSize;
|
||||
|
||||
template<typename, typename>
|
||||
struct ListUnique;
|
||||
}
|
||||
|
|
@ -40,12 +46,18 @@ namespace Nz
|
|||
template<typename List, typename NewType>
|
||||
using TypeListAppend = typename Detail::ListAppend<List, NewType>::Result;
|
||||
|
||||
template<typename List, template<typename> typename Functor, typename... Args>
|
||||
void TypeListApply(Args&&... args);
|
||||
|
||||
template<typename List, std::size_t Index>
|
||||
using TypeListAt = typename Detail::ListAt<List, Index>::Type;
|
||||
|
||||
template<typename FirstList, typename SecondList>
|
||||
using TypeListConcat = typename Detail::ListConcat<FirstList, SecondList>::Result;
|
||||
|
||||
template<typename List>
|
||||
constexpr bool TypeListEmpty = Detail::ListSize<List>::Size == 0;
|
||||
|
||||
template<typename List, typename Type>
|
||||
constexpr bool TypeListFind = Detail::ListFind<List, Type>::Find();
|
||||
|
||||
|
|
@ -55,6 +67,9 @@ namespace Nz
|
|||
template<typename List, typename NewType>
|
||||
using TypeListPrepend = typename Detail::ListPrepend<List, NewType>::Result;
|
||||
|
||||
template<typename List>
|
||||
constexpr std::size_t TypeListSize = Detail::ListSize<List>::Size;
|
||||
|
||||
template<typename List>
|
||||
using TypeListUnique = typename Detail::ListUnique<TypeList<>, List>::Result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
#include <Nazara/Core/TypeList.hpp>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <Nazara/Core/Debug.hpp>
|
||||
|
||||
namespace Nz::Detail
|
||||
namespace Nz
|
||||
{
|
||||
namespace Detail
|
||||
{
|
||||
template<typename NewType, typename... ListTypes>
|
||||
struct ListAppend<TypeList<ListTypes...>, NewType>
|
||||
{
|
||||
|
|
@ -15,6 +18,18 @@ namespace Nz::Detail
|
|||
};
|
||||
|
||||
|
||||
template<template<typename> typename Functor, typename T, typename... ListTypes>
|
||||
struct ListApply<TypeList<T, ListTypes...>, Functor>
|
||||
{
|
||||
template<typename... Args>
|
||||
static void Apply(Args&&... args)
|
||||
{
|
||||
Functor<T>()(std::forward<Args>(args)...);
|
||||
if constexpr (sizeof...(ListTypes) > 0)
|
||||
ListApply<TypeList<ListTypes...>, Functor>::Apply(std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T, typename... ListTypes>
|
||||
struct ListAt<TypeList<T, ListTypes...>, 0>
|
||||
{
|
||||
|
|
@ -95,6 +110,13 @@ namespace Nz::Detail
|
|||
};
|
||||
|
||||
|
||||
template<typename... ListTypes>
|
||||
struct ListSize<TypeList<ListTypes...>>
|
||||
{
|
||||
static constexpr std::size_t Size = sizeof...(ListTypes);
|
||||
};
|
||||
|
||||
|
||||
template<typename... Types, typename T1>
|
||||
struct ListUnique<TypeList<Types...>, TypeList<T1>>
|
||||
{
|
||||
|
|
@ -107,6 +129,14 @@ namespace Nz::Detail
|
|||
{
|
||||
using Result = typename ListUnique<typename ListUnique<TypeList<Types...>, TypeList<T1>>::Result, TypeList<T2, Rest...>>::Result;
|
||||
};
|
||||
}
|
||||
|
||||
template<typename List, template<typename> typename Functor, typename... Args>
|
||||
void TypeListApply(Args&&... args)
|
||||
{
|
||||
if constexpr (!TypeListEmpty<List>)
|
||||
Detail::ListApply<List, Functor>::Apply(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
#include <Nazara/Core/DebugOff.hpp>
|
||||
|
|
|
|||
Loading…
Reference in New Issue