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