12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #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
- {
- assert(a);
- return aValue;
- }
- B getB() const
- {
- assert(!a);
- 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
|