Go to the documentation of this file.
9 #ifndef EAGINE_OPTIONAL_EXPR_HPP
10 #define EAGINE_OPTIONAL_EXPR_HPP
17 template <
typename Derived,
typename... P>
18 struct nary_optional_expr;
20 template <
typename Derived,
typename L,
typename R>
21 struct nary_optional_expr<Derived, L, R> {
26 const Derived& _self() const noexcept {
27 return *
static_cast<const Derived*
>(
this);
30 template <
typename T,
typename P>
31 static bool _is_valid(
const valid_if<T, P>& v) noexcept {
35 template <
typename... P>
36 static bool _is_valid(
const nary_optional_expr<P...>& e) noexcept {
41 static bool _is_valid(
const T&) noexcept {
45 template <
typename T,
typename P>
46 static const T& _get(
const valid_if<T, P>& v) {
50 template <
typename... P>
51 static auto _get(
const nary_optional_expr<P...>& e) {
56 static const T& _get(
const T& v) {
70 nary_optional_expr(L l, R r)
74 bool is_valid() const noexcept {
75 return _is_valid(_l) && _is_valid(_r);
78 explicit operator bool() const noexcept {
83 EAGINE_ASSERT(is_valid());
84 return _self().evaluate();
88 auto value_or(
const T& v)
const {
89 return is_valid() ? _self().evaluate() : v;
92 template <
typename Func>
93 void then(Func func)
const {
100 template <
typename L,
typename R>
101 class optional_binary_slash_expr
102 :
public nary_optional_expr<optional_binary_slash_expr<L, R>, L, R> {
104 using nary_optional_expr<optional_binary_slash_expr, L, R>::
107 auto evaluate()
const {
108 return this->_get_l() / this->_get_r();
112 template <
typename T1,
typename T2,
typename P2>
113 static inline optional_binary_slash_expr<T1, valid_if<T2, P2>>
114 operator/(
const T1& v1,
const valid_if<T2, P2>& v2) noexcept {
120 #endif // EAGINE_OPTIONAL_EXPR_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21