1 #ifndef LICORNEA_UTILITY_MISC_H_ 2 #define LICORNEA_UTILITY_MISC_H_ 14 template<
typename...>
using void_t = void;
17 template<
typename Numeric> Numeric
sq(Numeric n) {
return n * n; }
20 template<
typename T,
typename T2,
typename T3>
21 T
clamp(T value, T2 minimum, T3 maximum);
24 template<
typename T> T
gcd(T a, T b);
27 template<
typename T> T
lcm(T a, T b);
32 return (x != 0) && !(x & (x - 1));
36 template<
typename T,
typename T2>
38 return (x % base == 0);
42 template<
typename T,
typename T2>
49 bool is_odd(T x) {
return (x % 2) != 0; }
53 bool is_even(T x) {
return (x % 2) == 0; }
62 std::uniform_int_distribution<T> dist(a, b);
72 using decayed_t = std::decay_t<T>;
73 return std::make_shared<decayed_t>(std::forward<T>(t));
81 using decayed_t = std::decay_t<T>;
82 return std::make_shared<const decayed_t>(std::forward<T>(t));
T gcd(T a, T b)
Compute greatest common divisor of a and b.
Numeric sq(Numeric n)
Compute square of a number.
auto forward_make_shared(T &&t)
Get shared_ptr to new object copy- or move- constructed from t.
bool is_multiple_of(T x, T2 base)
Check if x is a multiple of base, including zero.
T lcm(T a, T b)
Compute least common multiple of a and b.
bool is_power_of_two(T x)
Check if x is a power of 2.
std::mt19937 default_random_engine
bool is_nonzero_multiple_of(T x, T2 base)
Check if x is a non-zero multiple of base.
default_random_engine & random_engine()
T clamp(T value, T2 minimum, T3 maximum)
Clamp value between minimum and maximum value.
bool is_odd(T x)
Check if x is odd.
auto forward_make_shared_const(T &&t)
Get shared_ptr to new const object copy- or move- constructed from t.
bool is_even(T x)
Check if x is even.