Loading...
Searching...
No Matches
TypeList< Ts > Struct Template Reference

A list of types (not necessarily unique) More...

`#include <openvdb/TypeList.h>`

## Public Types

using | Self = TypeList
| The type of this list.
using | AsTupleList = TupleList< Ts... >
template<size_t N>
using | Get = typename typelist_internal::TSGetElementImpl< Self, N >::type
| Access a particular element of this type list. If the index is out of range, typelist_internal::NullType is returned.
using | Front = Get< 0 >
using | Back = Get< Size-1 >
template<typename ListT = TypeList<>>
using | Unique = typename typelist_internal::TSRecurseAppendUniqueImpl< ListT, Ts... >::type
| Remove any duplicate types from this TypeList by rotating the next valid type left (maintains the order of other types). Optionally combine the result with another TypeList.
template<typename... TypesToAppend>
using | Append = typename typelist_internal::TSAppendImpl< Self, TypesToAppend... >::type
| Append types, or the members of another TypeList, to this list.
template<typename... TypesToRemove>
using | Remove = typename typelist_internal::TSRemoveImpl< Self, TypesToRemove... >::type
| Remove all occurrences of one or more types, or the members of another TypeList, from this list.
using | PopFront = typename typelist_internal::TSRemoveFirstImpl< Self >::type
| Remove the first element of this type list. Has no effect if the type list is already empty.
using | PopBack = typename typelist_internal::TSRemoveLastImpl< Self >::type
| Remove the last element of this type list. Has no effect if the type list is already empty.
template<size_t First, size_t Last>
using | RemoveByIndex = typename typelist_internal::TSRemoveIndicesImpl< Self, First, Last >::type
| Return a new list with types removed by their location within the list. If First is equal to Last, a single element is removed (if it exists). If First is greater than Last, the list remains unmodified.
template<template< typename > class OpT>
using | Transform = typename typelist_internal::TSTranformImpl< OpT, Ts... >::type
| Transform each type of this TypeList, rebuiling a new list of converted types. This method instantiates a user provided Opt<T> to replace each type in the current list.

## Static Public Member Functions

template<template< typename > class OpT>
static OPENVDB_FORCE_INLINE void | foreach ()
| Invoke a templated class operator on each type in this list. Use this method if you only need access to the type for static methods.
template<typename OpT >
static OPENVDB_FORCE_INLINE void | foreach (OpT op)
| Invoke a templated, unary functor on a value of each type in this list.
template<typename OpT >
static OPENVDB_FORCE_INLINE void | foreachIndex (OpT op)
template<typename OpT , typename RetT >
static OPENVDB_FORCE_INLINE RetT | foreachIndex (OpT op, RetT def)
template<typename OpT , typename BaseT >
static OPENVDB_FORCE_INLINE bool | apply (OpT op, BaseT &obj)
| Invoke a templated, unary functor on a provide `obj` of type `BaseT` only if said object is an applicable (derived) type also contained in the current `TypeList`.

## Static Public Attributes

static constexpr size_t | Size = sizeof...(Ts)
| The number of types in the type list.
template<typename T >
static constexpr bool | Contains = typelist_internal::TSHasTypeImpl<Self, T>::Value
| True if this list contains the given type, false otherwise.
template<typename T >
static constexpr int64_t | Index = typelist_internal::TSHasTypeImpl<Self, T>::Index
| Returns the index of the first found element of the given type, -1 if no matching element exists.

## Detailed Description

template<typename... Ts>
struct openvdb::v11_0::TypeList< Ts >

A list of types (not necessarily unique)

Example:

using MyTypes = openvdb::TypeList<int, float, int, double, float>;
openvdb::v11_0::TypeList
A list of types (not necessarily unique)
Definition TypeList.h:578

## Member Typedef Documentation

## Append

template<typename... Ts>
template<typename... TypesToAppend>

using Append = typename typelist_internal::TSAppendImpl<Self, TypesToAppend...>::type

Append types, or the members of another TypeList, to this list.

Warning
  Appending nested TypeList<> objects causes them to expand to their contained list of types.

Example:

{
using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
using RealTypes = openvdb::TypeList<float, double>;
using NumericTypes = IntTypes::Append<RealTypes>;
}
{
using IntTypes = openvdb::TypeList<Int16>::Append<Int32, Int64>;
using NumericTypes = IntTypes::Append<float>::Append<double>;
}
openvdb::v11_0::Int64
int64_t Int64
Definition Types.h:57
openvdb::v11_0::Int32
int32_t Int32
Definition Types.h:56

