okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-189 (PR #189, the conversation snapshot core and RAM cache) into rel-0.1.30abbf12caf

main
704 B24 linesraw
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <initializer_list>
6#include <limits>
7
8namespace strata::core::conversation_detail {
9inline bool add(size_t& total, size_t n) {
10    if (n > std::numeric_limits<size_t>::max() - total) return false;
11    total += n;
12    return true;
13}
14inline bool product(size_t& out, std::initializer_list<uint64_t> factors) {
15    size_t value = 1;
16    for (uint64_t factor : factors) {
17        if (factor > std::numeric_limits<size_t>::max() ||
18            (factor && value > std::numeric_limits<size_t>::max() / factor)) return false;
19        value *= (size_t) factor;
20    }
21    out = value;
22    return true;
23}
24} // namespace strata::core::conversation_detail