Iros
 
Loading...
Searching...
No Matches
monad_try.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/util/move.h"
4
5#if __GNUC__ >= 13
6// NOTE: GCC 13 thinks that calling DI_TRY() on a di::Result<int&> produces a dangling reference, because the result
7// object gets destroyed before the reference is used. However, di::Result<int&> is essentially a pointer type, so this
8// is not a problem. Unfortunately, since this occurs in a macro, this warning cannot be suppressed only inside this
9// header file.
10#pragma GCC diagnostic ignored "-Wdangling-reference"
11#endif
12
13#define DI_TRY(...) \
14 __extension__({ \
15 auto __result = (__VA_ARGS__); \
16 if (!__result) { \
17 return di::util::move(__result).__try_did_fail(); \
18 } \
19 di::util::move(__result).__try_did_succeed(); \
20 }).__try_move_out()
21
22#if !defined(DI_NO_GLOBALS) && !defined(DI_NO_GLOBAL_TRY)
23#define TRY DI_TRY
24#endif