Either monad in C++11 I'm using C++11 with https://github.com/SmingHub/Sming. It has no support of std lib or exceptions. I wanted to use Either monad to return an error or result from my functions.
I implemented it using class hierarchy. I'm not a native C++ dev so I would be glad for the code review.
#pragma once

template &lt;class L, class R&gt; 
class Either
{
    virtual bool isLeft();
    virtual bool isRight();

    virtual bool matchLeft(L&amp; x);
    virtual bool matchRight(R&amp; x);
};

template &lt;class L, class R&gt; 
class Left : public Either&lt;L, R&gt; {
public:
    L left;

    Left(L left): left(left) {}
    constexpr bool isLeft() { return true; }
    constexpr bool isRight() { return false; }

    bool matchLeft(L&amp; x)
    {
        x = left;
        return true;
    }
    bool matchRight(R&amp; x) { return false; }
};

template &lt;class L, class R&gt; 
class Right : public Either&lt;L, R&gt; {
public:
    R right;

    Right(R right): right(right) {}
    constexpr bool isLeft() { return false; }
    constexpr bool isRight() { return true; }

    bool matchLeft(L&amp; x) { return false; }

    bool matchRight(R&amp; x) {
        x = right;
        return true;
    }
};
Your Either-monad suffers from a fatal flaw:
It is impossible to return an Either which might be either possibility.
You can only return a Left or a Right, an Either must per force be a pointer or reference to one of those.
Without help from the compiler in automatically deducing a return-type of Either&lt;T, U&gt; if it finds returns of a combination of Either&lt;T, U&gt;, Left&lt;T&gt; and Right&lt;U&gt; sufficient to deduce T and U, or at least adding pattern-matching, Left and Right are pretty much useless.
In the end, that just leaves Either, which is now only a poor-mans substitute for full-fledged std::variant of two.