diff options
Diffstat (limited to 'example/operators.cc')
-rw-r--r-- | example/operators.cc | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/example/operators.cc b/example/operators.cc index 14fa00b..68033dc 100644 --- a/example/operators.cc +++ b/example/operators.cc @@ -5,22 +5,20 @@ #include <vector> #include <list> - template<class S, class T> static void dump(S const &s, T const &v) { std::cout << s << '{'; - for( auto const &x : v ){ - std::cout << x << ", "; - } + for( auto const &x : v ){ std::cout << x << ", "; } std::cout << '}' << std::endl; } int main(int argc, char *argv[]) { + // syntactic sugar operators for same container, same type using namespace dwu::operators; - std::vector<int> va = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector<int> va = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; dump("va: ", va); auto vb = va + 10; @@ -37,12 +35,33 @@ int main(int argc, char *argv[]) dump("vd = vb * vc: ", vd); { + // syntactic sugar for mixed container, mixed type using namespace dwu::operators_xcxt; std::list<float> la = {100, 101, 101, 103, 104, 105}; dump("la: ", la); - auto rr = la - vd; - dump("rr = la - vd: ", rr); + auto r_ad = la - vd; + dump("r_ad = la - vd: ", r_ad); + } + + { + // syntactic sugar for mixed container, same type + using namespace dwu::operators_xc; + std::list<int> lb = {200, 201, 201, 203, 204, 205}; + dump("lb: ", lb); + + auto r_bd = lb + vd; + dump("r_bd = lb + vd: ", r_bd); + } + + { + // syntactic sugar for same container, mixed type + using namespace dwu::operators_xt; + std::vector<float> ve = {300, 301, 301, 303, 304, 305}; + dump("ve: ", ve); + + auto r_ed = ve / vd; + dump("r_ed = ve / vd: ", r_ed); } return 0; |