Pecunia 0.9.0-alpha.22
Library using the ISO-4217 currency standard & a fixed monetary unit size
Loading...
Searching...
No Matches
pecunia::math Namespace Reference

Functions

PECUNIA_EXPORT Money absoluteValue (const Money &money)
 Calculates the absolute value for the supplied amount of money.
 
template<template< typename, typename, typename, typename > typename AssociativeContainer, typename KeyType , typename ValueType , typename Compare = std::less<KeyType>, typename Allocator = std::allocator<std::pair<const KeyType, ValueType>>>
Money sum (const Currency &accumulateIn, const AssociativeContainer< KeyType, ValueType, Compare, Allocator > &elements, const std::optional< std::function< Money(const Money &money)> > &adjustor=std::nullopt)
 Accumulates the total of all the supplied monies with the fewest possible number of conversions.
 
template<typename Container >
Money sum (const Currency &accumulateIn, const Container &elements, const std::optional< std::function< Money(const typename Container::value_type &)> > &mutator=std::nullopt)
 Sums up a collection of monetary values, potentially transformed by a user-defined mutator function, with the fewest possible number of conversions.
 

Function Documentation

◆ absoluteValue()

PECUNIA_EXPORT Money pecunia::math::absoluteValue ( const Money & money)
nodiscard

Calculates the absolute value for the supplied amount of money.

Parameters
moneyThe money whose monetary amount should be an absolute value.
Returns
The absolute value of the monetary amount.

◆ sum() [1/2]

template<template< typename, typename, typename, typename > typename AssociativeContainer, typename KeyType , typename ValueType , typename Compare = std::less<KeyType>, typename Allocator = std::allocator<std::pair<const KeyType, ValueType>>>
Money pecunia::math::sum ( const Currency & accumulateIn,
const AssociativeContainer< KeyType, ValueType, Compare, Allocator > & elements,
const std::optional< std::function< Money(const Money &money)> > & adjustor = std::nullopt )
nodiscard

Accumulates the total of all the supplied monies with the fewest possible number of conversions.

Precondition
When an adjustor is supplied, it cannot be null.
Template Parameters
AssociativeContainerThe associative container type holding the money.
KeyTypeThe type the monies are keyed against, not used.
ValueTypeThe value type in the container, which must include monetary amounts.
CompareThe comparison type used for ordering elements in the container.
AllocatorThe allocator type used for memory management in the container.
Parameters
accumulateInThe currency in which the final sum will be accumulated.
elementsThe container holding monetary pairs to be summed.
adjustorAn optional function to adjust each monetary value during summation. If not provided, no adjustments are applied.
Returns
The result of the summation as a monetary value in the specified currency.

◆ sum() [2/2]

template<typename Container >
Money pecunia::math::sum ( const Currency & accumulateIn,
const Container & elements,
const std::optional< std::function< Money(const typename Container::value_type &)> > & mutator = std::nullopt )
nodiscard

Sums up a collection of monetary values, potentially transformed by a user-defined mutator function, with the fewest possible number of conversions.

Precondition
When a mutator is supplied, it cannot be null.
When a container’s element is not a Money type, the adjustor must be supplied.
Template Parameters
ContainerA container type that holds values convertible to pecunia::Money.
Parameters
accumulateInThe currency in which the result will be accumulated.
elementsThe container of elements to be summed.
mutatorAn optional function to transform container elements to pecunia::Money before summing or apply an adjustment before summing.
Returns
The sum of all elements in the container in the currency provided.