fork(2) download
  1. #include <iostream>
  2.  
  3. template <class T>
  4. class Maybe {
  5. bool is_ = false;
  6. T value_;
  7.  
  8. public:
  9. constexpr Maybe() = default;
  10. constexpr Maybe(T value) : is_(true), value_(value) {}
  11.  
  12. constexpr bool is() const { return is_; }
  13. };
  14.  
  15. Maybe<int> not_set_;
  16. Maybe<int> is_set_(2);
  17.  
  18. template <const Maybe<int>& parm>
  19. struct Test {
  20. void say() const {
  21. std::cout << "parm is " << (parm.is() ? "set" : "not set") << ".\n";
  22. }
  23. };
  24.  
  25. int main() {
  26. Test<not_set_> not_set;
  27. Test<is_set_> is_set;
  28.  
  29. not_set.say();
  30. is_set.say();
  31. }
  32.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
parm is not set.
parm is set.