4 ms·
I use preprocessor macros for what I guess I'll call "hyper-local extraction" in an attempt to be as DRY as possible. I don't know how modern C++ would handle t
by ursus_bonum 11y ago
I use preprocessor macros for what I guess I'll call "hyper-local extraction" in an attempt to be as DRY as possible. I don't know how modern C++ would handle this better. It looks a bit like this:
#define a_ frob(-1,0,0); grob("a"); blah(...);
#define b_ frob(1,0,0); grob("b"); blah(...);
#define c_ frob(0,-1,0); grob("c"); blah(...);
#define d_ frob(0,-1,1); grob("d"); blah(...);
#define e_ frob(0,0,-1); grob("e"); blah(...);
#define f_ frob(0,1,1); grob("f"); blah(...);
if (normal_order) {
a_ b_ c_ d_ e_ f_;
c_ b_ a_ f_ e_ d_;
} else if (special_order_1) {
b_ c_ d_ e_ a_;
d_ e_ c_ b_ a_ f_;
} else if (...) {
// ... and so on ...
}
#undef a_
#undef b_
#undef c_
#undef d_
#undef e_
#undef f_
- lmitchell 11y agoModern C++ could use lambdas: auto a = [] {frob(-1,0,0); grob("a"); blah(...);}; auto b = [] {frob(1,0,0); grob("b"); blah(...);}; auto c = [] {frob(0,-1,0); grob("c"); blah(...);}; ... if (normal_order) { a(); b(); c(); ... } else if (...) { b(); c(); a(); ... } ...
- ursus_bonum 11y agoI guess that's pretty good.