VTK-m  2.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | List of all members
vtkm::tmp::Variant< Ts > Class Template Reference

#include <VariantImpl.h>

Public Types

template<typename T >
using IndexOf = vtkm::ListIndexOf< vtkm::List< Ts... >, T >
 Type that converts to a std::integral_constant containing the index of the given type (or -1 if that type is not in the list). More...
 
template<vtkm::IdComponent Index>
using TypeAt = typename vtkm::ListAt< vtkm::List< Ts... >, Index >
 Type that converts to the type at the given index. More...
 
template<typename T >
using CanStore = std::integral_constant< bool,(IndexOf< T >::value >=0)>
 Type that indicates whether another type can be stored in this Variant. More...
 

Public Member Functions

vtkm::IdComponent GetIndex () const noexcept
 Returns the index of the type of object this variant is storing. More...
 
bool IsValid () const noexcept
 Returns true if this Variant is storing an object from one of the types in the template list, false otherwise. More...
 
template<typename T >
bool IsType () const
 Returns true if this Variant stores the given type. More...
 
 Variant ()=default
 
 ~Variant ()=default
 
 Variant (const Variant &)=default
 
 Variant (Variant &&)=default
 
Variantoperator= (const Variant &)=default
 
Variantoperator= (Variant &&)=default
 
template<typename T >
 Variant (const T &src) noexcept
 
template<typename T >
Variantoperator= (const T &src)
 
template<typename T , typename... Args>
T & Emplace (Args &&... args)
 
template<typename T , typename U , typename... Args>
T & Emplace (std::initializer_list< U > il, Args &&... args)
 
template<vtkm::IdComponent I, typename... Args>
TypeAt< I > & Emplace (Args &&... args)
 
template<vtkm::IdComponent I, typename U , typename... Args>
TypeAt< I > & Emplace (std::initializer_list< U > il, Args &&... args)
 
template<vtkm::IdComponent I>
TypeAt< I > & Get () noexcept
 
template<vtkm::IdComponent I>
const TypeAt< I > & Get () const noexcept
 
template<typename T >
T & Get () noexcept
 
template<typename T >
const T & Get () const noexcept
 
template<typename Functor , typename... Args>
auto CastAndCall (Functor &&f, Args &&... args) const noexcept(noexcept(f(std::declval< const TypeAt< 0 > & >(), args...)))
 
template<typename Functor , typename... Args>
auto CastAndCall (Functor &&f, Args &&... args) noexcept(noexcept(f(std::declval< TypeAt< 0 > & >(), args...)))
 
void Reset () noexcept
 Destroys any object the Variant is holding and sets the Variant to an invalid state. More...
 

Static Public Member Functions

template<typename T >
static constexpr vtkm::IdComponent GetIndexOf ()
 Returns the index for the given type (or -1 if that type is not in the list). More...
 
template<typename T >
static constexpr bool GetCanStore ()
 Returns whether the given type can be respresented in this Variant. More...
 

Static Public Attributes

static constexpr vtkm::IdComponent NumberOfTypes = vtkm::IdComponent{ sizeof...(Ts) }
 The number of types representable by this Variant. More...
 

Private Types

using Superclass = detail::VariantConstructorImpl< Variant< Ts... > >
 
using CheckTypes = vtkm::List< detail::VariantCheckType< Ts >... >
 

Private Member Functions

template<typename T , vtkm::IdComponent I, typename... Args>
T & EmplaceImpl (Args &&... args)
 
template<typename T , vtkm::IdComponent I, typename U , typename... Args>
T & EmplaceImpl (std::initializer_list< U > il, Args &&... args)
 
template<typename T >
T & GetImpl (std::true_type)
 
template<typename T >
const T & GetImpl (std::true_type) const
 
template<typename T >
T & GetImpl (std::false_type) const
 

Member Typedef Documentation

◆ CanStore

template<typename... Ts>
template<typename T >
using vtkm::tmp::Variant< Ts >::CanStore = std::integral_constant<bool, (IndexOf<T>::value >= 0)>

Type that indicates whether another type can be stored in this Variant.

