On Thursday, 1 August 2024 at 14:42:36 UTC, Ruby The Roobster
wrote:
Thank you. I am not very well acquainted with the standard
library, and this cleans up things significantly.
Question: Is there a good guide to Phobos anywhere? I would
like to learn the more commonly used algorithms / con
On Thursday, 1 August 2024 at 14:20:29 UTC, user1234 wrote:
That was a general criticism of implicit construction.
We are only talking about it in the context of returning from a
function.
The classic example is
```d
struct S {int i;}
function f(S s);
function f(int i);
unittest { f(0); }
Thanks everyone for the replies! I just thought it was weird that
implicit construction is seemingly supported when directly
initialising a struct but not in any other case. I guess it's
because it's clearly less ambiguous.
On Thursday, 1 August 2024 at 13:07:09 UTC, Lance Bachmeier wrote:
F
On Thursday, 1 August 2024 at 08:46:00 UTC, IchorDev wrote:
P.S. You might want to put `value = void`, otherwise it’ll
always be default-constructed.
Doing `= void` can violate the assumptions of a destructor of T.
Nullable uses a union to store T, so it can decide when to call
the destructor
On Thursday, 1 August 2024 at 07:03:04 UTC, IchorDev wrote:
Hey just a heads up, you might wanna use
[`readText`](https://dlang.org/library/std/file/read_text.html)
and
[`lineSplitter`](https://dlang.org/library/std/string/line_splitter.html) just so you don’t have to deal with file handles.
.
On Thursday, 1 August 2024 at 10:59:03 UTC, IchorDev wrote:
On Thursday, 1 August 2024 at 09:55:08 UTC, user1234 wrote:
The problem would be that sorting the candidates of an
overload set would be more complicated. Also in certain cases
it would be less obvious to get which one is selected.
P
On Thursday, 1 August 2024 at 07:25:53 UTC, Emma wrote:
but this doesn't:
```d
Option!int something() {
return None(); // Error: cannot implicitly convert expression
`None()` of type `None` to `Option!int`
}
```
For the program you've written, I'm happy it doesn't compile,
because a lot
On Thursday, 1 August 2024 at 09:55:08 UTC, user1234 wrote:
The problem would be that sorting the candidates of an overload
set would be more complicated. Also in certain cases it would
be less obvious to get which one is selected.
Please elaborate about how this would interact with function
On Thursday, 1 August 2024 at 08:46:00 UTC, IchorDev wrote:
[...]
I’m pretty sure this is intentional to prevent ambiguity, but I
can’t quite remember what the point of that is.
The problem would be that sorting the candidates of an overload
set would be more complicated. Also in certain case
Emma kirjoitti 1.8.2024 klo 10.25:
This kind of prevents ergonomic code like the above. Instead you have to
use a function like `Option!T None(T)() => Option!T()` and then you have
to repeat yourself with `return None!int` and etc... it's quite annoying :(
While this isn't exactly less verbos
On Thursday, 1 August 2024 at 07:25:53 UTC, Emma wrote:
This code works:
```d
struct None {}
struct Option(T) {
bool hasSome;
T value;
this(None) {}
this(T v) {
hasSome = true;
value = v;
}
}
Option!int a = 123;// automatically constructs an
Option!in
No, D does not support implicit construction.
However in saying that, I will continue to argue in support of sum types
when they get added to the language to support implicit construction!
This code works:
```d
struct None {}
struct Option(T) {
bool hasSome;
T value;
this(None) {}
this(T v) {
hasSome = true;
value = v;
}
}
Option!int a = 123;// automatically constructs an Option!int
from a bare int
Option!int b = None(); // same as abov
Hey just a heads up, you might wanna use
[`readText`](https://dlang.org/library/std/file/read_text.html)
and
[`lineSplitter`](https://dlang.org/library/std/string/line_splitter.html) just so you don’t have to deal with file handles. Also you can use something like [`formattedRead`](https://dlang
14 matches
Mail list logo