Re: opEquals() non-standard return type

2019-01-24 Thread Jacob Shtokolov via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 17:28:37 UTC, H. S. Teoh wrote: The best way to do this is to use a string DSL or a delegate as template argument. For example: auto result = User.filter!q{ User.name == "John" }; or: auto result = User.filter!(u => u.name == "John"); I

Re: opEquals() non-standard return type

2019-01-24 Thread Jacob Shtokolov via Digitalmars-d-learn
On Thursday, 24 January 2019 at 00:47:37 UTC, Ali Çehreli wrote: Yeah, that can't work. Remove the bool-returning one and your code works with the 'alias this' above. Wow, this is an amazing workaround! I didn't think about it in that way. It perfectly solves the issue. Thank you!

Re: opEquals() non-standard return type

2019-01-23 Thread Neia Neutuladh via Digitalmars-d-learn
On Wed, 23 Jan 2019 15:19:06 +, Jacob Shtokolov wrote: > I'm wondering, is that possible to declare multiple versions of > opEquals() and evaluate them in the different places depending on return > type? I looked at this a while ago for similar reasons. It didn't pan out. When you override

Re: opEquals() non-standard return type

2019-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/23/2019 07:19 AM, Jacob Shtokolov wrote: > Expressions like `User.id == 10`, `User.age > 18`, etc. should return a > struct instead of a bool (let's call it `struct BinaryExpression`). Have you considered 'alias this'? struct BinaryExpr(T) { T left; T right; Op op; bool value()

Re: opEquals() non-standard return type

2019-01-23 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Jan 23, 2019 at 03:19:06PM +, Jacob Shtokolov via Digitalmars-d-learn wrote: > Hi, > > I'm trying to check whether it's possible to implement Python's > SQLAlchemy-like query syntax in D, but I get stuck a bit. > > Here is a simple example of what I want to achieve: > > ``` > auto

Re: opEquals() non-standard return type

2019-01-23 Thread Jacob Shtokolov via Digitalmars-d-learn
On Wednesday, 23 January 2019 at 15:28:02 UTC, Jonathan M Davis wrote: But regardless of the specifics of operator overloading in D, D does not support overloading _any_ functions on the return type. Thanks!

Re: opEquals() non-standard return type

2019-01-23 Thread Jonathan M Davis via Digitalmars-d-learn
On Wednesday, January 23, 2019 8:19:06 AM MST Jacob Shtokolov via Digitalmars-d-learn wrote: > Hi, > > I'm trying to check whether it's possible to implement Python's > SQLAlchemy-like query syntax in D, but I get stuck a bit. > > Here is a simple example of what I want to achieve: > > ``` > auto

opEquals() non-standard return type

2019-01-23 Thread Jacob Shtokolov via Digitalmars-d-learn
Hi, I'm trying to check whether it's possible to implement Python's SQLAlchemy-like query syntax in D, but I get stuck a bit. Here is a simple example of what I want to achieve: ``` auto result = User.filter(User.id == 10); result = User.filter(User.name == "John"); result =