E.V.E  0.1-beta

◆ add

eve::add = {}
inlineconstexpr

Callable object performing the sum of multiple values.

Required header: #include <eve/function/add.hpp>

Members Functions

Member Effect
operator() Computes the sum of its parameter
operator[] Construct a conditional version of current function object

auto operator()(eve::value auto const&... xs) const noexcept;
Definition: value.hpp:31

Parameters

xs: Instances of eve::value

Return value

A value of the common compatible type of all xs containing the elementwise sum of all xs.

Warning
Although the infix notation with + is supported for two parameters, the + operator on standard scalar types is the original one and so can lead to automatic promotion.

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::add

Parameters

cond : conditional expression

Return value

A Callable object so that the expression add[cond](x0,xs...) is equivalent to if_else(cond,add(x0,xs...),x0)


Supported decorators

Example

See it live on Compiler Explorer

#include <eve/function/add.hpp>
#include <eve/function/saturated/add.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
w_t pi = {3, 2, -32700, 32700}, qi = {4, 1, -100, 100};
std::cout << "---- simd" << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " -> add(pi, qi) = " << eve::add(pi, qi) << '\n'
<< " -> pi + qi = " << pi + qi << '\n'
<< " -> saturated(add)(pi, qi) = " << eve::saturated(eve::add)(pi, qi) << '\n';
std::int16_t xi = 100, yi = 32700;
std::cout << "---- scalar" << '\n'
<< " <- xi = " << xi << '\n'
<< " <- yi = " << yi << '\n'
<< " -> add(xi, yi) = " << eve::add(xi, yi) << '\n'
<< " -> xi + yi = " << xi + yi << '\n'; // C++ promotion to int
std::cout << "---- multi parameters" << '\n'
<< " -> add(pi, pi, pi, 1) = " << eve::add(pi, pi, pi, 1) << '\n'
<< " -> saturated(eve::add)(pi,12, pi,pi) = " << eve::saturated(eve::add)(pi, 12, pi,pi) << '\n';
return 0;
}
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
constexpr saturated_type const saturated
Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
Definition: saturated.hpp:68
constexpr callable_add_ add
Callable object performing the sum of multiple values.
Definition: add.hpp:89
Wrapper for SIMD registers.
Definition: wide.hpp:65