OpenVDB: TupleList< Ts > Struct Template Reference

OpenVDB 12.0.0 |

Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
TupleList< Ts > Struct Template Reference

A trivial wrapper around a std::tuple but with compatible TypeList methods. Importantly can be instatiated from a TypeList and implements a similar foreach interface. More...

`#include <openvdb/TypeList.h>`

## Public Types
using | AsTypeList = TypeList<Ts...>
using | TupleT = std::tuple<Ts...>

## Public Member Functions
| TupleList ()=default
| TupleList (Ts &&... args)
constexpr auto | size ()
constexpr TupleT & | tuple ()
constexpr TupleT & | tuple () const
template<size_t Idx>
constexpr auto & | get ()
template<size_t Idx>
constexpr auto & | get () const
template<typename OpT>
OPENVDB_FORCE_INLINE constexpr void | foreach (OpT op)
| Run a function on each type instance in the underlying std::tuple. Effectively calls op(std::get<I>(mTuple)) where I = [0,Size). Does not support returning a value.
template<class Pred, class OpT>
OPENVDB_FORCE_INLINE void | evalFirstPred (Pred pred, OpT op)
| Run a function on the first element in the underlying std::tuple that satisfies the provided predicate. Effectively calls op(std::get<I>(mTuple)) when pred(I) returns true, then exits, where I = [0,Size). Does not support returning a value.
template<class Pred, class OpT, typename RetT>
OPENVDB_FORCE_INLINE RetT | evalFirstPred (Pred pred, OpT op, RetT def)
| Run a function on the first element in the underlying std::tuple that satisfies the provided predicate. Effectively calls op(std::get<I>(mTuple)) when pred(I) returns true, then exits, where I = [0,Size). Supports returning a value, but a default return value must be provided.

## Detailed Description

template<typename... Ts>
struct openvdb::v12_0::TupleList< Ts >

A trivial wrapper around a std::tuple but with compatible TypeList methods. Importantly can be instatiated from a TypeList and implements a similar foreach interface.

Warning
  Some member methods here run on actual instances of types in the list. As such, it's unlikely that they can always be resolved at compile time (unlike methods in TypeList). Compilers are notriously bad at automatically inlining recursive/nested template instations (without fine tuning inline options to the frontend) so the public API of this class is marked as force inlined. You can disable this behaviour by defining: OPENVDB_TYPELIST_NO_FORCE_INLINE before including this header. Note however that the ValueAccessor uses this API and disabling force inlining can cause significant performance degredation.

## Member Typedef Documentation

## ◆ AsTypeList

template<typename... Ts>

using AsTypeList = TypeList<Ts...>

## ◆ TupleT

template<typename... Ts>

using TupleT = std::tuple<Ts...>

## Constructor & Destructor Documentation

## ◆ TupleList() [1/2]

template<typename... Ts>

TupleList | ( |  | ) |
| default

## ◆ TupleList() [2/2]

template<typename... Ts>

TupleList | ( | Ts &&... | args | ) |
| inline

## Member Function Documentation

## ◆ evalFirstPred() [1/2]

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

OPENVDB_FORCE_INLINE void evalFirstPred | ( | Pred | pred,
|  | OpT | op )
| inline

Run a function on the first element in the underlying std::tuple that satisfies the provided predicate. Effectively calls op(std::get<I>(mTuple)) when pred(I) returns true, then exits, where I = [0,Size). Does not support returning a value.

Note
  This is mainly useful to avoid the overhead of calling std::get on every element when only a single unknown element needs processing.

Parameters

  pred | Predicate to run on each index, should return true/false
  op | Function to run on the first element that satisfies pred

Example:

{
using Types = openvdb::TypeList<Int32, float, std::string>;
}
{
Types::AsTupleList tuple(Int32(1), float(3.3), std::string("foo"));
bool runtimeFlags[tuple.size()] = { .... } // some runtime flags
tuple.foreach(
[&](auto Idx) { return runtimeFlags[Idx]; },
[](auto value) { std::cout << value << std::endl; }
);
}
openvdb::v12_0::Int32
int32_t Int32
Definition Types.h:56
openvdb::v12_0::TupleList::tuple
constexpr TupleT & tuple()
Definition TypeList.h:859
openvdb::v12_0::TypeList
A list of types (not necessarily unique)
Definition TypeList.h:578

## ◆ evalFirstPred() [2/2]

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

OPENVDB_FORCE_INLINE RetT evalFirstPred | ( | Pred | pred,
|  | OpT | op,
|  | RetT | def )
| inline

Run a function on the first element in the underlying std::tuple that satisfies the provided predicate. Effectively calls op(std::get<I>(mTuple)) when pred(I) returns true, then exits, where I = [0,Size). Supports returning a value, but a default return value must be provided.

Parameters

  pred | Predicate to run on each index, should return true/false
  op | Function to run on the first element that satisfies pred
  def | Default return value

Example:

{
using Types = openvdb::TypeList<Int32, float, std::string>;
}
{
Types::AsTupleList tuple(Int32(1), float(3.3), std::string("foo"));
// returns 3
auto size = tuple.foreach(
[](auto Idx) { return std::is_same<std::string, Types::template Get<Idx>>::value; },
[](auto value) { return value.size(); },
-1
);
}
openvdb::v12_0::TupleList::size
constexpr auto size()
Definition TypeList.h:858

## ◆ foreach()

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

OPENVDB_FORCE_INLINE constexpr void foreach | ( | OpT | op | ) |
| inlineconstexpr

Run a function on each type instance in the underlying std::tuple. Effectively calls op(std::get<I>(mTuple)) where I = [0,Size). Does not support returning a value.

Parameters

  op | Function to run on each type

Example:

{
using Types = openvdb::TypeList<Int32, float, std::string>;
}
{
Types::AsTupleList tuple(Int32(1), float(3.3), std::string("foo"));
tuple.foreach([](auto value) { std::cout << value << ' '; }); // prints '1 3.3 foo'
}

## ◆ get() [1/2]

template<typename... Ts>
template<size_t Idx>

auto & get | ( |  | ) |
| inlineconstexpr

## ◆ get() [2/2]

template<typename... Ts>
template<size_t Idx>

auto & get | ( |  | ) | const
| inlineconstexpr

## ◆ size()

template<typename... Ts>

auto size | ( |  | ) |
| inlineconstexpr

## ◆ tuple() [1/2]

template<typename... Ts>

TupleT & tuple | ( |  | ) |
| inlineconstexpr

## ◆ tuple() [2/2]

template<typename... Ts>

TupleT & tuple | ( |  | ) | const
| inlineconstexpr