1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- #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;
- }
- };
- }
|