ugmisc 0.2-76
Miscellaneous C++ header library
Loading...
Searching...
No Matches
typelist.hpp File Reference

Lists of types which may be used in some of the ugmisc templates where a single type would usually be used. More...

#include <cstddef>
#include <type_traits>
#include <utility>

Go to the source code of this file.

Classes

struct  ugmisc::is_type_list< T >
struct  ugmisc::wrapped_list< T >
struct  ugmisc::get_as_list< T >
struct  ugmisc::flatten< T >
struct  ugmisc::type_list< T >
 Encapsulates a list of types. More...

Typedefs

template<class... T>
using ugmisc::concatenate_type_lists_t = typename concatenate_type_lists<T...>::type
template<class T>
using ugmisc::get_as_list_t = typename get_as_list<T>::type
template<std::size_t I, class T>
using ugmisc::type_list_member
template<class... T>
using ugmisc::flatten_t = typename flatten<T...>::type
 Converts the template parameters into a type_list.
template<std::size_t From, std::size_t To, class T>
using ugmisc::type_list_sublist = typename get_type_list_sublist<From, To, T>::type
template<std::size_t From, std::size_t Count, class T>
using ugmisc::type_list_sized_sublist = type_list_sublist<From, From + Count, T>
template<std::size_t Count, class T>
using ugmisc::type_list_prefix = type_list_sublist<0, Count, T>
template<std::size_t Count, class T>
using ugmisc::type_list_suffix = type_list_sublist<T::size - Count, T::size, T>
template<std::size_t Count, class T>
using ugmisc::type_list_remove_prefix = type_list_sublist<Count, T::size, T>
template<std::size_t Count, class T>
using ugmisc::type_list_remove_suffix = type_list_sublist<0, T::size-Count, T>
template<std::size_t From, std::size_t To, class... T>
using ugmisc::flatten_sublist = type_list_sublist<From, To, flatten_t<T...>>
template<std::size_t From, std::size_t Count, class... T>
using ugmisc::flatten_sized_sublist = type_list_sized_sublist<From, Count, flatten_t<T...>>
template<std::size_t Count, class... T>
using ugmisc::flatten_prefix = type_list_prefix<Count, flatten_t<T...>>
template<std::size_t Count, class... T>
using ugmisc::flatten_suffix = type_list_suffix<Count, flatten_t<T...>>
template<std::size_t Count, class... T>
using ugmisc::flatten_remove_prefix = type_list_remove_prefix<Count, flatten_t<T...>>
template<std::size_t Count, class... T>
using ugmisc::flatten_remove_suffix = type_list_remove_suffix<Count, flatten_t<T...>>
template<template< class > class Test, class T, test_modifier Mod = no_invert_test>
using ugmisc::type_list_filter
template<template< class > class Test, class T, test_modifier Mod = static_cast<test_modifier>(0)>
using ugmisc::filter_type_list = type_list_filter<Test, T, Mod>
template<template< class > class F, class T>
using ugmisc::type_list_apply_each_class = typename typelist_::apply_each<F, T>::class_types
template<template< class > class F, class T>
using ugmisc::type_list_apply_each = typename typelist_::apply_each<F, T>::inner_types
template<template< class > class F, class... T>
using ugmisc::flatten_apply_each_class = type_list_apply_each_class<F, flatten_t<T...>>
template<template< class > class F, class... T>
using ugmisc::flatten_apply_each = type_list_apply_each<F, flatten_t<T...>>
template<template< class > class Test, test_modifier Mod, class... T>
using ugmisc::flatten_filter = type_list_filter<Test, flatten_t<T...>, Mod>
template<std::ptrdiff_t Base, std::ptrdiff_t Stride, std::size_t Count, class T>
using ugmisc::type_list_stride
template<std::ptrdiff_t Base, std::ptrdiff_t Stride, std::size_t Count, class... T>
using ugmisc::flatten_stride = type_list_stride<Base, Stride, Count, flatten_t<T...>>

Enumerations

enum  ugmisc::test_modifier { ugmisc::no_invert_test , ugmisc::invert_test }

Functions

template<class T, class U>
constexpr auto ugmisc::operator+ (T, U) -> concatenate_type_lists_t< T, U >

Detailed Description

Lists of types which may be used in some of the ugmisc templates where a single type would usually be used.

Why?

The member.hpp header finds this stuff useful. You might too.

List of types can be manipulated easily, as if they are lists of objects.

Operations

Some operations are templates which come in two variants.

  • flatten_ prefixed template type aliases
  • type_list_ prefixed template type aliases

The flatten_ variants are more flexible, and will always work as a drop in replacement for their type_list_ twins. That might not be what you want though. If you think you have an instance of the type_list<> template to pass to e.g. flatten_filter then using type_list_filter is effectively like doing the same thing but also making a static assertion that it is indeed a type_list.

Operations include adding and removing prefixes and suffixes or taking sublists from type_lists, filtering out some of the members of a type_list, and concatenating two or more type_lists.

