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