Mundy: Multibody Nonlocal Dynamics Version of the Day
Loading...
Searching...
No Matches
mundy::AScalar< T, Accessor > Class Template Reference

Class for an owning or viewing arithmetic scalar. More...

#include <Scalar.hpp>

Inheritance diagram for mundy::AScalar< T, Accessor >:
[legend]

Public Types

Type aliases
using value_type = T
 The type of the stored value.
using non_const_value_type = std::remove_const_t<T>
 Non-const version of value_type.
using deep_copy_t = AScalar<T>
 Owning deep-copy type.
using accessor_t = Accessor
 The type of the accessor.

Public Member Functions

Constructors and destructor
constexpr AScalar ()=default
 Default constructor. Element is uninitialized.
constexpr AScalar (const Accessor &data)
 Construct from a copy of the given accessor.
constexpr AScalar (Accessor &&data)
 Construct from a moved accessor.
constexpr AScalar (const T &val)
 Construct from a single value (requires the Accessor to have a 1-argument constructor).
constexpr ~AScalar ()=default
 Destructor.
constexpr AScalar (const AScalar< T, Accessor > &)=default
 Copy constructor (shallow).
constexpr AScalar (AScalar< T, Accessor > &&)=default
 Move constructor (shallow).
constexpr AScalar< T, Accessor > & operator= (const AScalar< T, Accessor > &other)
 Copy assignment (deep — copies the stored value).
constexpr AScalar< T, Accessor > & operator= (AScalar< T, Accessor > &&other)
 Move assignment (deep — copies the stored value).
template<typename OtherScalarType>
constexpr AScalar (const OtherScalarType &other)
 Deep copy constructor from a different AScalar accessor or ownership.
template<typename OtherScalarType>
constexpr AScalar (OtherScalarType &&other)
 Deep move constructor from a different AScalar accessor or ownership.
template<typename OtherScalarType>
constexpr AScalar< T, Accessor > & operator= (const OtherScalarType &other)
 Deep copy assignment from a different AScalar accessor or ownership.
template<typename OtherScalarType>
constexpr AScalar< T, Accessor > & operator= (OtherScalarType &&other)
 Deep move assignment from a different AScalar accessor or ownership.
constexpr AScalar< T, Accessor > & operator= (const T val)
 Assignment from a raw arithmetic value.
constexpr operator T () const
 Implicit conversion to the underlying arithmetic type.
Value accessors
constexpr T & value ()
 Primary named accessor — returns a reference to the stored value.
constexpr const T & value () const
constexpr T & operator[] (size_t index)
 Subscript accessor for compatibility with generic index-based code (index must be 0).
constexpr const T & operator[] (size_t index) const
constexpr T & operator() ()
 Call-operator accessor (no argument — returns the value directly).
constexpr const T & operator() () const
constexpr T & operator() (size_t index)
 Call-operator accessor with an index argument (index must be 0, for generic compatibility).
constexpr const T & operator() (size_t index) const
constexpr decltype(auto) data ()
 Access the underlying accessor data.
constexpr decltype(auto) data () const
Setters and modifiers
constexpr void set (const T &val)
 Set the stored value.
constexpr void fill (const T &val)
 Fill the scalar with a value (synonym for set; mirrors AVector::fill).
Deep copy and cast
constexpr deep_copy_t copy () const
 Return an owning deep copy of this scalar.
template<typename U>
constexpr auto cast () const
 Cast the value to a different arithmetic type and return an owning AScalar.
Unary operators
constexpr AScalar< T > operator+ () const
 Unary plus.
constexpr AScalar< T > operator- () const
 Unary minus.
Addition and subtraction (AScalar op AScalar)
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator+ (const AScalar< U, OtherAccessor > &other) const
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AScalar< T, Accessor > & operator+= (const AScalar< U, OtherAccessor > &other)
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator- (const AScalar< U, OtherAccessor > &other) const
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AScalar< T, Accessor > & operator-= (const AScalar< U, OtherAccessor > &other)
Multiplication and division (AScalar op AScalar)
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator* (const AScalar< U, OtherAccessor > &other) const
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AScalar< T, Accessor > & operator*= (const AScalar< U, OtherAccessor > &other)
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr auto operator/ (const AScalar< U, OtherAccessor > &other) const
 Division — promotes integral/integral pairs to double, matching AVector::operator/ semantics.
template<typename U, ValidAccessor< U > OtherAccessor>
constexpr AScalar< T, Accessor > & operator/= (const AScalar< U, OtherAccessor > &other)
 Self-division — does NOT type-promote (integer division is possible).
Addition and subtraction (AScalar op arithmetic)
template<typename U>
constexpr auto operator+ (const U &scalar) const
template<typename U>
constexpr AScalar< T, Accessor > & operator+= (const U &scalar)
template<typename U>
constexpr auto operator- (const U &scalar) const
template<typename U>
constexpr AScalar< T, Accessor > & operator-= (const U &scalar)
Multiplication and division (AScalar op arithmetic)
template<typename U>
constexpr auto operator* (const U &scalar) const
template<typename U>
constexpr AScalar< T, Accessor > & operator*= (const U &scalar)
template<typename U>
constexpr auto operator/ (const U &scalar) const
 Division by arithmetic scalar — promotes integral/integral pairs to double.
