MUQ  0.4.3
muq::Utilities::AnyCast Class Reference

Class for easily casting boost::any's in assignment operations. More...

#include <AnyHelpers.h>

Detailed Description

Class for easily casting boost::any's in assignment operations.

Consider the following code involving boost::any_cast

double A = 1.0;
boost::any anyA = A;
double b = boost::any_cast<double>(anyA);
double const& aRef = boost::any_cast<double const&>(anyA);

This class, AnyCast, attempts to streamline these casting operations and ensure that references are used whenever possible. Using AnyCast, the above code would be replace by

double A = 1.0;
boost::any anyA = A;
double b = AnyCast(anyA);
double& aRef = AnyCast(anyA);
AnyCast(boost::any &objIn)
Definition: AnyHelpers.h:36

NOTE: This class stores a reference to the boost::any in question and errors may occur if an object of this class persists longer than the original boost::any. For this reason, we recommend using AnyCast in expressions like the code above;

Definition at line 33 of file AnyHelpers.h.

Public Member Functions

 AnyCast (boost::any &objIn)
 
template<typename T >
 operator T& ()
 

Constructor & Destructor Documentation

◆ AnyCast()

muq::Utilities::AnyCast::AnyCast ( boost::any &  objIn)
inline

Definition at line 36 of file AnyHelpers.h.

Member Function Documentation

◆ operator T&()

template<typename T >
muq::Utilities::AnyCast::operator T& ( )
inline

Definition at line 42 of file AnyHelpers.h.

References obj.

Member Data Documentation

◆ obj

boost::any& muq::Utilities::AnyCast::obj
private

Definition at line 45 of file AnyHelpers.h.

Referenced by operator T&().


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