OpenVDB  11.0.0
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 TupleTtuple ()
 
constexpr TupleTtuple () 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. More...
 
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. More...
 
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. More...
 

Detailed Description

template<typename... Ts>
struct openvdb::v11_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

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

Constructor & Destructor Documentation

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

Member Function Documentation

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<I> on every element when only a single unknown element needs processing.
Parameters
predPredicate to run on each index, should return true/false
opFunction to run on the first element that satisfies pred

Example:

{
}
{
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_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
predPredicate to run on each index, should return true/false
opFunction to run on the first element that satisfies pred
defDefault return value

Example:

{
}
{
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_FORCE_INLINE constexpr void foreach ( OpT  op)
inline

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
opFunction to run on each type

Example:

{
}
{
Types::AsTupleList tuple(Int32(1), float(3.3), std::string("foo"));
tuple.foreach([](auto value) { std::cout << value << ' '; }); // prints '1 3.3 foo'
}
constexpr auto& get ( )
inline
constexpr auto& get ( ) const
inline
constexpr auto size ( )
inline
constexpr TupleT& tuple ( )
inline
constexpr TupleT& tuple ( ) const
inline