Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor > Class Template Reference

Accessor wrapper to automatically apply a constant scaling factor to all accessed elements. More...

Inheritance diagram for arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >:
Inheritance graph

Public Types

using data_handle_type = typename NestedAccessor::data_handle_type
 Data handle type.
 
using element_type
 Element type of the element space mapped by the access function (no elements of this type are stored)
 
using offset_policy = scaled_accessor<ScalingFactor, typename NestedAccessor::offset_policy>
 Offset policy type.
 
using reference = std::remove_const_t<element_type>
 Reference type yielded by calls to the access function.
 

Public Member Functions

constexpr scaled_accessor ()=default
 Default constructor.
 
template<class OtherNestedAccessor, constraints< std::enable_if_t< std::is_convertible< OtherNestedAccessor, NestedAccessor >::value > > = nullptr>
constexpr scaled_accessor (scaled_accessor< ScalingFactor, OtherNestedAccessor > other) noexcept(std::is_nothrow_constructible< NestedAccessor, OtherNestedAccessor const & >::value &&std::is_nothrow_copy_constructible< ScalingFactor >::value)
 Converting constructor; implicit SFINAE overload for when the nested accessors are implicitly convertible.
 
template<class OtherNestedAccessor, constraints< std::enable_if_t< std::is_constructible< NestedAccessor, OtherNestedAccessor >::value >, std::enable_if_t<!std::is_convertible< OtherNestedAccessor, NestedAccessor >::value > > = nullptr>
constexpr scaled_accessor (scaled_accessor< ScalingFactor, OtherNestedAccessor > other) noexcept(std::is_nothrow_constructible< NestedAccessor, OtherNestedAccessor const & >::value &&std::is_nothrow_copy_constructible< ScalingFactor >::value)
 Converting constructor; explicit SFINAE overload for when the nested accessors are explicitly constructible.
 
constexpr scaled_accessor (ScalingFactor const &scale, NestedAccessor const &inner_accessor) noexcept(std::is_nothrow_copy_constructible< NestedAccessor >::value &&std::is_nothrow_copy_constructible< ScalingFactor >::value)
 Construct a scaled_accessor from a scaling factor and an instance of the nested accessor.
 
constexpr auto access (data_handle_type handle, std::size_t index) const noexcept(noexcept(std::declval< ScalingFactor const & >() *typename NestedAccessor::element_type(std::declval< >()))) -> reference
 Obtain the element at the specified index, multiplied by the scaling factor.
 
 ARENE_IGNORE_CLANG ("-Wimplicit-int-float-conversion", "The noexcept specification is unevaluated so it can't lose information")
 
 ARENE_IGNORE_CLANG ("-Wsign-conversion", "The noexcept specification is unevaluated so it can't lose information")
 
constexpr auto nested_accessor () const noexcept -> NestedAccessor const &
 Get the specific nested accessor used by this accessor.
 
constexpr auto offset (data_handle_type handle, std::size_t index) const noexcept(noexcept(std::declval< NestedAccessor >().offset(handle, index))) -> typename offset_policy::data_handle_type
 apply an offset to a pointer
 
constexpr auto scaling_factor () const noexcept -> ScalingFactor const &
 Get the specific scaling factor used by this accessor.
 

Detailed Description

template<class ScalingFactor, class NestedAccessor>
class arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >

Accessor wrapper to automatically apply a constant scaling factor to all accessed elements.

Template Parameters
ScalingFactorType of the scaling factor to use; must be a scalar in the linalg sense
NestedAccessorType of the underlying data accessor to use; must be an mdspan accessor policy

Backport of std::linalg::scaled_accessor from C++26. Provides access to an underlying data array such that the elements of the array are automatically scaled by a constant factor before being returned.

Note
C++26 only requires ScalingFactor to be semiregular, but we require it to be a linalg scalar since this class represents a combination of data access with linalg scalar multiplication.

Member Typedef Documentation

◆ data_handle_type

template<class ScalingFactor, class NestedAccessor>
using arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::data_handle_type = typename NestedAccessor::data_handle_type

Data handle type.

◆ element_type

template<class ScalingFactor, class NestedAccessor>
using arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::element_type
Initial value:
const

Element type of the element space mapped by the access function (no elements of this type are stored)

◆ offset_policy

template<class ScalingFactor, class NestedAccessor>
using arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::offset_policy = scaled_accessor<ScalingFactor, typename NestedAccessor::offset_policy>

Offset policy type.

◆ reference

