-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwin_error.h
36 lines (27 loc) · 1005 Bytes
/
win_error.h
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
#pragma once
#include <Windows.h>
#define _WD(x) L##x
#define WD(x) _WD(x)
#define panic_if_win_err(code, ...) _panic_if_win_err(code, __LINE__, WD(__FILE__))
#define panic_if_win_null(value) _panic_if_win_null(value, __LINE__, WD(__FILE__))
[[noreturn]] void panic_win(int line, WCHAR const* file);
void _panic_if_win_err_impl(DWORD error_code, int line, WCHAR const* file);
template<typename value_type>
inline value_type _panic_if_win_null(value_type value, int line, WCHAR const* file) {
if(value) {
return value;
}
panic_win(line, file);
}
template<typename... arg_types>
inline auto _panic_if_win_err(auto value, int line, WCHAR const* file, arg_types... args) {
if constexpr(sizeof...(args) == 0) {
_panic_if_win_err_impl((DWORD) (LONGLONG) value, line, file);
return value;
} else {
if(((value == args) || ... || false)) {
return value;
}
_panic_if_win_err_impl((DWORD) (LONGLONG) value, line, file);
}
}