-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfwd.hpp
More file actions
48 lines (35 loc) · 1.07 KB
/
fwd.hpp
File metadata and controls
48 lines (35 loc) · 1.07 KB
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
#pragma once
#ifndef SAFE_INLINE
#define SAFE_INLINE inline
#endif
namespace safe {
template <typename T, auto Requirement> struct var;
template <typename T> constexpr bool is_var_v = false;
template <typename T, auto Requirement>
constexpr bool is_var_v<var<T, Requirement>> = true;
template <typename T>
concept Var = is_var_v<T>;
[[nodiscard]] constexpr inline auto value(auto value);
namespace detail {
template <typename U, U value>
[[nodiscard]] constexpr inline auto make_constant();
}
template <typename T> struct unsafe_cast_ferry {
private:
T v;
public:
SAFE_INLINE constexpr explicit(true) unsafe_cast_ferry(T new_value)
: v{new_value} {}
[[nodiscard]] SAFE_INLINE constexpr auto value() const -> T { return v; }
};
} // namespace safe
template <typename T>
requires(safe::Var<T>)
[[nodiscard]] SAFE_INLINE constexpr auto unsafe_cast(auto const &src) {
return T{safe::unsafe_cast_ferry{src}};
}
template <typename T>
requires(!safe::Var<T>)
[[nodiscard]] SAFE_INLINE constexpr auto unsafe_cast(auto const &src) {
return src;
}