If this templated type resolves to std::true_type, then the provided T can be represented in this Variant. Otherwise, the type resolves to std::false_type.

◆ CheckTypes

template<typename... Ts>
using vtkm::tmp::Variant< Ts >::CheckTypes = vtkm::List<detail::VariantCheckType<Ts>...>
private

◆ IndexOf

template<typename... Ts>
template<typename T >
using vtkm::tmp::Variant< Ts >::IndexOf = vtkm::ListIndexOf<vtkm::List<Ts...>, T>

Type that converts to a std::integral_constant containing the index of the given type (or -1 if that type is not in the list).

◆ Superclass

template<typename... Ts>
using vtkm::tmp::Variant< Ts >::Superclass = detail::VariantConstructorImpl<Variant<Ts...> >
private

◆ TypeAt

template<typename... Ts>
template<vtkm::IdComponent Index>
using vtkm::tmp::Variant< Ts >::TypeAt = typename vtkm::ListAt<vtkm::List<Ts...>, Index>

Type that converts to the type at the given index.

Constructor & Destructor Documentation

◆ Variant() [1/4]

template<typename... Ts>
vtkm::tmp::Variant< Ts >::Variant ( )
default

◆ ~Variant()

template<typename... Ts>
vtkm::tmp::Variant< Ts >::~Variant ( )
default

◆ Variant() [2/4]

template<typename... Ts>
vtkm::tmp::Variant< Ts >::Variant ( const Variant< Ts > &  )
default

◆ Variant() [3/4]

template<typename... Ts>
vtkm::tmp::Variant< Ts >::Variant ( Variant< Ts > &&  )
default

◆ Variant() [4/4]

template<typename... Ts>
template<typename T >
vtkm::tmp::Variant< Ts >::Variant ( const T &  src)
inlinenoexcept

Member Function Documentation

◆ CastAndCall() [1/2]

template<typename... Ts>
template<typename Functor , typename... Args>
auto vtkm::tmp::Variant< Ts >::CastAndCall ( Functor &&  f,
Args &&...  args 
) const
inlinenoexcept

Given a functor object, calls the functor with the contained object cast to the appropriate type. If extra args are given, then those are also passed to the functor after the cast object. If the functor returns a value, that value is returned from CastAndCall.

The results are undefined if the Variant is not valid.

◆ CastAndCall() [2/2]

template<typename... Ts>
template<typename Functor , typename... Args>
auto vtkm::tmp::Variant< Ts >::CastAndCall ( Functor &&  f,
Args &&...  args 
)
inlinenoexcept

Given a functor object, calls the functor with the contained object cast to the appropriate type. If extra args are given, then those are also passed to the functor after the cast object. If the functor returns a value, that value is returned from CastAndCall.

The results are undefined if the Variant is not valid.

◆ Emplace() [1/4]

template<typename... Ts>
template<typename T , typename... Args>
T& vtkm::tmp::Variant< Ts >::Emplace ( Args &&...  args)
inline

◆ Emplace() [2/4]

template<typename... Ts>
template<vtkm::IdComponent I, typename... Args>
TypeAt<I>& vtkm::tmp::Variant< Ts >::Emplace ( Args &&...  args)
inline

◆ Emplace() [3/4]

template<typename... Ts>
template<typename T , typename U , typename... Args>
T& vtkm::tmp::Variant< Ts >::Emplace ( std::initializer_list< U >  il,
Args &&...  args 
)
inline

◆ Emplace() [4/4]

template<typename... Ts>
template<vtkm::IdComponent I, typename U , typename... Args>
TypeAt<I>& vtkm::tmp::Variant< Ts >::Emplace ( std::initializer_list< U >  il,
Args &&...  args 
)
inline

◆ EmplaceImpl() [1/2]

template<typename... Ts>
template<typename T , vtkm::IdComponent I, typename... Args>
T& vtkm::tmp::Variant< Ts >::EmplaceImpl ( Args &&...  args)
inlineprivate

◆ EmplaceImpl() [2/2]

template<typename... Ts>
template<typename T , vtkm::IdComponent I, typename U , typename... Args>
T& vtkm::tmp::Variant< Ts >::EmplaceImpl ( std::initializer_list< U >  il,
Args &&...  args 
)
inlineprivate