template<typename U>
constexpr AScalar< T, Accessor > & operator/= (const U &scalar)
 Self-division by arithmetic scalar — does NOT type-promote.

Static Public Member Functions

Static factory methods
static constexpr AScalar< T > zero ()
static constexpr AScalar< T > one ()

Public Attributes

Internal data
storage< Accessor > accessor_
 Our data accessor (public, matching AVector / AMatrix convention).

Friends

Friends
template<typename U, ValidAccessor< U > OtherAccessor>
class AScalar
template<typename U, ValidAccessor< U > OtherAccessor>
std::ostream & operator<< (std::ostream &os, const AScalar< U, OtherAccessor > &s)

Detailed Description

template<typename T, ValidAccessor< T > Accessor>
class mundy::AScalar< T, Accessor >

AScalar is the scalar analogue of AVector and AMatrix. It holds a single arithmetic value through a templated Accessor, which may be owning (e.g., Array<T,1>) or non-owning (e.g., a pointer or Kokkos::View slice). This separation of concerns — storage policy vs. value semantics — mirrors the rest of the Mundy math library and makes AScalar Kokkos-compatible.

The primary interface is value(), operator T() (implicit conversion to the underlying type), and the full set of arithmetic operators. AScalar participates naturally in expressions with AVector and AMatrix through non-member operators defined at the bottom of this file.

Scalar<double> s{3.14}; // owning, default accessor
double raw[1] = {2.0};
AScalar<double, double*> view(raw); // non-owning view of raw memory
Vector3<double> v{1.0, 2.0, 3.0};
auto scaled = v * s; // AVector<double, 3>
auto doubled = s * s; // Scalar<double>{9.87...}
double x = s; // implicit conversion
friend class AScalar
Definition Scalar.hpp:498
AScalar< T, Array< T, 1 > > Scalar
Owning scalar with the default Array<T,1> accessor.
Definition Scalar.hpp:520
Note
Accessors may be owning or non-owning; they should be lightweight so they can be copied cheaply. The lifetime of the underlying data must exceed the lifetime of any AScalar that views it.

Member Typedef Documentation

◆ value_type

template<typename T, ValidAccessor< T > Accessor>
using mundy::AScalar< T, Accessor >::value_type = T

◆ non_const_value_type

template<typename T, ValidAccessor< T > Accessor>
using mundy::AScalar< T, Accessor >::non_const_value_type = std::remove_const_t<T>

◆ deep_copy_t

template<typename T, ValidAccessor< T > Accessor>
using mundy::AScalar< T, Accessor >::deep_copy_t = AScalar<T>

◆ accessor_t

template<typename T, ValidAccessor< T > Accessor>
using mundy::AScalar< T, Accessor >::accessor_t = Accessor

Constructor & Destructor Documentation

