Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 20:55:32 UTC, wjoe wrote: In my particular case the compiler can rule out ```opIndex``` so why does it abort instead of trying ```opIndexUnary``` ? Or was it trying and it didn't work ? If that's the case I'd like to know the reason why it discarded ```opIndexUnar

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 20:55:32 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 16:13:35 UTC, Tejas wrote: [...] Congratulations:) Unfortunately I haven't got anything I could return by ref so I can't take advantage of a low hanging fruit. In my book overloading operators is no fun - at

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread someone via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 23:44:18 UTC, jfondren wrote: On Wednesday, 14 July 2021 at 22:59:38 UTC, someone wrote: [...] so, these lines: ```d stringUGC32 lugcSequence3 = stringUGC32(cast(char) 'x'); stringUGC32 lugcSequence4 = stringUGC32(1); ``` which call stringUGC32, an alias

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Thursday, 15 July 2021 at 01:08:28 UTC, Alain De Vos wrote: As an example i show this. https://docs.python.org/3/library/json.html But that is more what i look for. That's JSON, not JSONB. D has JSON support in https://dlang.org/phobos/std_json.html

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread Alain De Vos via Digitalmars-d-learn
As an example i show this. https://docs.python.org/3/library/json.html But that is more what i look for.

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 21:56:11 UTC, Alain De Vos wrote: With good select operators i can extract the data i need for instance: select measurement->'room.temperature' from mytable; Now how to process that further as json object ? or jsonb object in dlang ? You'll need to either lean

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 22:59:38 UTC, someone wrote: Please, go to the bottom of the unittest block and uncomment one of those lines (DMD version here is DMD64 D Compiler v2.096.1): so, these lines: ```d stringUGC32 lugcSequence3 = stringUGC32(cast(char) 'x'); stringUGC32 lugc

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread someone via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 19:00:08 UTC, jfondren wrote: On Wednesday, 14 July 2021 at 18:04:44 UTC, someone wrote: On Wednesday, 14 July 2021 at 06:28:37 UTC, jfondren wrote: alternate 1: - pull tests out into a named enum template, like std.traits - always static assert enum, rather than

Re: Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread Alain De Vos via Digitalmars-d-learn
With good select operators i can extract the data i need for instance: select measurement->'room.temperature' from mytable; Now how to process that further as json object ? or jsonb object in dlang ?

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 16:13:35 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 15:08:56 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/d

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 11:27 AM, Tejas wrote: > the compiler error should have been a dead giveaway > that opIndex was returning a _constant_ value I know you mean "rvalue" but if I may be unnecessarily pedantic, an rvalue can indeed be mutated: struct A { int i; void mutate() { i = 42; impor

Re: Reference Counted Class

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:33:56 UTC, Tejas wrote: For deterministic object destruction, there's the ```scope``` storage class: ```d scope class_instance = new class(); scope(exit) class_instance.destroy ``` One or the other. The `scope(exit)` will still fire on scope exit in the case

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread jfondren via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:04:44 UTC, someone wrote: On Wednesday, 14 July 2021 at 06:28:37 UTC, jfondren wrote: alternate 1: - pull tests out into a named enum template, like std.traits - always static assert enum, rather than conditionally asserting false - always have the rest of the

Re: Reference Counted Class

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 18:04:59 UTC, IGotD- wrote: On Wednesday, 14 July 2021 at 17:52:16 UTC, sclytrack wrote: Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right?

Re: Reference Counted Class

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:52:16 UTC, sclytrack wrote: Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right? This isn't happening until DIP 1000 passes successfully(w

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:42:03 UTC, Ali Çehreli wrote: On 7/14/21 9:13 AM, Tejas wrote: > ref/*notice this ref*/ int opIndex(int index)return/*NOTICE THE > RETURN*/ { Indeed... I cover that 'ref' here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.r

Re: Reference Counted Class

2021-07-14 Thread IGotD- via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 17:52:16 UTC, sclytrack wrote: Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right? Combination both the rc and the stop-the-world gc, for the

Re: static assert not printing out along the error diagnostic

2021-07-14 Thread someone via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 06:28:37 UTC, jfondren wrote: alternate 1: - pull tests out into a named enum template, like std.traits - always static assert enum, rather than conditionally asserting false - always have the rest of the code ```d enum isString(T) = is(T == string) || is(T == ws

Reference Counted Class

2021-07-14 Thread sclytrack via Digitalmars-d-learn
Would reference counted classes by default be too much of a change? Is it a bad idea? Currently there a changes in the language where you can avoid the reference count, right? Combination both the rc and the stop-the-world gc, for the cycles.

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 9:13 AM, Tejas wrote: > ref/*notice this ref*/ int opIndex(int index)return/*NOTICE THE > RETURN*/ { Indeed... I cover that 'ref' here: http://ddili.org/ders/d.en/operator_overloading.html#ix_operator_overloading.return%20type,%20operator Two quotes from that section: 1) "it

Re: Error with implicit cast of ^^=

2021-07-14 Thread Ali Çehreli via Digitalmars-d-learn
On 7/14/21 2:44 AM, wjoe wrote: >> x = (x ^^ y).to!(typeof(x)); >> } >> >> For example, run-time error if y == 7. > I was planning on adding support for over-/underflow bits but this is > much better. Thanks! If so, then there is also std.experimental.checkedint: https://dlang.org/phobos/s

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:08:56 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/dec return the modified value, post-inc/dec return the ori

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:23:05 UTC, vit wrote: On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote: ```d import std.stdio; struct abc{ int[100] a; struct Proxy{ abc* ptr; const int index; int opUnary(string op : "++")(){ return ++pt

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:23:05 UTC, vit wrote: On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote: ```d import std.stdio; struct abc{ int[100] a; struct Proxy{ abc* ptr; const int index; int opUnary(string op : "++")(){ return ++pt

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread vit via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:19:03 UTC, vit wrote: ```d import std.stdio; struct abc{ int[100] a; struct Proxy{ abc* ptr; const int index; int opUnary(string op : "++")(){ return ++ptr.a[index]; //add missing ++ } } Pr

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html Post

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread vit via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 15:01:45 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: [...] This work: ```d import std.stdio; struct abc{ int[100] a; ref int opIndex(int index)return{ retur

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:50:01 UTC, Mike Parker wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: [...] It's how the contract of post-inc/dec work---pre-inc/dec return the modified value, post-inc/dec return the original value. [...] That makes a lot of sense now, tha

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 14:39:03 UTC, vit wrote: On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html Post

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Mike Parker via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw that, and I suppose it would work just fine if it were re

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: I think it's a bug, because the following works: ```d import std.stdio; struct abc{ int[100] a; int opIndex(int index){ return a[index]; } int opIndexUnary(string s)(int index) if(s == "++"){ re

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread vit via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 13:16:49 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: [...] From doc: https://dlang.org/spec/operatoroverloading.html Postincrement e++ and Postdecrement e-- Operators These are

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 13:09:56 UTC, vit wrote: On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread vit via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:49:58 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: On Wednesday, 14 July 2021 at 10:07:38 UTC, wjoe wrote: I'm want to do something like this ```D part_int_t!(1,2,3) i; auto x = -i[0]; --i[1]; // 1 i[1]++; // 2 ``` I think the operator I need to overload would be opIndexUnary which I di

Manipulate and parse jasonb object in timescaledb(postgresql)

2021-07-14 Thread Alain De Vos via Digitalmars-d-learn
When I read a record out of the database I receive a jsonb datatatype as a string. How do I convert this string into a json object and parse and manipulate it?

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 12:35:07 UTC, wjoe wrote: On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw that, and I suppose it would work just fine if it were re

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 11:31:36 UTC, Tejas wrote: ``` {auto a = i[1] , ++i[1] , a} //note the , not the ;``` Sorry I can't provide something even more concrete. Yes I saw that, and I suppose it would work just fine if it were rewritten to just ```++i[1]```. What I'm struggling to und

Re: opIndexUnary post in-/decrement how to ?

2021-07-14 Thread Tejas via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 10:07:38 UTC, wjoe wrote: I'm want to do something like this ```D part_int_t!(1,2,3) i; auto x = -i[0]; --i[1]; // 1 i[1]++; // 2 ``` I think the operator I need to overload would be opIndexUnary which I did. (1) compiles. (2) doesn't - the compiler complains tha

Re: catching segfault using try_ catch

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Wednesday, 14 July 2021 at 00:10:59 UTC, seany wrote: On Tuesday, 13 July 2021 at 17:49:54 UTC, Adam D Ruppe wrote: On Tuesday, 13 July 2021 at 16:52:43 UTC, seany wrote: [...] true if it succeeded. [...] You mean transparently rerun some code? That's better done with the lowlevel sig

opIndexUnary post in-/decrement how to ?

2021-07-14 Thread wjoe via Digitalmars-d-learn
I'm want to do something like this ```D part_int_t!(1,2,3) i; auto x = -i[0]; --i[1]; // 1 i[1]++; // 2 ``` I think the operator I need to overload would be opIndexUnary which I did. (1) compiles. (2) doesn't - the compiler complains that i.opIndex isn't an lvalue and can't be modified. The l

Re: Error with implicit cast of ^^=

2021-07-14 Thread wjoe via Digitalmars-d-learn
On Tuesday, 13 July 2021 at 15:14:26 UTC, Ali Çehreli wrote: On 7/13/21 4:12 AM, wjoe wrote: > ```D > byte x = some_val; > long y = some_val; > > x ^^= y; // Error: cannot implicitly convert expression > pow(cast(long)cast(int)x, y) of type long to byte [...] > I rewrote it to something like >