Re: Templates considered impressive

2024-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 01, 2024 at 04:30:27PM +, Salih Dincer via Digitalmars-d-learn wrote: [...] > > ``` > Please add this to your MyCon structure: > ```d > alias value this; > // assert(num1 == 3.14); > ``` > And test it like this too, I think it's awesome! [...] IMO it's not a good idea to recommend

Re: Templates considered impressive

2024-10-01 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 1 October 2024 at 16:18:17 UTC, Salih Dincer wrote: ```d // ... struct MyCon { string input; T value; this(string data) { // ... } // ... } } ``` Please add this to your MyCon structure: ```d alias value this; // assert(num1 == 3

Re: Templates considered impressive

2024-10-01 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 1 October 2024 at 01:00:08 UTC, Andy Valencia wrote: ... A conversion like: auto d = atoi!double("123.456"); is about 4k of code. Nice! Congratulations on your initiative. D is very flexible with templates, especially with the mixin templates. For example, you might like t

Re: Templates considered impressive

2024-10-01 Thread Andy Valencia via Digitalmars-d-learn
On Tuesday, 1 October 2024 at 11:45:35 UTC, monkyyy wrote: On Tuesday, 1 October 2024 at 05:44:16 UTC, H. S. Teoh wrote: why spend the time and effort when you could have just done: ``` import std.conv; theres a bunch of relivent tradeoffs and phoboes doesnt make a good set of them To be f

Re: Templates considered impressive

2024-10-01 Thread monkyyy via Digitalmars-d-learn
On Tuesday, 1 October 2024 at 05:44:16 UTC, H. S. Teoh wrote: why spend the time and effort when you could have just done: ``` import std.conv; theres a bunch of relivent tradeoffs and phoboes doesnt make a good set of them

Re: Templates considered impressive

2024-10-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Oct 01, 2024 at 01:00:08AM +, Andy Valencia via Digitalmars-d-learn wrote: > I had an old atoi() I wrote when I was getting started with D. You know, > fixed type, string in, int output. Today for fun I templated the type: > > T atoi(T)(string s) [...] It's all good and fun to try