#pragma once struct Left{}; struct Right{}; template class Either{ T *left; U *right; public: Either(Left,const T &l) :left(new T(l)),right(nullptr){} Either(Right,const U &r) :left(nullptr),right(new U(r)){} Either(const Either &other){ if(other.left)left=new T(*other.left); if(other.right)right=new U(*other.right); } ~Either(void){ if(left)delete left; if(right)delete right; } T fromLeft(void) const { return *left; } U fromRight(void) const { return *right; } bool isLeft(void) const { return (bool)left; } bool isRight(void) const { return (bool)right; } };