5#ifndef UGMISC_TYPELIST_HPP
6#define UGMISC_TYPELIST_HPP
80template<
class...>
struct flatten;
87template<std::
size_t, std::
size_t,
class>
struct get_type_list_sublist;
91template<
class>
struct unwrap;
97template<
template<
class>
class,
class>
struct apply_each;
100template<std::
size_t,
class>
struct get_type_list_member;
101template<std::ptrdiff_t, std::ptrdiff_t, std::
size_t,
class>
141template<
class...T>
static constexpr bool are_type_lists_v = (... && is_type_list_v<T>);
154 typename typelist_::get_type_list_member<I, T>::type;
194template<std::
size_t From, std::
size_t To,
class T>
200template<std::
size_t From, std::
size_t Count,
class T>
209template<std::
size_t Count,
class T>
218template<std::
size_t Count,
class T>
227template<std::
size_t Count,
class T>
236template<std::
size_t Count,
class T>
246template<std::size_t From, std::size_t To,
class...T>
252template<std::size_t From, std::size_t Count,
class...T>
258template<std::size_t Count,
class...T>
264template<std::size_t Count,
class...T>
273template<std::size_t Count,
class...T>
282template<std::size_t Count,
class...T>
303 template<
class>
class Test,
308 typename typelist_::filter_type_list<Test, T, Mod>::type;
316 template<
class>
class Test,
331template<
template<
class>
class F,
class T >
341template<
template<
class>
class F,
class T >
352template<
template<
class>
class F,
class...T >
362template<
template<
class>
class F,
class...T >
370 template<
class>
class Test,
431 std::ptrdiff_t Stride,
436 typename typelist_::type_list_stride<Base, Stride, Count, T>::type;
445 std::ptrdiff_t Stride,
456template<std::
size_t I,
class T>
struct get_type_list_member {};
458template<std::size_t I,
class T1,
class...T>
459struct get_type_list_member<I,
type_list<T1, T...>> {
460 static_assert( I <
sizeof...(T) + 1,
"Index out of range" );
461 using type =
typename get_type_list_member<I-1,
type_list<T...>>::type;
464template<
class T1,
class...T>
struct get_type_list_member<0,
type_list<T1, T...>> {
471template<
template <
class>
class Test,
class T,
test_modifier Mod>
482template<
template <
class>
class Test,
class T,
test_modifier Mod>
484 using type = std::conditional_t<
492template<
template<
class>
class Test,
test_modifier Mod,
class T1,
class T2,
class...Ts>
496 static constexpr std::size_t halfway = all::size / 2;
508template<
template<
class>
class F,
class...T >
523 std::ptrdiff_t SignedBase,
524 std::ptrdiff_t Stride,
528struct type_list_stride_params {
530 static_assert( is_type_list_v< T > );
532 static constexpr std::size_t Base =
533 (std::size_t)(SignedBase >= 0 ? SignedBase : T::size + SignedBase);
536 template<std::
size_t new_index,
bool check = true>
537 static constexpr std::size_t original_index() {
538 static_assert( (!check) || new_index < Count );
539 const std::ptrdiff_t base = Base;
540 return base + ((std::ptrdiff_t)new_index) * Stride;
544 template<std::
size_t original_index,
bool check = true>
545 static constexpr std::size_t new_index() {
556 constexpr std::ptrdiff_t dist = ((std::ptrdiff_t)original_index) - Base;
557 constexpr std::ptrdiff_t new_index_signed = dist/Stride;
558 constexpr std::ptrdiff_t new_index_mod = dist%Stride;
559 constexpr std::size_t new_index = (std::size_t)new_index_signed;
562 (!check) || (new_index >= T::size),
563 "Index out of underlying array bounds."
567 (!check) || (original_index >= Count),
568 "Index out of stride array bounds."
572 (!check) || (new_index_mod == 0),
573 "Index not touched by the stride array."
583 Count == 0 || original_index<Count - 1,
false>() < T::size,
584 "type_list_stride out of bounds."
593 std::ptrdiff_t Stride,
599 using params = type_list_stride_params<Base, Stride, Count, T>;
601 template<
class S>
struct deduce_type;
603 template<std::size_t...N>
struct deduce_type<std::index_sequence<N...>> {
610 using type =
typename deduce_type< std::make_index_sequence<Count> >::type;
628template<>
struct concatenate_type_lists<> {
629 using type = type_list<>;
634 using type = type_list<T...>;
639 static_assert( are_type_lists_v<T1, T2, T3, Ts...> );
640 using type =
typename concatenate_type_lists<
641 typename concatenate_type_lists<T1, T2>::type,
642 typename concatenate_type_lists<T3, Ts...>::type
647template<
class T,
class...Ts>
650 static_assert( is_type_list_v<T> );
651 using type =
typename T::template append<Ts...>;
660template<std::size_t From,
class...T>
661struct get_type_list_sublist<From, From,
type_list<T...>> {
662 static_assert( From <=
sizeof...(T) );
663 using type = type_list<>;
666template<std::size_t From,
class...T>
667struct get_type_list_sublist<From, From+1,
type_list<T...>> {
668 static_assert( From <
sizeof...(T) );
673template<std::size_t From, std::size_t To,
class...T>
674struct get_type_list_sublist<From, To,
type_list<T...>> {
676 static_assert( To >= From,
"Invalid range: To must be no less than From." );
677 static_assert( To > From+1,
"Logic error. Wrong partial specialisation." );
679 using list = type_list<T...>;
681 static constexpr std::size_t from1 = From;
682 static constexpr std::size_t to1 = From + (To - From)/2;
683 static constexpr std::size_t from2 = to1;
684 static constexpr std::size_t to2 = To;
686 using part1 =
typename get_type_list_sublist<from1, to1, list>::type;
687 using part2 =
typename get_type_list_sublist<from2, to2, list>::type;
690 using type = concatenate_type_lists_t< part1, part2 >;
698template<std::
size_t From, std::
size_t To,
class T>
699struct get_type_list_slice :
public get_type_list_sublist<From, To, T> {};
716 "wrapped_list must wrap a wrapped_list or a type_list"
726template<
class T>
struct wrapped_list<wrapped_list<T>> {
727 using type = wrapped_list<T>;
744template<
class T>
struct unwrap {
765template<
class T>
struct flatten<T> {
774template<
class...T>
struct flatten< type_list<T...> > {
775 using type = concatenate_type_lists_t<typename flatten<T>::type...>;
783 using type = type_list<T>;
794 static constexpr std::size_t
size =
sizeof...(T);
797 template<
template<
class...>
class Templ>
using apply_t = Templ<T...>;
810 template<
template<
class...>
class Templ>
using call_t =
811 typename Templ<T...>::type;
855 template<std::
size_t From, std::
size_t To>
863 std::ptrdiff_t Stride,
875 std::ptrdiff_t Stride,
892template<
class T,
class U>
Definition typelist.hpp:78
Definition typelist.hpp:754
Definition typelist.hpp:733
Definition typelist.hpp:621
Encapsulates a list of types.
Definition typelist.hpp:792
prepend_t< U... > prepend
Definition typelist.hpp:831
type_list< T..., U... > append_t
Definition typelist.hpp:837
type_list_stride< Base, Stride, Count, type_list > stride_t
Definition typelist.hpp:866
append_t< U... > append
Definition typelist.hpp:844
typename Templ< T... >::type call_t
Definition typelist.hpp:810
apply_t< Templ > apply
Definition typelist.hpp:804
type_list_sublist< From, To, type_list > sublist_t
Definition typelist.hpp:856
type_list< U..., T... > prepend_t
Definition typelist.hpp:824
call_t< Templ > call
Definition typelist.hpp:818
static constexpr std::size_t size
Definition typelist.hpp:794
stride_t< Base, Stride, Count > stride
Definition typelist.hpp:878
Templ< T... > apply_t
Definition typelist.hpp:797
Definition typelist.hpp:713
type_list_sized_sublist< From, Count, flatten_t< T... > > flatten_sized_sublist
Definition typelist.hpp:253
type_list_sublist< 0, Count, T > type_list_prefix
Definition typelist.hpp:210
type_list_sublist< From, To, flatten_t< T... > > flatten_sublist
Definition typelist.hpp:247
typename get_as_list< T >::type get_as_list_t
Definition typelist.hpp:135
typename typelist_::type_list_stride< Base, Stride, Count, T >::type type_list_stride
Definition typelist.hpp:435
typename typelist_::apply_each< F, T >::class_types type_list_apply_each_class
Definition typelist.hpp:332
type_list_filter< Test, T, Mod > filter_type_list
Definition typelist.hpp:320
type_list_sublist< 0, T::size-Count, T > type_list_remove_suffix
Definition typelist.hpp:237
type_list_filter< Test, flatten_t< T... >, Mod > flatten_filter
Definition typelist.hpp:374
type_list_remove_prefix< Count, flatten_t< T... > > flatten_remove_prefix
Definition typelist.hpp:274
typename typelist_::filter_type_list< Test, T, Mod >::type type_list_filter
Definition typelist.hpp:307
test_modifier
Definition typelist.hpp:50
@ invert_test
Keep types when the Filter returns false.
Definition typelist.hpp:52
@ no_invert_test
Keep types when the Filter returns true.
Definition typelist.hpp:51
type_list_sublist< T::size - Count, T::size, T > type_list_suffix
Definition typelist.hpp:219
typename typelist_::apply_each< F, T >::inner_types type_list_apply_each
Definition typelist.hpp:342
typename flatten< T... >::type flatten_t
Converts the template parameters into a type_list.
Definition typelist.hpp:181
type_list_prefix< Count, flatten_t< T... > > flatten_prefix
Definition typelist.hpp:259
type_list_sublist< From, From+Count, T > type_list_sized_sublist
Definition typelist.hpp:201
type_list_remove_suffix< Count, flatten_t< T... > > flatten_remove_suffix
Definition typelist.hpp:283
typename concatenate_type_lists< T... >::type concatenate_type_lists_t
Definition typelist.hpp:131
type_list_apply_each< F, flatten_t< T... > > flatten_apply_each
Definition typelist.hpp:363
type_list_stride< Base, Stride, Count, flatten_t< T... > > flatten_stride
Definition typelist.hpp:449
type_list_suffix< Count, flatten_t< T... > > flatten_suffix
Definition typelist.hpp:265
type_list_sublist< Count, T::size, T > type_list_remove_prefix
Definition typelist.hpp:228
type_list_apply_each_class< F, flatten_t< T... > > flatten_apply_each_class
Definition typelist.hpp:353
typename typelist_::get_type_list_member< I, T >::type type_list_member
Definition typelist.hpp:153
typename get_type_list_sublist< From, To, T >::type type_list_sublist
Definition typelist.hpp:195