◆ AScalar() [1/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( )
constexprdefault

◆ AScalar() [2/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( const Accessor & data)
inlineexplicitconstexpr

◆ AScalar() [3/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( Accessor && data)
inlineexplicitconstexpr

◆ AScalar() [4/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( const T & val)
inlineexplicitconstexpr

◆ ~AScalar()

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::~AScalar ( )
constexprdefault

◆ AScalar() [5/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( const AScalar< T, Accessor > & )
constexprdefault

◆ AScalar() [6/8]

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::AScalar ( AScalar< T, Accessor > && )
constexprdefault

◆ AScalar() [7/8]

template<typename T, ValidAccessor< T > Accessor>
template<typename OtherScalarType>
mundy::AScalar< T, Accessor >::AScalar ( const OtherScalarType & other)
inlineconstexpr

◆ AScalar() [8/8]

template<typename T, ValidAccessor< T > Accessor>
template<typename OtherScalarType>
mundy::AScalar< T, Accessor >::AScalar ( OtherScalarType && other)
inlineconstexpr

Member Function Documentation

◆ operator=() [1/5]

template<typename T, ValidAccessor< T > Accessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator= ( const AScalar< T, Accessor > & other)
inlineconstexpr

◆ operator=() [2/5]

template<typename T, ValidAccessor< T > Accessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator= ( AScalar< T, Accessor > && other)
inlineconstexpr

◆ operator=() [3/5]

template<typename T, ValidAccessor< T > Accessor>
template<typename OtherScalarType>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator= ( const OtherScalarType & other)
inlineconstexpr

◆ operator=() [4/5]

template<typename T, ValidAccessor< T > Accessor>
template<typename OtherScalarType>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator= ( OtherScalarType && other)
inlineconstexpr

◆ operator=() [5/5]

template<typename T, ValidAccessor< T > Accessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator= ( const T val)
inlineconstexpr

◆ operator T()

template<typename T, ValidAccessor< T > Accessor>
mundy::AScalar< T, Accessor >::operator T ( ) const
inlineconstexpr

This allows an AScalar to be passed anywhere a T is expected, and lets existing AVector / AMatrix member operators (which require std::is_arithmetic_v) accept an AScalar via implicit conversion rather than requiring separate overloads.

◆ value() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AScalar< T, Accessor >::value ( )
inlineconstexpr

◆ value() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AScalar< T, Accessor >::value ( ) const
inlineconstexpr

◆ operator[]() [1/2]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AScalar< T, Accessor >::operator[] ( size_t index)
inlineconstexpr

◆ operator[]() [2/2]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AScalar< T, Accessor >::operator[] ( size_t index) const
inlineconstexpr

◆ operator()() [1/4]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AScalar< T, Accessor >::operator() ( )
inlineconstexpr

◆ operator()() [2/4]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AScalar< T, Accessor >::operator() ( ) const
inlineconstexpr

◆ operator()() [3/4]

template<typename T, ValidAccessor< T > Accessor>
T & mundy::AScalar< T, Accessor >::operator() ( size_t index)
inlineconstexpr

◆ operator()() [4/4]

template<typename T, ValidAccessor< T > Accessor>
const T & mundy::AScalar< T, Accessor >::operator() ( size_t index) const
inlineconstexpr

◆ data() [1/2]

template<typename T, ValidAccessor< T > Accessor>
decltype(auto) mundy::AScalar< T, Accessor >::data ( )
inlineconstexpr

◆ data() [2/2]

template<typename T, ValidAccessor< T > Accessor>
decltype(auto) mundy::AScalar< T, Accessor >::data ( ) const
inlineconstexpr

◆ set()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AScalar< T, Accessor >::set ( const T & val)
inlineconstexpr

◆ fill()

template<typename T, ValidAccessor< T > Accessor>
void mundy::AScalar< T, Accessor >::fill ( const T & val)
inlineconstexpr

◆ copy()

template<typename T, ValidAccessor< T > Accessor>
deep_copy_t mundy::AScalar< T, Accessor >::copy ( ) const
inlineconstexpr

◆ cast()

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AScalar< T, Accessor >::cast ( ) const
inlineconstexpr

◆ operator+() [1/3]

template<typename T, ValidAccessor< T > Accessor>
AScalar< T > mundy::AScalar< T, Accessor >::operator+ ( ) const
inlineconstexpr

◆ operator-() [1/3]

template<typename T, ValidAccessor< T > Accessor>
AScalar< T > mundy::AScalar< T, Accessor >::operator- ( ) const
inlineconstexpr

◆ operator+() [2/3]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AScalar< T, Accessor >::operator+ ( const AScalar< U, OtherAccessor > & other) const
inlineconstexpr

◆ operator+=() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator+= ( const AScalar< U, OtherAccessor > & other)
inlineconstexpr

◆ operator-() [2/3]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AScalar< T, Accessor >::operator- ( const AScalar< U, OtherAccessor > & other) const
inlineconstexpr

◆ operator-=() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator-= ( const AScalar< U, OtherAccessor > & other)
inlineconstexpr

◆ operator*() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AScalar< T, Accessor >::operator* ( const AScalar< U, OtherAccessor > & other) const
inlineconstexpr

◆ operator*=() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator*= ( const AScalar< U, OtherAccessor > & other)
inlineconstexpr

◆ operator/() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
auto mundy::AScalar< T, Accessor >::operator/ ( const AScalar< U, OtherAccessor > & other) const
inlineconstexpr

◆ operator/=() [1/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator/= ( const AScalar< U, OtherAccessor > & other)
inlineconstexpr

◆ operator+() [3/3]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AScalar< T, Accessor >::operator+ ( const U & scalar) const
inlineconstexpr

◆ operator+=() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator+= ( const U & scalar)
inlineconstexpr

◆ operator-() [3/3]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AScalar< T, Accessor >::operator- ( const U & scalar) const
inlineconstexpr

◆ operator-=() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator-= ( const U & scalar)
inlineconstexpr

◆ operator*() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AScalar< T, Accessor >::operator* ( const U & scalar) const
inlineconstexpr

◆ operator*=() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator*= ( const U & scalar)
inlineconstexpr

◆ operator/() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
auto mundy::AScalar< T, Accessor >::operator/ ( const U & scalar) const
inlineconstexpr

◆ operator/=() [2/2]

template<typename T, ValidAccessor< T > Accessor>
template<typename U>
AScalar< T, Accessor > & mundy::AScalar< T, Accessor >::operator/= ( const U & scalar)
inlineconstexpr

◆ zero()

template<typename T, ValidAccessor< T > Accessor>
constexpr AScalar< T > mundy::AScalar< T, Accessor >::zero ( )
inlinestaticconstexpr

◆ one()

template<typename T, ValidAccessor< T > Accessor>
constexpr AScalar< T > mundy::AScalar< T, Accessor >::one ( )
inlinestaticconstexpr

◆ AScalar

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
friend class AScalar
friend

◆ operator<<

template<typename T, ValidAccessor< T > Accessor>
template<typename U, ValidAccessor< U > OtherAccessor>
std::ostream & operator<< ( std::ostream & os,
const AScalar< U, OtherAccessor > & s )
friend

Member Data Documentation

◆ accessor_

template<typename T, ValidAccessor< T > Accessor>
storage<Accessor> mundy::AScalar< T, Accessor >::accessor_