#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