kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches

◆ sum() [2/2]

template<product_type Tuple, typename Value >
constexpr auto kumi::sum ( Tuple &&  t,
Value  init 
)
constexpr

Computes the sum of all elements.

Parameters
tTuple to operate on.
initOptional initial value of the sum.
Returns
The value of get<0>(t) + ... + get<N-1>(t) + init

Helper type

namespace kumi::result
{
template<product_type Tuple, typename Value> struct sum;
template<product_type Tuple, typename Value>
using sum_t = typename sum_t<Tuple,Value>::type;
}
constexpr auto sum(Tuple &&t, Value init)
Computes the sum of all elements.
Definition: reduce.hpp:37

Computes the return type of a call to kumi::sum

Example

#include <kumi/tuple.hpp>
#include <iostream>
int main()
{
auto t = kumi::tuple{2.,1,short{55},' '};
std::cout << kumi::sum(t, 100) << "\n";
std::cout << kumi::sum(t) << "\n";
}
Fixed-size collection of heterogeneous values.
Definition: tuple.hpp:35