13template <
typename T =
size_t>
14constexpr T
to_size(std::ranges::range
auto &&xs) {
15 return static_cast<T
>(std::ranges::size(xs));
19constexpr auto to_first(std::ranges::range
auto &&xs) {
20 assert(not std::ranges::empty(xs));
25constexpr auto to_last = [](std::ranges::range
auto &&xs) {
26 assert(not std::ranges::empty(xs));
31constexpr auto to_sum(std::ranges::range
auto &&xs) {
32 return std::ranges::fold_left(
33 xs, 0.0, [](
const double acc,
double x) {
return acc + x; });
37constexpr auto to_sum2(std::ranges::range
auto &&xs) {
38 assert(not std::ranges::empty(xs));
40 const auto &&sum = std::ranges::fold_left(
41 xs,
decltype(xs[0]){}, [](
auto acc,
auto &&x) {
return acc + x; });
44 static_assert(std::is_same_v<std::remove_cvref_t<
decltype(xs[0])>,
45 std::remove_cvref_t<
decltype(sum)>>);
51constexpr auto identity = [](
auto &&xs) {
return xs; };
55 return std::forward<decltype(xs)>(xs);
59constexpr auto to_profit(
auto &&entry,
auto &&exit) {
60 auto &&profit =
decltype(entry){100.0f} * (exit - entry) / entry;
62 static_assert(std::is_same_v<
decltype(entry),
decltype(exit)>);
63 static_assert(std::is_same_v<
decltype(profit),
decltype(entry)>);
Core routines that don't depend on any other fx routines.
constexpr auto to_first(std::ranges::range auto &&xs)
Return the first entry in a series.
constexpr auto to_sum2(std::ranges::range auto &&xs)
Calculate sum of series.
constexpr auto to_last
Return the last entry in a series.
constexpr auto to_profit(auto &&entry, auto &&exit)
Calculate profit from a trade.
constexpr auto identity2
Just passing through.
constexpr auto to_sum(std::ranges::range auto &&xs)
Calculate sum of series.
constexpr auto identity
Just passing through.
constexpr T to_size(std::ranges::range auto &&xs)
Calculate size of a series, return type depends on input param.