fork download
  1. #include <functional>
  2. #include <string>
  3.  
  4. enum MaybeType{
  5. _Nothing,
  6. _Just
  7. };
  8.  
  9. template<typename T>
  10. class Maybe{
  11. virtual MaybeType getType() const = 0;
  12. };
  13.  
  14. template<typename T>
  15. class Just : public Maybe<T>{
  16. T value;
  17. virtual MaybeType getType() const{
  18. return MaybeType::_Just;
  19. }
  20. public:
  21. Just(T v) : value(v){}
  22. };
  23.  
  24. template<typename T>
  25. class Nothing : public Maybe<T>{
  26. virtual MaybeType getType() const{
  27. return MaybeType::_Nothing;
  28. }
  29. };
  30.  
  31. int main(){
  32. using namespace std;
  33. string s = "Hello";
  34. auto m=Just<string>(s);
  35. }
  36.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
Standard output is empty