Allow default constructors for structs
Salih Dincer
salihdb at hotmail.com
Sun Sep 1 22:34:20 UTC 2024
On Thursday, 29 August 2024 at 14:28:09 UTC, Ogi wrote:
> A struct with a default constructor can only be instantiated by
> an implicit constructor call, following the same rules as a
> struct with a disabled default constructor.
I think everything is consistent and works as it should. D gives
more than C...
```d
struct S(T)
{
T i;
this(T value)
{
i = value;
}
alias i this;
}
alias sint = S!int;
void main()
{
sint s1;
auto s2 = sint(1);
auto sarr= [sint(2)]; // i = 2
sarr ~= s2; // i = 1
sarr ~= s1; // i = 0
assert(sarr == [2, 1, 0]);
}
```
SDB at 79
More information about the dip.ideas
mailing list