Typedef Documentation

◆ concatenate_type_lists_t

template<class... T>
using ugmisc::concatenate_type_lists_t = typename concatenate_type_lists<T...>::type

Aliases a type which is a type_list containing all the member types of the template paramter type_list types.

For example:

#include <type_traits>
using namespace ugmisc;
using B = type_list<>; // Empty list.
static_assert( std::is_same_v< all, type_list<int, float, char, int, int> > );
Encapsulates a list of types.
Definition typelist.hpp:810
Lists of types which may be used in some of the ugmisc templates where a single type would usually be...
typename concatenate_type_lists< T... >::type concatenate_type_lists_t
Definition typelist.hpp:149
Template Parameters
TEach type is an instance of type_list.

◆ filter_type_list

template<template< class > class Test, class T, test_modifier Mod = static_cast<test_modifier>(0)>
using ugmisc::filter_type_list = type_list_filter<Test, T, Mod>
Deprecated
This is an alias of the preferred type_list_filter.

◆ flatten_apply_each

template<template< class > class F, class... T>
using ugmisc::flatten_apply_each = type_list_apply_each<F, flatten_t<T...>>

Like type_list_apply_each, but creates a type list using flatten_t<T...>.

See also
flatten_apply_each_class, type_list_apply_each

◆ flatten_apply_each_class

template<template< class > class F, class... T>
using ugmisc::flatten_apply_each_class = type_list_apply_each_class<F, flatten_t<T...>>

Like type_list_apply_each_class, but creates a type list using flatten_t<T...>.

See also
flatten_apply_each, type_list_apply_each_class

◆ flatten_filter

template<template< class > class Test, test_modifier Mod, class... T>
using ugmisc::flatten_filter = type_list_filter<Test, flatten_t<T...>, Mod>

◆ flatten_prefix

template<std::size_t Count, class... T>
using ugmisc::flatten_prefix = type_list_prefix<Count, flatten_t<T...>>

◆ flatten_remove_prefix

template<std::size_t Count, class... T>
using ugmisc::flatten_remove_prefix = type_list_remove_prefix<Count, flatten_t<T...>>

Aliases an ugmisc::type_list with the first Count members of the parameter types T removed.

See also
ugmisc::flatten_sublist, ugmisc::type_list_remove_prefix.

◆ flatten_remove_suffix

template<std::size_t Count, class... T>
using ugmisc::flatten_remove_suffix = type_list_remove_suffix<Count, flatten_t<T...>>

Aliases an ugmisc::type_list with the last Count members of the template parameter types T removed.

See also
ugmisc::flatten_sublist, ugmisc::type_list_remove_suffix.

◆ flatten_sized_sublist

template<std::size_t From, std::size_t Count, class... T>
using ugmisc::flatten_sized_sublist = type_list_sized_sublist<From, Count, flatten_t<T...>>

◆ flatten_stride

template<std::ptrdiff_t Base, std::ptrdiff_t Stride, std::size_t Count, class... T>
using ugmisc::flatten_stride = type_list_stride<Base, Stride, Count, flatten_t<T...>>

Like type_list_stride, but passes flatten_t<T...> as the type_list template parameter.

◆ flatten_sublist

template<std::size_t From, std::size_t To, class... T>
using ugmisc::flatten_sublist = type_list_sublist<From, To, flatten_t<T...>>

Creates an ugmisc::type_alias. Uses the From'th element of the list of types T, and all types up to but not including the To'th element.

See also
ugmisc::type_list_sublist.

◆ flatten_suffix

template<std::size_t Count, class... T>
using ugmisc::flatten_suffix = type_list_suffix<Count, flatten_t<T...>>

◆ flatten_t

template<class... T>
using ugmisc::flatten_t = typename flatten<T...>::type

Converts the template parameters into a type_list.

Every parameter which is itself a type_list is unrolled. Every wrapped_list is unwrapped (but not recursively).

So for example:

flatten_t< typelist<A, B>, C, wrapped_list<typelist<D, E, F> >

is the type:

typelist<A, B, C, typelist<D, E, F> >

The implementation uses some single-arg template specializations to distinguish between template args which are type_list, wrapped_list, or neither. Then the non-specialised flatten concatenates the types produced by those.

A wrapped_list should be unwrapped once, whereas a type_list should be unwrapped recursively.

◆ get_as_list_t

template<class T>
using ugmisc::get_as_list_t = typename get_as_list<T>::type
See also
get_as_list

◆ type_list_apply_each

template<template< class > class F, class T>
using ugmisc::type_list_apply_each = typename typelist_::apply_each<F, T>::inner_types

Given a type T which is an instance of type_list type_list<U...>, this template type alias is a type type_list<typename F<U>::type...>.

See also
type_list_apply_each_class, flatten_apply_each

◆ type_list_apply_each_class

template<template< class > class F, class T>
using ugmisc::type_list_apply_each_class = typename typelist_::apply_each<F, T>::class_types