## AsTupleList

template<typename... Ts>

using AsTupleList = TupleList<Ts...>

## Back

template<typename... Ts>

using Back = Get<Size-1>

## Front

template<typename... Ts>

using Front = Get<0>

## Get

template<typename... Ts>
template<size_t N>

using Get = typename typelist_internal::TSGetElementImpl<Self, N>::type

Access a particular element of this type list. If the index is out of range, typelist_internal::NullType is returned.

## PopBack

template<typename... Ts>

using PopBack = typename typelist_internal::TSRemoveLastImpl<Self>::type

Remove the last element of this type list. Has no effect if the type list is already empty.

Example:

{
using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
using EmptyTypes = openvdb::TypeList<>;
}
{
IntTypes::PopBack; // openvdb::TypeList<Int16, Int32>;
EmptyTypes::PopBack; // openvdb::TypeList<>;
}

## PopFront

template<typename... Ts>

using PopFront = typename typelist_internal::TSRemoveFirstImpl<Self>::type

Remove the first element of this type list. Has no effect if the type list is already empty.

Example:

{
using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
using EmptyTypes = openvdb::TypeList<>;
}
{
IntTypes::PopFront; // openvdb::TypeList<Int32, Int64>;
EmptyTypes::PopFront; // openvdb::TypeList<>;
}

## Remove

template<typename... Ts>
template<typename... TypesToRemove>

using Remove = typename typelist_internal::TSRemoveImpl<Self, TypesToRemove...>::type

Remove all occurrences of one or more types, or the members of another TypeList, from this list.

Example:

{
using NumericTypes = openvdb::TypeList<float, double, Int16, Int32, Int64>;
using LongTypes = openvdb::TypeList<Int64, double>;
using ShortTypes = NumericTypes::Remove<LongTypes>; // float, Int16, Int32
}

## RemoveByIndex

template<typename... Ts>
template<size_t First, size_t Last>

using RemoveByIndex = typename typelist_internal::TSRemoveIndicesImpl<Self, First, Last>::type

Return a new list with types removed by their location within the list. If First is equal to Last, a single element is removed (if it exists). If First is greater than Last, the list remains unmodified.

Example:

{
using NumericTypes = openvdb::TypeList<float, double, Int16, Int32, Int64>;
}
{
using IntTypes = NumericTypes::RemoveByIndex<0,1>; // openvdb::TypeList<Int16, Int32, Int64>;
using RealTypes = NumericTypes::RemoveByIndex<2,4>; // openvdb::TypeList<float, double>;
using RemoveFloat = NumericTypes::RemoveByIndex<0,0>; // openvdb::TypeList<double, Int16, Int32, Int64>;
}

## Self

template<typename... Ts>

using Self = TypeList

The type of this list.

## Transform

template<typename... Ts>
template<template< typename > class OpT>

using Transform = typename typelist_internal::TSTranformImpl<OpT, Ts...>::type

Transform each type of this TypeList, rebuiling a new list of converted types. This method instantiates a user provided Opt<T> to replace each type in the current list.

Warning
  Transforming types to new TypeList<> objects causes them to expand to their contained list of types.

Example:

{
// Templated type decl, where the type T will be subsituted for each type
// in the TypeList being transformed.
template <typename T>
using ConvertedType = typename openvdb::PromoteType<T>::Next;
// Results in: openvdb::TypeList<Int64, double>;
using PromotedType = openvdb::TypeList<Int32, float>::Transform<ConvertedType>;
}
openvdb::v11_0::PromoteType
Promotion classes which provide an interface for elevating and demoting a scalar or VDB type to a hig...
Definition Types.h:354

## Unique

template<typename... Ts>
template<typename ListT = TypeList<>>

using Unique = typename typelist_internal::TSRecurseAppendUniqueImpl<ListT, Ts...>::type

Remove any duplicate types from this TypeList by rotating the next valid type left (maintains the order of other types). Optionally combine the result with another TypeList.

Example:

{
using Types = openvdb::TypeList<Int16, Int32, Int16, float, float, Int64>;
}
{
using UniqueTypes = Types::Unique<>; // <Int16, Int32, float, Int64>
}

## Member Function Documentation

## apply()

template<typename... Ts>
template<typename OpT , typename BaseT >

