match.cpp 639 B

123456789101112131415161718192021222324252627282930313233343536
  1. //
  2. // match.cpp
  3. // case-matcher
  4. //
  5. // Created by Sam Jaffe on 9/10/16.
  6. //
  7. #include <iostream>
  8. #include "match.hpp"
  9. struct example {
  10. example(long in) : i(in) {}
  11. example(example const &) : i(0xDEADBEEF) {}
  12. long i;
  13. };
  14. bool operator==(example const & a, example const & b) {
  15. return a.i == b.i;
  16. }
  17. int main() {
  18. example const ex{1};
  19. bool b{true};
  20. match(ex, b) {
  21. with(example{1}, false) {
  22. std::cout << "Match 1" << std::endl;
  23. }
  24. with(example{0xDEADBEEF}, matcher::any) {
  25. std::cout << "Match 2" << std::endl;
  26. }
  27. with(matcher::any, true) {
  28. std::cout << "Match 3" << std::endl;
  29. }
  30. }
  31. }