Ginkgo  Generated from pipelines/3133041809 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
gko::temporary_conversion< T > Class Template Reference

A temporary_conversion is a special smart pointer-like object that is designed to hold an object temporarily converted to another format. More...

#include <ginkgo/core/base/temporary_conversion.hpp>

Public Types

using value_type = T
 
using pointer = T *
 

Public Member Functions

T * get () const
 Returns the object held by temporary_conversion. More...
 
T * operator-> () const
 Calls a method on the underlying object. More...
 

Static Public Member Functions

template<typename Other >
static void static_assert_compatibility ()
 Static assertion to check if a conversion from Other to T is possible. More...
 
template<typename Other >
static void dynamic_assert_compatibility (Other *other)
 Dynamic assertion to check if a conversion from Other to T is possible. More...
 
template<typename OrigT >
static temporary_conversion create (OrigT *orig)
 Create a temporary conversion from a bare pointer. More...
 
template<typename OrigT >
static temporary_conversion create (std::unique_ptr< OrigT > orig)
 Create a temporary conversion that also owns orig. More...
 
template<typename Derived , typename = std::enable_if_t<std::is_base_of_v< std::decay_t<T>, std::decay_t<Derived>>>>
static temporary_conversion create_from_derived (temporary_conversion< Derived > &&derived)
 Create a temporary conversion for a base type T from an object of a derived type. More...
 
template<typename Base , typename = std::enable_if_t<std::is_base_of_v< std::decay_t<Base>, std::decay_t<T>>>>
static temporary_conversion create_from_base (temporary_conversion< Base > &&base)
 Create a temporary conversion for a derived type T from an object of a base type. More...
 

Friends

template<typename OtherT >
class temporary_conversion
 

Detailed Description

template<typename T>
class gko::temporary_conversion< T >

A temporary_conversion is a special smart pointer-like object that is designed to hold an object temporarily converted to another format.

After the temporary_conversion goes out of scope, the stored object will be converted back to its original format. This class is optimized to avoid copies if the object is already in the correct format, in which case it will just hold a reference to that object, without performing the conversion.

Template Parameters
Tthe type of object held in the temporary_conversion

Member Function Documentation

◆ create() [1/2]

template<typename T>
template<typename OrigT >
static temporary_conversion gko::temporary_conversion< T >::create ( OrigT *  orig)
inlinestatic

Create a temporary conversion from a bare pointer.

Template Parameters
OrigTType of the pointer to convert from, see static_assert_compatibility for requirements.
Parameters
origObject to convert from
Exceptions
NotSupportedsee dynamic_assert_compatibility
Returns
Temporary conversion of orig_ptr to type T

References gko::temporary_conversion< T >::dynamic_assert_compatibility().

◆ create() [2/2]

template<typename T>
template<typename OrigT >
static temporary_conversion gko::temporary_conversion< T >::create ( std::unique_ptr< OrigT >  orig)
inlinestatic

Create a temporary conversion that also owns orig.

This create method takes ownership of the input pointer. It can be useful, when chaining conversion. For example if the conversion A -> C isn't implemented, but A -> B and B -> C are, then this can simplify the conversion by just chaining the two.

When the temporary conversion is deleted, orig will be deleted as well.

Template Parameters
OrigTType of the pointer to convert from, see static_assert_compatibility for requirements.
Parameters
origObject to convert from and take ownership of
Exceptions
NotSupportedsee dynamic_assert_compatibility
Returns
Temporary conversion of orig_ptr to type T

References gko::temporary_conversion< T >::dynamic_assert_compatibility().

◆ create_from_base()

template<typename T>
template<typename Base , typename = std::enable_if_t<std::is_base_of_v< std::decay_t<Base>, std::decay_t<T>>>>
static temporary_conversion gko::temporary_conversion< T >::create_from_base ( temporary_conversion< Base > &&  base)
inlinestatic

Create a temporary conversion for a derived type T from an object of a base type.

Template Parameters
BaseA base type of T
Parameters
baseObject to convert from
Exceptions
NotSupportedif the dynamic type of base is not T
Returns
Temporary conversion of base to type T

Referenced by gko::as().

◆ create_from_derived()

template<typename T>
template<typename Derived , typename = std::enable_if_t<std::is_base_of_v< std::decay_t<T>, std::decay_t<Derived>>>>
static temporary_conversion gko::temporary_conversion< T >::create_from_derived ( temporary_conversion< Derived > &&  derived)
inlinestatic

Create a temporary conversion for a base type T from an object of a derived type.

Template Parameters
DerivedA derived type of T
Parameters
derivedObject to convert from
Returns
Temporary conversion of derived to type T

◆ dynamic_assert_compatibility()

template<typename T>
template<typename Other >
static void gko::temporary_conversion< T >::dynamic_assert_compatibility ( Other *  other)
inlinestatic

Dynamic assertion to check if a conversion from Other to T is possible.

Template Parameters
OtherType to convert from
Parameters
otherthe object to convert from
Exceptions
NotSupportedif:
  • other is nullptr, or
  • other is not of static or dynamic type T and:
    • other is not of dynamic type ConvertibleTo<T>, or
    • T is not const qualified and T is not derived from ConvertibleTo<Other>

Referenced by gko::temporary_conversion< T >::create().

◆ get()

template<typename T>
T* gko::temporary_conversion< T >::get ( ) const
inline

Returns the object held by temporary_conversion.

Returns
the object held by temporary_conversion

◆ operator->()

template<typename T>
T* gko::temporary_conversion< T >::operator-> ( ) const
inline

Calls a method on the underlying object.

Returns
the underlying object

◆ static_assert_compatibility()

template<typename T>
template<typename Other >
static void gko::temporary_conversion< T >::static_assert_compatibility ( )
inlinestatic

Static assertion to check if a conversion from Other to T is possible.

Note
Succeeding this check can still lead to runtime exceptions, if the to convert from object is a nullptr, if its dynamic type is not T and T is not const and T is not convertible to Other.
Template Parameters
OtherThe type to convert from

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