Given a type T which is an instance of type_list type_list<U...>, this template type alias is a type type_list<F<U>...>.

See also
type_list_apply_each, flatten_apply_each_class

◆ type_list_filter

template<template< class > class Test, class T, test_modifier Mod = no_invert_test>
using ugmisc::type_list_filter
Initial value:
typename typelist_::filter_type_list<Test, T, Mod>::type

Aliases a type_list instance only containing those member types which pass a test.

Template Parameters
TA type_list.
TestA template, such that Test<T>::value exists and can be implicitly converted to bool. If the value is true, T is included in the aliased type_list.
ModSet this to ugmisc::invert_test to reverse the result of each application of the test. This means that if Test<T>::value is false the type T is included in the result.

◆ type_list_member

template<std::size_t I, class T>
using ugmisc::type_list_member
Initial value:
typename typelist_::get_type_list_member<I, T>::type

The type at an index of a typelist.

Template Parameters
IThe zero based index.
TAn instance of the type_list class template.

◆ type_list_prefix

template<std::size_t Count, class T>
using ugmisc::type_list_prefix = type_list_sublist<0, Count, T>

Aliases an ugmisc::type_list with the first Count members of the type_list template parameter T.

See also
ugmisc::type_list_sublist, ugmisc::type_list_suffix, ugmisc::flatten_prefix.

◆ type_list_remove_prefix

template<std::size_t Count, class T>
using ugmisc::type_list_remove_prefix = type_list_sublist<Count, T::size, T>

Aliases an ugmisc::type_list with the first Count members of the type_list template parameter T removed.

See also
ugmisc::type_list_sublist, ugmisc::flatten_remove_prefix.

◆ type_list_remove_suffix

template<std::size_t Count, class T>
using ugmisc::type_list_remove_suffix = type_list_sublist<0, T::size-Count, T>

Aliases an ugmisc::type_list with the last Count members of the type_list template parameter T removed.

See also
ugmisc::type_list_sublist, ugmisc::flatten_remove_suffix.

◆ type_list_sized_sublist

template<std::size_t From, std::size_t Count, class T>
using ugmisc::type_list_sized_sublist = type_list_sublist<From, From + Count, T>

◆ type_list_stride

template<std::ptrdiff_t Base, std::ptrdiff_t Stride, std::size_t Count, class T>
using ugmisc::type_list_stride
Initial value:
typename typelist_::type_list_stride<Base, Stride, Count, T>::type

Creates a type list by starting from any part of the type list T and taking steps of zero or more elements.

Template Parameters
BaseThe index in T which is used as the first element of the new type_list.
StrideEach new element of the new type list is taken by taking Stride steps along the elements of T. Use a negative value to step backward.
CountThe number of elements in the new type list.
TAn instance of the type_list template.

For example:

#include <type_traits>
using namespace ugmisc;
// define some types here
// A, B ...
// Start from index 1 (type B).
// Stride of 2.
// Take 2 elements.
static_assert( std::is_same_v< t2, type_list<B, D> > );
// Use a stride of 0 to get the same element multiple times.
static_assert( std::is_same_v< t3, type_list<D, D, D, D, D> );
// Go backwards.
using t4 = type_list_stride< 4, -1, 5, t1 >;
static_assert( std::is_same_v< t4, type_list<E, D, C, B, A> > );
// Same thing again, but without having to know the size of t1.
using t5 = type_list_stride< -1, -1, t1::size, t1 >;
static_assert( std::is_same_v< t5, t4 > );
// A count of zero works.
static_assert( std::is_same_v< t6, type_list<> > );
typename typelist_::type_list_stride< Base, Stride, Count, T >::type type_list_stride
Definition typelist.hpp:453
See also
flatten_stride

◆ type_list_sublist

template<std::size_t From, std::size_t To, class T>
using ugmisc::type_list_sublist = typename get_type_list_sublist<From, To, T>::type
Template Parameters
TA type_list.

Takes the types from the From index up to but not including the To index, and turns them into an ugmisc::type_list.

See also
flatten_sublist

◆ type_list_suffix

template<std::size_t Count, class T>
using ugmisc::type_list_suffix = type_list_sublist<T::size - Count, T::size, T>

Aliases an ugmisc::type_list with the last Count members of the type_list template parameter T.

See also
ugmisc::type_list_sublist, ugmisc::type_list_prefix, ugmisc::flatten_suffix.

Enumeration Type Documentation

◆ test_modifier

See also
filter_type_list
Enumerator
no_invert_test 

Keep types when the Filter returns true.

invert_test 

Keep types when the Filter returns false.

Function Documentation

◆ operator+()

template<class T, class U>
auto ugmisc::operator+ ( T ,
U  ) -> concatenate_type_lists_t<T, U>
constexpr

Concatenate type lists, using instances of the type lists. A type list is a type, not an object. However, it can be instantiated, and is a trivial empty class.

Instances can be added, and the resulting object is an instance of the type that would be produced by concatenating the two type lists.