Documentation of CSL
conditional.h
Go to the documentation of this file.
1 // This file is part of MARTY.
2 //
3 // MARTY is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // MARTY is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with MARTY. If not, see <https://www.gnu.org/licenses/>.
15 
23 #ifndef CONDITIONAL_H_INCLUDED
24 #define CONDITIONAL_H_INCLUDED
25 
26 #include <optional>
27 #include <functional>
28 
29 namespace csl {
30 
31 template<class ...Args>
33 
34  using cond_t = std::function<bool(Args...)>;
35 
36  public:
37 
39  :condition([]([[maybe_unused]]Args&& ...args) { return true; })
40  {
41 
42  }
43 
44  OptionalCondition(std::optional<cond_t> t_condition)
45  :condition(t_condition)
46  {
47 
48  }
49 
50  operator bool() const
51  {
52  return condition.operator bool();
53  }
54 
55  bool operator()(Args ...args) const
56  {
57  if (not condition)
58  return true;
59  return condition.value()(args...);
60  }
61 
62  private:
63 
64  std::optional<cond_t> condition;
65 };
66 } // End of namespace csl
67 
68 #endif
Namespace for csl library.
Definition: abreviation.h:34
Definition: conditional.h:32