Re: Implicit type conversion depending on assignment

2023-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 3/23/23 07:36, Alexander Zhirov wrote: > @property auto toString(T)() The name is misleading because you want types other than string as well. > alias toString this; That should have been a compilation error because 'toString' does not have a known type (because it depends on a t

Re: Implicit type conversion depending on assignment

2023-03-23 Thread zjh via Digitalmars-d-learn
On Thursday, 23 March 2023 at 13:38:51 UTC, Alexander Zhirov wrote: Is it possible to convert such records inside the structure to the assigned type? ```d struct MyVal { string value; // Here it would be possible to use an alias to this, but it can only be used 1 time } auto a = MyVa

Re: Implicit type conversion depending on assignment

2023-03-23 Thread apz28 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:36:11 UTC, Alexander Zhirov wrote: On Thursday, 23 March 2023 at 14:19:31 UTC, user1234 wrote: omg, let's rewrite this... Or abuse opBinary struct MyVal { string value; T opBinary(string op, T)(T rhs) if (op == "+") {

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 3/23/23 06:38, Alexander Zhirov wrote: > Is it possible to convert such records inside the structure to the > assigned type? D does not embrace implicit conversions. There is some support like 'alias this' as you mentioned but what you are looking for is not possible. Ali

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:36:11 UTC, Alexander Zhirov wrote: I wanted WITHOUT explicit casting. I also have thoughts about using [templates](https://dlang.org/spec/template.html#this_rtti), but I don't have enough experience yet how to implement it.

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:19:31 UTC, user1234 wrote: omg, let's rewrite this... I meant something like that. But you can't do that. I wanted WITHOUT explicit casting. ```d struct MyVal { private string value; @property auto toString(T)() { return value.to!T; }

Re: Implicit type conversion depending on assignment

2023-03-23 Thread user1234 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:17:25 UTC, user1234 wrote: not exactly thing goal yet. The doc example you have put a link for is different, the struct with alias this a redefinition of the "alias this"'ed thing, that just cant work in what you ask in the first post. omg, let's rewrite this.

Re: Implicit type conversion depending on assignment

2023-03-23 Thread user1234 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 14:05:07 UTC, Alexander Zhirov wrote: On Thursday, 23 March 2023 at 13:38:51 UTC, Alexander Zhirov wrote: Is it possible to convert such records inside the structure to the assigned type? ```d struct MyVal { string value; // Here it would be possible to us

Re: Implicit type conversion depending on assignment

2023-03-23 Thread Alexander Zhirov via Digitalmars-d-learn
On Thursday, 23 March 2023 at 13:38:51 UTC, Alexander Zhirov wrote: Is it possible to convert such records inside the structure to the assigned type? ```d struct MyVal { string value; // Here it would be possible to use an alias to this, but it can only be used 1 time } auto a = MyVa

Implicit type conversion depending on assignment

2023-03-23 Thread Alexander Zhirov via Digitalmars-d-learn
Is it possible to convert such records inside the structure to the assigned type? ```d struct MyVal { string value; // Here it would be possible to use an alias to this, but it can only be used 1 time } auto a = MyVal("100"); auto b = MyVal("11.2"); int MyInt = a;// Implicitl

Re: Any working REPL program on windows? DREPL doesn't compile

2023-03-23 Thread jmh530 via Digitalmars-d-learn
On Thursday, 23 March 2023 at 11:46:48 UTC, matheus wrote: On Thursday, 23 March 2023 at 09:39:40 UTC, John Xu wrote: Anybody know any working REPL program? I failed to find a working one. https://github.com/dlang-community/drepl can't compile on my Windows 10, dub reports: ... According to

Re: Any working REPL program on windows? DREPL doesn't compile

2023-03-23 Thread matheus via Digitalmars-d-learn
On Thursday, 23 March 2023 at 09:39:40 UTC, John Xu wrote: Anybody know any working REPL program? I failed to find a working one. https://github.com/dlang-community/drepl can't compile on my Windows 10, dub reports: ... According to their Readme: Supported OS Works on any OS with full sha

Any working REPL program on windows? DREPL doesn't compile

2023-03-23 Thread John Xu via Digitalmars-d-learn
Anybody know any working REPL program? I failed to find a working one. https://github.com/dlang-community/drepl can't compile on my Windows 10, dub reports: src\drepl\engines\dmd.d(258,16): Error: undefined identifier `dlsym`