-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynopsis.hpp
91 lines (65 loc) · 3.25 KB
/
synopsis.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#pragma once
#include <cstdint>
#include <optional>
#include "dumpster_v1/private.hpp"
namespace dumpster_v1 {
// defaulted.hpp ===============================================================
/// Default initializes a value with the given arguments.
template <class Value, auto... defaults> struct defaulted {
/// Default constructor initializes value with the defaults given as template
/// arguments.
defaulted();
/// Non-default constructor initializes value with given arguments.
template <class... Arguments> defaulted(Arguments &&... arguments);
/// Implicit conversion to const reference for convenience.
operator const Value &() const;
/// Implicit conversion to reference for convenience.
operator Value &();
/// The value is directly accessible as there is no reason to hide it.
Value value;
};
/// Zero initializes a value of the given type.
template <class Value> using zeroed = defaulted<Value, static_cast<Value>(0)>;
// finally.hpp =================================================================
/// Finalizer that invokes stored action when destroyed.
template <class Action> struct finalizer : Private::finalizer<Action> {
/// Calls the finalizing action given to the constructor.
~finalizer();
/// Constructs a finalizer from the given finalizing action.
template <class ForwardableAction> finalizer(ForwardableAction &&action);
/// Finalizers are not CopyConstructible.
finalizer(const finalizer &) = delete;
/// Finalizers are not CopyAssignable.
finalizer &operator=(const finalizer &) = delete;
};
/// Creates a finalizer that invokes the action when destroyed.
template <class Action>
finalizer<std::decay_t<Action>> finally(Action &&action);
/// Creates a finalizer wrapped inside an optional so that the finalizer can be
/// invoked explicitly by calling the `reset()` method.
template <class Action>
std::optional<finalizer<std::decay_t<Action>>>
finally_with_reset(Action &&action);
// insertion_sort.hpp ==========================================================
/// Sorts given sentinel terminated sequence to ascending order. Intended for
/// use cases where sequences are expected to be short, and low overhead and
/// small code size are desired.
template <class RandomIt, class Less, class IsSentinel>
void insertion_sort(RandomIt values, Less less, IsSentinel is_sentinel);
// primes.hpp ==================================================================
/// Returns the largest prime that is less than the given value rounded to the
/// next power of 2 or 1.
uint32_t prime_less_than_next_pow_2_or_1(uint32_t x);
/// Returns the largest prime that is less than the given value rounded to the
/// next power of 2 or 1.
uint64_t prime_less_than_next_pow_2_or_1(uint64_t x);
/// Returns the largest prime that is less than the given value rounded to the
/// next power of 2 or 1.
template <class UnsignedType,
class = std::enable_if_t<(std::is_unsigned_v<UnsignedType> &&
sizeof(UnsignedType) <= sizeof(uint64_t))>>
UnsignedType prime_less_than_next_pow_2_or_1(UnsignedType x);
// ranqd1.hpp ==================================================================
/// The `ranqd1` generator from Numerical Recipes in C, 2nd Edition.
uint32_t ranqd1(uint32_t seed);
} // namespace dumpster_v1