blob: 45be139ebc9fbc2b7fb64e7b06af6115246a1fcb (
plain)
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
|
#ifndef MYGRATE_HELPERS_H
#define MYGRATE_HELPERS_H
#include <concepts>
#include <cstdint>
#include <cstdlib>
#include <string>
#include <utility>
namespace MyGrate {
template<std::integral I>
constexpr inline auto
bitslice(const I i, uint8_t offset, uint8_t size)
{
return (i >> offset) & ((1U << size) - 1U);
}
template<typename X, typename R, typename... P>
constexpr inline auto
verify(R expr, P &&... p)
{
if (!expr) {
throw X(std::forward<P>(p)...);
}
return expr;
}
template<typename T>
constexpr inline auto
mod100_extract(T & i)
{
const auto r {i % 100};
i /= 100;
return r;
}
template<typename T>
concept Stringable = requires(T a)
{
{
std::to_string(a)
} -> std::same_as<std::string>;
};
template<typename T>
concept Viewable = requires(T a)
{
{
a.data()
} -> std::convertible_to<const char *>;
{
a.size()
} -> std::integral;
};
inline const char *
getenv(const char * env, const char * dfl)
{
if (const auto e {::getenv(env)}) {
return e;
}
return dfl;
}
}
#endif
|