type_list_join added

This commit is contained in:
Mateusz Pusz
2020-02-24 15:15:46 +01:00
parent b9e7ffc90c
commit c745bebffd
2 changed files with 28 additions and 0 deletions

View File

@@ -73,6 +73,25 @@ namespace units {
template<TypeList List, typename... Types> template<TypeList List, typename... Types>
using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type; using type_list_push_back = detail::type_list_push_back_impl<List, Types...>::type;
// join
namespace detail {
template<typename List, typename... Rest>
struct type_list_join_impl {
using type = List;
};
template<template<typename...> typename List, typename... First, typename... Second, typename... Rest>
struct type_list_join_impl<List<First...>, List<Second...>, Rest...> {
using type = type_list_join_impl<List<First..., Second...>, Rest...>::type;
};
}
template<TypeList... Lists>
using type_list_join = detail::type_list_join_impl<Lists...>::type;
// split // split
namespace detail { namespace detail {

View File

@@ -44,6 +44,15 @@ static_assert(std::is_same_v<type_list_push_back<type_list<>, int>, type_list<in
static_assert(std::is_same_v<type_list_push_back<type_list<>, int, long, double>, type_list<int, long, double>>); static_assert(std::is_same_v<type_list_push_back<type_list<>, int, long, double>, type_list<int, long, double>>);
static_assert(std::is_same_v<type_list_push_back<type_list<double>, int, long>, type_list<double, int, long>>); static_assert(std::is_same_v<type_list_push_back<type_list<double>, int, long>, type_list<double, int, long>>);
static_assert(std::is_same_v<type_list_join<type_list<>>, type_list<>>);
static_assert(std::is_same_v<type_list_join<type_list<>, type_list<>>, type_list<>>);
static_assert(std::is_same_v<type_list_join<type_list<>, type_list<>, type_list<>>, type_list<>>);
static_assert(std::is_same_v<type_list_join<type_list<int>, type_list<>, type_list<>>, type_list<int>>);
static_assert(std::is_same_v<type_list_join<type_list<>, type_list<int>, type_list<>>, type_list<int>>);
static_assert(std::is_same_v<type_list_join<type_list<>, type_list<>, type_list<int>>, type_list<int>>);
static_assert(std::is_same_v<type_list_join<type_list<int>, type_list<float>, type_list<bool>>, type_list<int, float, bool>>);
static_assert(std::is_same_v<type_list_join<type_list<int, short>, type_list<float, double>, type_list<bool>>, type_list<int, short, float, double, bool>>);
// type_list_split // type_list_split
static_assert(std::is_same_v<type_list_split<type_list<int>, 0>::first_list, type_list<>>); static_assert(std::is_same_v<type_list_split<type_list<int>, 0>::first_list, type_list<>>);