template<class ScalingFactor, class NestedAccessor>
using arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::reference = std::remove_const_t<element_type>

Reference type yielded by calls to the access function.

Note
Despite the name, this type is not actually a reference, because access returns temporary values instead.

Constructor & Destructor Documentation

◆ scaled_accessor() [1/4]

template<class ScalingFactor, class NestedAccessor>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::scaled_accessor ( )
constexprdefault

Default constructor.

◆ scaled_accessor() [2/4]

template<class ScalingFactor, class NestedAccessor>
template<class OtherNestedAccessor, constraints< std::enable_if_t< std::is_convertible< OtherNestedAccessor, NestedAccessor >::value > > = nullptr>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::scaled_accessor ( scaled_accessor< ScalingFactor, OtherNestedAccessor > other)
inlineconstexprnoexcept

Converting constructor; implicit SFINAE overload for when the nested accessors are implicitly convertible.

Template Parameters
OtherNestedAccessorAccessor type of the other scaled_accessor
Parameters
otherA scaled_accessor with the same ScalingFactor type but possibly a different NestedAccessor

◆ scaled_accessor() [3/4]

template<class ScalingFactor, class NestedAccessor>
template<class OtherNestedAccessor, constraints< std::enable_if_t< std::is_constructible< NestedAccessor, OtherNestedAccessor >::value >, std::enable_if_t<!std::is_convertible< OtherNestedAccessor, NestedAccessor >::value > > = nullptr>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::scaled_accessor ( scaled_accessor< ScalingFactor, OtherNestedAccessor > other)
inlineexplicitconstexprnoexcept

Converting constructor; explicit SFINAE overload for when the nested accessors are explicitly constructible.

Template Parameters
OtherNestedAccessorAccessor type of the other scaled_accessor
Parameters
otherA scaled_accessor with the same ScalingFactor type but possibly a different NestedAccessor

◆ scaled_accessor() [4/4]

template<class ScalingFactor, class NestedAccessor>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::scaled_accessor ( ScalingFactor const & scale,
NestedAccessor const & inner_accessor )
inlineconstexprnoexcept

Construct a scaled_accessor from a scaling factor and an instance of the nested accessor.

Parameters
scaleSpecific scaling factor to use for this accessor
inner_accessorInstance of the nested accessor to use

Member Function Documentation

◆ access()

template<class ScalingFactor, class NestedAccessor>
auto arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::access ( data_handle_type handle,
std::size_t index ) const -> reference
inlineconstexprnoexcept

Obtain the element at the specified index, multiplied by the scaling factor.

Parameters
handleHandle to the underlying data
indexOffset from the first element
Returns
The indexth element of the given data buffer, multiplied by scaling_factor()
Note
Despite the return type name, the data returned by this function is not a reference, it's a value.
Warning
This performs an unchecked multiplication of scaling_factor() and the accessed element. Depending on their values, this may lead to infinities, NaNs, or undefined behaviour (e.g. from signed integer overflow).

◆ ARENE_IGNORE_CLANG() [1/2]

template<class ScalingFactor, class NestedAccessor>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::ARENE_IGNORE_CLANG ( "-Wimplicit-int-float-conversion" ,
"The noexcept specification is unevaluated so it can't lose information"  )

◆ ARENE_IGNORE_CLANG() [2/2]

template<class ScalingFactor, class NestedAccessor>
arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::ARENE_IGNORE_CLANG ( "-Wsign-conversion" ,
"The noexcept specification is unevaluated so it can't lose information"  )

◆ nested_accessor()

template<class ScalingFactor, class NestedAccessor>
auto arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::nested_accessor ( ) const -> NestedAccessor const&
inlineconstexprnoexcept

Get the specific nested accessor used by this accessor.

Returns
A reference to the underlying accessor used to get data references

◆ offset()

template<class ScalingFactor, class NestedAccessor>
auto arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::offset ( data_handle_type handle,
std::size_t index ) const -> typename offset_policy::data_handle_type
inlineconstexprnoexcept

apply an offset to a pointer

Parameters
handleHandle to the underlying data
indexoffset to apply
Returns
data handle after applying the offset

◆ scaling_factor()

template<class ScalingFactor, class NestedAccessor>
auto arene::base::linalg::scaled_accessor< ScalingFactor, NestedAccessor >::scaling_factor ( ) const -> ScalingFactor const&
inlineconstexprnoexcept

Get the specific scaling factor used by this accessor.

Returns
A reference to the scaling factor applied to all accessed data

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