Caffe2 - C++ API
A deep learning, cross platform ML framework
Data Structures | Public Member Functions | Friends
torch::nn::AnyModule::Value Class Reference

A simplified implementation of std::any which stores a type erased object, whose concrete value can be retrieved at runtime by checking if the typeid() of a requested type matches the typeid() of the object stored. More...

#include <any.h>

Public Member Functions

 Value (Value &&)=default
 Move construction and assignment is allowed, and follows the default behavior of move for std::unique_ptr. More...
 
Valueoperator= (Value &&)=default
 
 Value (const Value &other)=delete
 Copy is disallowed, because we don't need it.
 
Valueoperator= (const Value &other)=delete
 
template<typename T >
Ttry_get ()
 Returns a pointer to the value contained in the Value if the type passed as template parameter matches the type of the value stored, and returns a null pointer otherwise. More...
 
template<typename T >
T get ()
 Returns the value contained in the Value if the type passed as template parameter matches the type of the value stored, and throws an exception otherwise. More...
 
const std::type_info & type_info () const noexcept
 Returns the type_info object of the contained value.
 

Friends

class AnyModule
 
struct TestValue
 

Detailed Description

A simplified implementation of std::any which stores a type erased object, whose concrete value can be retrieved at runtime by checking if the typeid() of a requested type matches the typeid() of the object stored.

It is simplified in that it does not handle copying, as we do not require it for our use cases. Moves are sufficient.

Definition at line 235 of file any.h.

Constructor & Destructor Documentation

torch::nn::AnyModule::Value::Value ( Value &&  )
default

Move construction and assignment is allowed, and follows the default behavior of move for std::unique_ptr.

Member Function Documentation

template<typename T >
T torch::nn::AnyModule::Value::get ( )
inline

Returns the value contained in the Value if the type passed as template parameter matches the type of the value stored, and throws an exception otherwise.

Definition at line 267 of file any.h.

template<typename T >
T* torch::nn::AnyModule::Value::try_get ( )
inline

Returns a pointer to the value contained in the Value if the type passed as template parameter matches the type of the value stored, and returns a null pointer otherwise.

Definition at line 250 of file any.h.


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