static OPENVDB_FORCE_INLINE bool apply | ( | OpT | op,
|  | BaseT & | obj
| ) |  |

inlinestatic

Invoke a templated, unary functor on a provide `obj` of type `BaseT` only if said object is an applicable (derived) type also contained in the current `TypeList`.

This method loops over every type in the type list and calls an interface method on `obj` to check to see if the `obj` is interpretable as the given type. If it is, the method static casts `obj` to the type, invokes the provided functor with the casted type and returns, stopping further list iteration. `obj` is expected to supply an interface to validate the type which satisfies the prototype:

template <typename T> bool isType()

A full example (using dynamic_cast - see Grid/Tree implementations for string based comparisons:

struct Base {
virtual ~Base() = default;
template<typename T> bool isType() { return dynamic_cast<const T*>(this); }
};
struct MyType1 : public Base { void print() { std::cerr << "MyType1" << std::endl; } };
struct MyType2 : public Base { void print() { std::cerr << "MyType2" << std::endl; } };
using MyTypeList = TypeList<MyType1, MyType2>;
Base* getObj() { return new MyType2(); }
std::unique_ptr<Base> obj = getObj();
// Returns 'true', prints 'MyType2'
const bool success =
MyTypeList::apply([](const auto& type) { type.print(); }, *obj);

Note
  The functor object is passed by value. Wrap it with `std::ref` pass by reference.

## foreach() [1/2]

template<typename... Ts>
template<template< typename > class OpT>

static OPENVDB_FORCE_INLINE void foreach | ( |  | ) |

inlinestatic

Invoke a templated class operator on each type in this list. Use this method if you only need access to the type for static methods.

Example:

#include <typeinfo>
template <typename T>
struct PintTypes() {
inline void operator()() { std::cout << typeid(T).name() << std::endl; }
};
using MyTypes = openvdb::TypeList<int, float, double>;
MyTypes::foreach<PintTypes>(); // "i, f, d" (exact output is compiler-dependent)

Note
  OpT must be a templated class. It is created and invoked for each type in this list.

## foreach() [2/2]

template<typename... Ts>
template<typename OpT >

static OPENVDB_FORCE_INLINE void foreach | ( | OpT | op | ) |

inlinestatic

Invoke a templated, unary functor on a value of each type in this list.

Example:

#include <typeinfo>
template<typename ListT>
void printTypeList()
{
std::string sep;
auto op = [&](auto x) { // C++14
std::cout << sep << typeid(decltype(x)).name(); sep = ", "; };
ListT::foreach(op);
}
using MyTypes = openvdb::TypeList<int, float, double>;
printTypeList<MyTypes>(); // "i, f, d" (exact output is compiler-dependent)

Note
  The functor object is passed by value. Wrap it with `std::ref` to use the same object for each type.

## foreachIndex() [1/2]

template<typename... Ts>
template<typename OpT >

static OPENVDB_FORCE_INLINE void foreachIndex | ( | OpT | op | ) |

inlinestatic

## foreachIndex() [2/2]

template<typename... Ts>
template<typename OpT , typename RetT >

static OPENVDB_FORCE_INLINE RetT foreachIndex | ( | OpT | op,
|  | RetT | def
| ) |  |

inlinestatic

## Member Data Documentation

## Contains

template<typename... Ts>
template<typename T >

constexpr bool Contains = typelist_internal::TSHasTypeImpl<Self, T>::Value

staticconstexpr

True if this list contains the given type, false otherwise.

Example:

{
using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
using RealTypes = openvdb::TypeList<float, double>;
}
{
openvdb::TypeList<IntTypes>::Contains<Int32>; // true
openvdb::TypeList<RealTypes>::Contains<Int32>; // false
}

## Index

template<typename... Ts>
template<typename T >

constexpr int64_t Index = typelist_internal::TSHasTypeImpl<Self, T>::Index

staticconstexpr

Returns the index of the first found element of the given type, -1 if no matching element exists.

Example:

{
using IntTypes = openvdb::TypeList<Int16, Int32, Int64>;
using RealTypes = openvdb::TypeList<float, double>;
}
{
const int64_t L1 = openvdb::TypeList<IntTypes>::Index<Int32>; // 1
const int64_t L2 = openvdb::TypeList<RealTypes>::Index<Int32>; // -1
}

## Size

template<typename... Ts>

constexpr size_t Size = sizeof...(Ts)

staticconstexpr

The number of types in the type list.