Loading...
Searching...
No Matches
when.hpp
Go to the documentation of this file.
1
4#pragma once
5
7#include "indep/def/_nout.hpp"
12#include <cstdlib>
13#include <functional>
14#include <utility>
15
16namespace by {
17
82#define __WHEN_OBJECT__ __indep_when__
83
84 class _nout __WHEN_OBJECT__ {
85 BY(ME(__WHEN_OBJECT__))
86
87 public:
88 static const me& get();
89
90 template <typename R> R& ret([[maybe_unused]] R& r) const { return r; }
91
92 template <typename R> R* ret([[maybe_unused]] R* r) const { return r; }
93
94 template <typename R> R&& ret([[maybe_unused]] R&& r) const { return std::move(r); }
95
96 const me& run(const std::function<void(void)>& closure) const;
97
98 void ret() const;
99
100 template <typename T> tmay<T> retMay() const { return tmay<T>(); }
101
102 template <typename T, typename... Ts> tmay<T> retMay(Ts... args) const { return tmay<T>(args...); }
103
104 void crash() const;
105
106 template <typename R> R& crash([[maybe_unused]] R& r) const {
107 abort();
108 return r;
109 }
110
111 template <typename R> R&& crash([[maybe_unused]] R&& r) const {
112 abort();
113 return std::move(r);
114 }
115 };
116
117#define BY_WHEN ::by::__WHEN_OBJECT__::get()
118
119#define __WHEN_POSTFIX__ return BY_WHEN
120#define WHEN(condition) \
121 if(condition) __WHEN_POSTFIX__
122#define WHEN_NUL_1(v1) \
123 if(nul(v1)) __WHEN_POSTFIX__
124#define WHEN_NUL_2(v1, v2) \
125 if(nul(v1) || nul(v2)) __WHEN_POSTFIX__
126#define WHEN_NUL_3(v1, v2, v3) \
127 if(nul(v1) || nul(v2) || nul(v3)) __WHEN_POSTFIX__
128#define WHEN_NUL_4(v1, v2, v3, v4) \
129 if(nul(v1) || nul(v2) || nul(v3) || nul(v4)) __WHEN_POSTFIX__
130#define WHEN_NUL_5(v1, v2, v3, v4, v5) \
131 if(nul(v1) || nul(v2) || nul(v3) || nul(v4) || nul(v5)) __WHEN_POSTFIX__
132#define WHEN_NUL_6(v1, v2, v3, v4, v5, v6) \
133 if(nul(v1) || nul(v2) || nul(v3) || nul(v4) || nul(v5) || nul(v6)) __WHEN_POSTFIX__
134#define WHEN_NUL(...) BY_OVERLOAD(WHEN_NUL, __VA_ARGS__)
135
136} // namespace by
Conditional logging utility for clog module.
Definition when.hpp:84
Function or object evaluation arguments.
Definition args.hpp:22
func closure with captured object scope
Definition closure.hpp:20
Weak reference smart pointer with type-safe access.
Definition tweak.hpp:16
to Top