KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

Callable object computing the sum of all elements. More...

Variables

constexpr sum_t kumi::sum {}

Detailed Description

Callable object computing the sum of all elements.

Variable Documentation

◆ sum

sum_t kumi::sum {}
inlineconstexprnodiscard

On record types, this function operates on the underlying values, not on the fields themselves.

Note
For associative operations, this produces the same result as a left or right fold, but has a different intermediate evaluation order.

inline constexpr

Header file

#include <kumi/kumi.hpp>

Call Signature

namespace kumi
{
template<concepts::product_type T>
constexpr auto sum(T && t);
template<concepts::product_type T, typename V>
constexpr auto sum(T && t, V init);
}
constexpr sum_t sum
Definition reduce.hpp:376
Main KUMI namespace.
Definition algorithm.hpp:11

Parameters

  • t: Product Type to operate on
  • init: Optional initial value of the reduction.

Return value

The result of the computation of `get<0>(t) + ... + get<N-1>(t) + init`

Helper type

namespace kumi::result
{
template<product_type T, typename Value> struct sum;
template<product_type T, typename Value>
using sum_t = typename sum<T,Value>::type;
}

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

Examples

  • Tuple
    #include <kumi/kumi.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
  • Record
    #include <kumi/kumi.hpp>
    #include <iostream>
    int main()
    {
    using namespace kumi::literals;
    auto r = kumi::record{"a"_id = 2.,"b"_id = 1,"c"_id = short{55},"d"_id = ' '};
    std::cout << kumi::sum(r, 100) << "\n";
    std::cout << kumi::sum(r) << "\n";
    }
    Fixed-size collection of heterogeneous fields with distinct labels.
    Definition record.hpp:36