跳到正文

个人记录

useful functions

Eason_wu约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年11月5日
收录
2025年12月12日
更新
2026年11月6日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

bool is_sorted(bg,ed)

checks if the elements in [bg,ed)is sorted in non-descending order.


T max_element(bg,ed) and T min_element(bg,ed)

returns the max or min value in [bg,ed)


void shuffle(bg,ed,gen)

mix [bg,ed) with gen(a mt19937’s instance)


iota(bg,ed,val) —> val,val+1,val+2,…,val+ed-1-bg


accumulate(bg,ed,init)

CPP reference

C++
template<class InputIt, class T>
constexpr // since C++20
T accumulate(InputIt first, InputIt last, T init)
{
    for (; first != last; ++first)
        init = std::move(init) + *first; // std::move since C++20

    return init;
}

get sum or multiple

原文