Guest User

Untitled

a guest
Oct 17th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #ifndef COMPUTERSCIENCE_ANGULAR_OPERATOR_H
  2. #define COMPUTERSCIENCE_ANGULAR_OPERATOR_H
  3.  
  4. template <typename LHS, typename RHS, typename RET> struct AngularOperator;
  5.  
  6. template <typename LHS, typename RHS, typename RET>
  7. struct InnerAngularOperator {
  8. const AngularOperator<LHS, RHS, RET>* outer;
  9. LHS* lhs;
  10. bool outer_l;
  11.  
  12. RET operator>(RHS& rhs) {
  13. return (outer_l) ? outer->angular_lr(*lhs, rhs) : outer->angular_rr(*lhs, rhs);
  14. }
  15.  
  16. RET operator<(RHS& rhs) {
  17. return (outer_l) ? outer->angular_ll(*lhs, rhs) : outer->angular_rl(*lhs, rhs);
  18. }
  19. };
  20.  
  21. template <typename LHS, typename RHS, typename RET>
  22. struct AngularOperator {
  23. explicit AngularOperator() { }
  24.  
  25. virtual RET operator()(LHS& lhs, RHS& rhs) const = 0;
  26. virtual RET angular_lr(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
  27. virtual RET angular_rr(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
  28. virtual RET angular_ll(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
  29. virtual RET angular_rl(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
  30. };
  31.  
  32. template <typename LHS, typename RHS, typename RET>
  33. InnerAngularOperator<LHS, RHS, RET> operator<(LHS& lhs, const AngularOperator<LHS, RHS, RET>& outer) {
  34. return {&outer, &lhs, true};
  35. };
  36.  
  37. template <typename LHS, typename RHS, typename RET>
  38. InnerAngularOperator<LHS, RHS, RET> operator>(LHS& lhs, const AngularOperator<LHS, RHS, RET>& outer) {
  39. return {&outer, &lhs, false};
  40. };
  41.  
  42. #endif //COMPUTERSCIENCE_ANGULAR_OPERATOR_H
  43.  
  44. using namespace std;
  45.  
  46. static const struct OP__ANG__STRING_CONCAT : AngularOperator<string, string, string> {
  47. string operator()(string& lhs, string& rhs) const override { return lhs + rhs; }
  48. } C{};
  49.  
  50. std::string a = "123", b = "456";
  51. std::string c = a <C> b;
  52. // c == "123456
Add Comment
Please, Sign In to add comment