#pragma once template class Maybe{ T *value; public: Maybe(void):value(NULL){} // 'Nothing' constructor Maybe(T v):value(new T(move(v))){} ~Maybe(void){ if(value)delete value; } T fromJust(void) const { return *value; } T fromMaybe(T &def) const { if(value)return *value; else return def; } bool isJust(void) const { return (bool)value; } bool isNothing(void) const { return !value; } static Maybe Nothing(void){ return Maybe(); } };