1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #pragma once
- #include <functional>
- #include "Betriebssystem.h"
- namespace Framework
- {
- template<typename A, typename B> class Either
- {
- private:
- A aValue;
- B bValue;
- bool a;
- public:
- Either(const Either<A, B>& b)
- {
- a = b.isA();
- if (a)
- aValue = (A)b;
- else
- bValue = (B)b;
- }
- Either(A a)
- {
- aValue = a;
- this->a = 1;
- }
- Either(B b)
- {
- bValue = b;
- a = 0;
- }
- bool isA() const
- {
- return a;
- }
- bool isB() const
- {
- return !a;
- }
- A getA() const
- {
- return aValue;
- }
- B getB() const
- {
- return bValue;
- }
- void doIfA(std::function<A> action)
- {
- if (a) action(aValue);
- }
- void doIfB(std::function<B> action)
- {
- if (!a) action(bValue);
- }
- operator A() const
- {
- assert(a);
- return aValue;
- }
- operator B() const
- {
- assert(!a);
- return bValue;
- }
- };
- } // namespace Framework
|