Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef COMPUTERSCIENCE_ANGULAR_OPERATOR_H
- #define COMPUTERSCIENCE_ANGULAR_OPERATOR_H
- template <typename LHS, typename RHS, typename RET> struct AngularOperator;
- template <typename LHS, typename RHS, typename RET>
- struct InnerAngularOperator {
- const AngularOperator<LHS, RHS, RET>* outer;
- LHS* lhs;
- bool outer_l;
- RET operator>(RHS& rhs) {
- return (outer_l) ? outer->angular_lr(*lhs, rhs) : outer->angular_rr(*lhs, rhs);
- }
- RET operator<(RHS& rhs) {
- return (outer_l) ? outer->angular_ll(*lhs, rhs) : outer->angular_rl(*lhs, rhs);
- }
- };
- template <typename LHS, typename RHS, typename RET>
- struct AngularOperator {
- explicit AngularOperator() { }
- virtual RET operator()(LHS& lhs, RHS& rhs) const = 0;
- virtual RET angular_lr(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
- virtual RET angular_rr(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
- virtual RET angular_ll(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
- virtual RET angular_rl(LHS& lhs, RHS& rhs) const { return operator()(lhs, rhs); }
- };
- template <typename LHS, typename RHS, typename RET>
- InnerAngularOperator<LHS, RHS, RET> operator<(LHS& lhs, const AngularOperator<LHS, RHS, RET>& outer) {
- return {&outer, &lhs, true};
- };
- template <typename LHS, typename RHS, typename RET>
- InnerAngularOperator<LHS, RHS, RET> operator>(LHS& lhs, const AngularOperator<LHS, RHS, RET>& outer) {
- return {&outer, &lhs, false};
- };
- #endif //COMPUTERSCIENCE_ANGULAR_OPERATOR_H
- using namespace std;
- static const struct OP__ANG__STRING_CONCAT : AngularOperator<string, string, string> {
- string operator()(string& lhs, string& rhs) const override { return lhs + rhs; }
- } C{};
- std::string a = "123", b = "456";
- std::string c = a <C> b;
- // c == "123456
Add Comment
Please, Sign In to add comment