ug_misc 0.1
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 <type_traits>

Go to the source code of this file.

Classes

struct  ugmisc::flatten< T >
 Converts the template parameters into a type_list. More...

Typedefs

template<std::size_t I, class T>
using ugmisc::get_indexed_t = typename get_indexed<I, T>::type
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<class... T>
using ugmisc::flatten_t = typename flatten<T...>::type

Detailed Description

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

?

The UGMISC_NAMED_MEMBER_TYPE_TEST macro declares a template that can be instanciated with a type and an optional default type, for example:

// Creates these declarations, among others:
// template<class T, class Default=void> TestFoo;
// template<class T, class D=void> TestFooT = typename TestFoo<T, D>::type;
UGMISC_NAMED_MEMBER_TYPE_TEST(TestFoo, TestFooT, hasFoo, Foo);
#define UGMISC_NAMED_MEMBER_TYPE_TEST(TEMPLATENAME, ALIASNAME, HASMEMBERNAME, NAME)
Definition member.hpp:277

These declarations allow types to be tested for member types called 'Foo'.

In the above example, you could also pass a series of types which may or may not have a member type called Foo, like this:

using FooType = TestFooT<type_list<A, B, C>, int>;

If member type A::Foo exists, that will be the type aliased by FooType. Otherwise, B::Foo will be used, or failing that C::Foo, or as a last resort, int.

If you really want to use a type_list type as the type to check for a member, you can wrap it:

// FooType is int, because type_list<A, B, C> will never have a member type
// called Foo no matter what A, B, and C are.
using FooType = TestFooT<wrapped_list<type_list<A, B, C>>, int>;

Templates which use type_lists in this way rely on the template #flatten_t.

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> > );
Definition typelist.hpp:81
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:200
Template Parameters
TEach type is an instance of type_list.