From 6ce13e4a51fdc67d24570e8475fff6f97bcca098 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Sat, 20 Jul 2019 22:43:04 +0200 Subject: finegrained operator category selection --- example/operators.cc | 9 +++++---- include/dwu/operators | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/example/operators.cc b/example/operators.cc index 9656e1c..c22e87a 100644 --- a/example/operators.cc +++ b/example/operators.cc @@ -16,7 +16,8 @@ static void dump(S const &s, T const &v) int main(int argc, char *argv[]) { // syntactic sugar operators for same container, same type - using namespace dwu::operators; + using namespace dwu::operators::arithmetic; + using namespace dwu::operators::shift; std::vector va = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; dump("va: ", va); @@ -45,7 +46,7 @@ int main(int argc, char *argv[]) { // syntactic sugar for mixed container, mixed type - using namespace dwu::operators_xcxt; + using namespace dwu::operators_xcxt::arithmetic; std::list la = {100, 101, 101, 103, 104, 105}; dump("la: ", la); @@ -55,7 +56,7 @@ int main(int argc, char *argv[]) { // syntactic sugar for mixed container, same type - using namespace dwu::operators_xc; + using namespace dwu::operators_xc::arithmetic; std::list lb = {200, 201, 201, 203, 204, 205}; dump("lb: ", lb); @@ -65,7 +66,7 @@ int main(int argc, char *argv[]) { // syntactic sugar for same container, mixed type - using namespace dwu::operators_xt; + using namespace dwu::operators_xt::arithmetic; std::vector ve = {300, 301, 301, 303, 304, 305}; dump("ve: ", ve); diff --git a/include/dwu/operators b/include/dwu/operators index 1decb51..5eee7a0 100644 --- a/include/dwu/operators +++ b/include/dwu/operators @@ -92,16 +92,22 @@ namespace dwu { } \ return l; \ } +namespace arithmetic { DWU_OPERATORS(+) DWU_OPERATORS(-) DWU_OPERATORS(*) DWU_OPERATORS(/) DWU_OPERATORS(%) +} +namespace bitwise { DWU_OPERATORS(^) DWU_OPERATORS(&) DWU_OPERATORS(|) +} +namespace shift { DWU_OPERATORS(>>) DWU_OPERATORS(<<) +} #undef DWU_OPERATORS } @@ -153,16 +159,22 @@ DWU_OPERATORS(<<) for(auto &x:l){ x O##= r; } \ return l; \ } +namespace arithmetic { DWU_OPERATORS_XT(+) DWU_OPERATORS_XT(-) DWU_OPERATORS_XT(*) DWU_OPERATORS_XT(/) DWU_OPERATORS_XT(%) +} +namespace bitwise { DWU_OPERATORS_XT(^) DWU_OPERATORS_XT(&) DWU_OPERATORS_XT(|) +} +namespace shift { DWU_OPERATORS_XT(>>) DWU_OPERATORS_XT(<<) +} #undef DWU_OPERATORS_XT } @@ -193,16 +205,22 @@ DWU_OPERATORS_XT(<<) } \ return l; \ } +namespace arithmetic { DWU_OPERATORS_XC(+) DWU_OPERATORS_XC(-) DWU_OPERATORS_XC(*) DWU_OPERATORS_XC(/) DWU_OPERATORS_XC(%) +} +namespace bitwise { DWU_OPERATORS_XC(^) DWU_OPERATORS_XC(&) DWU_OPERATORS_XC(|) +} +namespace shift { DWU_OPERATORS_XC(>>) DWU_OPERATORS_XC(<<) +} #undef DWU_OPERATORS_XC } @@ -235,16 +253,22 @@ DWU_OPERATORS_XC(<<) } \ return l; \ } +namespace arithmetic { DWU_OPERATORS_XCXT(+) DWU_OPERATORS_XCXT(-) DWU_OPERATORS_XCXT(*) DWU_OPERATORS_XCXT(/) DWU_OPERATORS_XCXT(%) +} +namespace bitwise { DWU_OPERATORS_XCXT(^) DWU_OPERATORS_XCXT(&) DWU_OPERATORS_XCXT(|) +} +namespace shift { DWU_OPERATORS_XCXT(>>) DWU_OPERATORS_XCXT(<<) +} #undef DWU_OPERATORS_XCXT } -- cgit v1.2.3 From 793e8c792d8118955de39c050fbc3fe3eb46c4c6 Mon Sep 17 00:00:00 2001 From: Wolfgang Draxinger Date: Mon, 22 Jul 2019 13:30:11 +0200 Subject: removed superfluous mixed type operators template allocator types --- include/dwu/operators | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/dwu/operators b/include/dwu/operators index 5eee7a0..b85a92a 100644 --- a/include/dwu/operators +++ b/include/dwu/operators @@ -117,7 +117,7 @@ DWU_OPERATORS(<<) template< \ template class C, \ typename Tl, typename Al, \ - typename Tr, typename Ar > \ + typename Tr > \ C operator O (C const &l, Tr const &r) { \ C v(l.size()); \ auto vi = v.begin(); auto li = l.begin(); \ @@ -128,7 +128,7 @@ DWU_OPERATORS(<<) } \ template< \ template class C, \ - typename Tl, typename Al, \ + typename Tl, \ typename Tr, typename Ar > \ C operator O (Tl const &l, C const &r) { \ C v(r.size()); \ @@ -154,7 +154,7 @@ DWU_OPERATORS(<<) template< \ template class C, \ typename Tl, typename Al, \ - typename Tr, typename Ar > \ + typename Tr > \ C& operator O##= (C &l, Tr const &r){ \ for(auto &x:l){ x O##= r; } \ return l; \ -- cgit v1.2.3