useful functions

· · 个人记录

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

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