HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
openvdb::OPENVDB_VERSION_NAME::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 <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_TYPELIST_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_TYPELIST_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_TYPELIST_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::OPENVDB_VERSION_NAME::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.

Definition at line 850 of file TypeList.h.

Member Typedef Documentation

template<typename... Ts>
using openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::AsTypeList = TypeList<Ts...>

Definition at line 852 of file TypeList.h.

template<typename... Ts>
using openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::TupleT = std::tuple<Ts...>

Definition at line 853 of file TypeList.h.

Constructor & Destructor Documentation

template<typename... Ts>
openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::TupleList ( )
default
template<typename... Ts>
openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::TupleList ( Ts &&...  args)
inline

Definition at line 856 of file TypeList.h.

Member Function Documentation

template<typename... Ts>
template<class Pred , class OpT >
OPENVDB_TYPELIST_FORCE_INLINE void openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::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:

{
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; }
);
}

Definition at line 909 of file TypeList.h.

template<typename... Ts>
template<class Pred , class OpT , typename RetT >
OPENVDB_TYPELIST_FORCE_INLINE RetT openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::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:

{
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
);
}

Definition at line 941 of file TypeList.h.

template<typename... Ts>
template<typename OpT >
OPENVDB_TYPELIST_FORCE_INLINE constexpr void openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::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:

{
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'
}

Definition at line 881 of file TypeList.h.

template<typename... Ts>
template<size_t Idx>
constexpr auto& openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::get ( )
inline

Definition at line 862 of file TypeList.h.

template<typename... Ts>
template<size_t Idx>
constexpr auto& openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::get ( ) const
inline

Definition at line 863 of file TypeList.h.

template<typename... Ts>
constexpr auto openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::size ( void  )
inline

Definition at line 858 of file TypeList.h.

template<typename... Ts>
constexpr TupleT& openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::tuple ( )
inline

Definition at line 859 of file TypeList.h.

template<typename... Ts>
constexpr TupleT& openvdb::OPENVDB_VERSION_NAME::TupleList< Ts >::tuple ( ) const
inline

Definition at line 860 of file TypeList.h.


The documentation for this struct was generated from the following file: