FreeTensor
Loading...
Searching...
No Matches
maybe_void.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_MAYBE_VOID_H
2#define FREE_TENSOR_MAYBE_VOID_H
3
4#include <type_traits>
5#include <variant>
6
7namespace freetensor {
8
9template <class T> struct TypeOrMonostate { typedef T type; };
10template <> struct TypeOrMonostate<void> { typedef std::monostate type; };
11
15#define MAYBE_VOID_ASSIGN(name, expr) \
16 if constexpr (std::is_same_v<decltype(expr), void>) { \
17 expr; \
18 } else { \
19 name = expr; \
20 }
21
25#define MAYBE_VOID(name, expr) \
26 [[maybe_unused]] typename TypeOrMonostate<decltype(expr)>::type name; \
27 MAYBE_VOID_ASSIGN(name, expr)
28
29} // namespace freetensor
30
31#endif // FREE_TENSOR_MAYBE_VOID_H
Definition: allocator.h:9
std::monostate type
Definition: maybe_void.h:10
Definition: maybe_void.h:9
T type
Definition: maybe_void.h:9