SpECTRE  v2024.04.12
MathWrapper< T > Class Template Reference

Type-erased data for performing math on. More...

#include <MathWrapper.hpp>

Public Types

using value_type = T
 The class's template parameter.
 
using scalar_type = typename Impl<>::scalar_type
 Scalar type for linear-algebra operations. Either double or std::complex<double>.
 

Public Member Functions

T & operator* () const
 
 MathWrapper (MathWrapper &&)=default
 
 MathWrapper (const MathWrapper &)=delete
 
MathWrapperoperator= (const MathWrapper &)=delete
 
MathWrapperoperator= (MathWrapper &&)=delete
 
 operator MathWrapper< const T > () const
 Convert MathWrapper wrapping a mutable value to one wrapping a const one. More...
 
MathWrapper< const T > to_const () const
 Convert MathWrapper wrapping a mutable value to one wrapping a const one. More...
 

Friends

MathWrapper< T > make_math_wrapper (tmpl::conditional_t< std::is_const_v< T >, T &, gsl::not_null< T * > >)
 

Detailed Description

template<typename T>
class MathWrapper< T >

Type-erased data for performing math on.

This class can only be instantiated with possibly const-qualified types from MATH_WRAPPER_TYPES, which can be assumed to support the mathematical operations of a linear-algebra vector. Instances of this class with those template arguments can be created using overloads of make_math_wrapper (passing a const T& for const versions and a gsl::not_null<T*> for mutable versions). Other data structures (such as Variables) can add additional overloads implemented on top of these basic ones.

double mutable_double = 1.0;
const double const_double = 2.0;
const auto mutable_wrapper = make_math_wrapper(&mutable_double);
const auto const_wrapper = make_math_wrapper(const_double);
*mutable_wrapper += *const_wrapper;
CHECK(mutable_double == 3.0);

Member Function Documentation

◆ operator MathWrapper< const T >()

template<typename T >
MathWrapper< T >::operator MathWrapper< const T >

Convert MathWrapper wrapping a mutable value to one wrapping a const one.

These methods will fail to compile if called on a MathWrapper wrapping a const value. The to_const method is useful because C++ fails to resolve the implicit conversion in many cases.

◆ to_const()

template<typename T >
MathWrapper< const T > MathWrapper< T >::to_const ( ) const
inline

Convert MathWrapper wrapping a mutable value to one wrapping a const one.

These methods will fail to compile if called on a MathWrapper wrapping a const value. The to_const method is useful because C++ fails to resolve the implicit conversion in many cases.


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