◆ Get() [1/4]

template<typename... Ts>
template<vtkm::IdComponent I>
const TypeAt<I>& vtkm::tmp::Variant< Ts >::Get ( ) const
inlinenoexcept

Returns the value as the type at the given index. The behavior is undefined if the variant does not contain the value at the given index.

◆ Get() [2/4]

template<typename... Ts>
template<typename T >
const T& vtkm::tmp::Variant< Ts >::Get ( ) const
inlinenoexcept

Returns the value as the given type. The behavior is undefined if the variant does not contain a value of the given type.

◆ Get() [3/4]

template<typename... Ts>
template<vtkm::IdComponent I>
TypeAt<I>& vtkm::tmp::Variant< Ts >::Get ( )
inlinenoexcept

Returns the value as the type at the given index. The behavior is undefined if the variant does not contain the value at the given index.

◆ Get() [4/4]

template<typename... Ts>
template<typename T >
T& vtkm::tmp::Variant< Ts >::Get ( )
inlinenoexcept

Returns the value as the given type. The behavior is undefined if the variant does not contain a value of the given type.

◆ GetCanStore()

template<typename... Ts>
template<typename T >
static constexpr bool vtkm::tmp::Variant< Ts >::GetCanStore ( )
inlinestaticconstexpr

Returns whether the given type can be respresented in this Variant.

◆ GetImpl() [1/3]

template<typename... Ts>
template<typename T >
T& vtkm::tmp::Variant< Ts >::GetImpl ( std::false_type  ) const
inlineprivate

◆ GetImpl() [2/3]

template<typename... Ts>
template<typename T >
T& vtkm::tmp::Variant< Ts >::GetImpl ( std::true_type  )
inlineprivate

◆ GetImpl() [3/3]

template<typename... Ts>
template<typename T >
const T& vtkm::tmp::Variant< Ts >::GetImpl ( std::true_type  ) const
inlineprivate

◆ GetIndex()

template<typename... Ts>
vtkm::IdComponent vtkm::tmp::Variant< Ts >::GetIndex ( ) const
inlinenoexcept

Returns the index of the type of object this variant is storing.

If no object is currently stored (i.e. the Variant is invalid), an invalid is returned.

◆ GetIndexOf()

template<typename... Ts>
template<typename T >
static constexpr vtkm::IdComponent vtkm::tmp::Variant< Ts >::GetIndexOf ( )
inlinestaticconstexpr

Returns the index for the given type (or -1 if that type is not in the list).

◆ IsType()

template<typename... Ts>
template<typename T >
bool vtkm::tmp::Variant< Ts >::IsType ( ) const
inline

Returns true if this Variant stores the given type.

◆ IsValid()

template<typename... Ts>
bool vtkm::tmp::Variant< Ts >::IsValid ( ) const
inlinenoexcept

Returns true if this Variant is storing an object from one of the types in the template list, false otherwise.

Note that if this Variant was not initialized with an object, the result of IsValid is undefined. The Variant could report itself as validly containing an object that is trivially constructed.

◆ operator=() [1/3]

template<typename... Ts>
template<typename T >
Variant& vtkm::tmp::Variant< Ts >::operator= ( const T &  src)
inline

◆ operator=() [2/3]

template<typename... Ts>
Variant& vtkm::tmp::Variant< Ts >::operator= ( const Variant< Ts > &  )
default

◆ operator=() [3/3]

template<typename... Ts>
Variant& vtkm::tmp::Variant< Ts >::operator= ( Variant< Ts > &&  )
default

◆ Reset()

template<typename... Ts>
void vtkm::tmp::Variant< Ts >::Reset ( )
inlinenoexcept

Destroys any object the Variant is holding and sets the Variant to an invalid state.

This method is not thread safe.

Member Data Documentation

◆ NumberOfTypes

template<typename... Ts>
constexpr vtkm::IdComponent vtkm::tmp::Variant< Ts >::NumberOfTypes = vtkm::IdComponent{ sizeof...(Ts) }
staticconstexpr

The number of types representable by this Variant.


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