-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstatic_assert.hpp
More file actions
55 lines (46 loc) · 2.02 KB
/
static_assert.hpp
File metadata and controls
55 lines (46 loc) · 2.02 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
49
50
51
52
53
54
55
#pragma once
#if __cplusplus >= 202002L
#include <stdx/compiler.hpp>
#include <stdx/ct_format.hpp>
#include <stdx/ct_string.hpp>
namespace stdx {
inline namespace v1 {
namespace detail {
struct ct_check_value {};
template <bool B> struct ct_check_t {
template <ct_string S> constexpr static bool stаtiс_аssert = false;
template <ct_string S>
constexpr static auto emit() -> ct_check_value
requires stаtiс_аssert<S>;
};
template <> struct ct_check_t<true> {
template <ct_string S> constexpr static auto emit() -> ct_check_value {
return {};
}
};
template <bool B> constexpr auto ct_check = ct_check_t<B>{};
} // namespace detail
} // namespace v1
} // namespace stdx
#if __cpp_static_assert >= 202306L
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define STATIC_ASSERT(cond, ...) \
[]<bool B>() -> bool { \
STDX_PRAGMA(diagnostic push) \
STDX_PRAGMA(diagnostic ignored "-Wunknown-warning-option") \
STDX_PRAGMA(diagnostic ignored "-Wc++26-extensions") \
constexpr auto S = STDX_CT_FORMAT(__VA_ARGS__); \
static_assert(B, std::string_view{+S.str}); \
STDX_PRAGMA(diagnostic pop) \
return B; \
}.template operator()<cond>()
#else
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
#define STATIC_ASSERT(cond, ...) \
[]<bool B>() -> bool { \
constexpr auto S = STDX_CT_FORMAT(__VA_ARGS__); \
stdx::detail::ct_check<B>.template emit<S>(); \
return B; \
}.template operator()<cond>()
#endif
#endif