123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #pragma once
- #include <functional>
- #include "Betriebssystem.h"
- namespace Frmaework
- {
- template<typename T> class Maybe
- {
- private:
- bool set;
- T value;
- Maybe()
- {
- set = 0;
- }
- public:
- static Maybe<T> of(T value)
- {
- return {1, value};
- }
- static Maybe<T> empty()
- {
- return {0, value};
- }
- bool isEmpty() const
- {
- return !set;
- }
- bool isPresent() const
- {
- return set;
- }
- operator T() const
- {
- assert(set);
- return value;
- }
- void ifPresent(std::function<T> action)
- {
- if (set) action(value);
- }
- void ifNotPresent(std::function<T> action)
- {
- if (!set) action(value);
- }
- T operator->()
- {
- assert(set);
- return current->var;
- }
- };
- } // namespace Frmaework
|