https://issues.dlang.org/show_bug.cgi?id=14593
Igor Stepanov <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #2 from Igor Stepanov <[email protected]> --- (In reply to Martin Nowak from comment #0) > A motivating example is using expression templates to specify db queries. > > db.get!Person.where!(p => p.age > 21 && p.name == "Peter") > > This has the following problems: > - opCmp doesn't allow to capture the op > - it's not possible to overload && > - opEquals must return a bool (but here it needs to return p) > > A solution would be to use the generic opBinary for < <= > >= == iff > opCmp/opEquals don't exist and also extending it to && ||. (In reply to Walter Bright from comment #1) > Using expression templates to implement DSL's makes code really hard to > understand and debug. There are better ways. +1 You may pass where condition as string, and use libdparse, or something like it to build AST and compile it to your SQL expression. db.get!Person.where!(`p.age > 21 && p.name == "Peter"`) This looks not worse, and at the same time, more honest. BTW, if we will implement .astof property, which returns AST of expression/symbol (without possibility to generate new symbol from existing AST it will not be macros), we will able to use compiler to generate AST of this expression: template AstOf(string expr) { enum AstOf = mixin(expr).astof; } --
