OT: Leaving Rust gamedev after 3 years
bachmeier
no at spam.net
Mon Apr 29 19:10:35 UTC 2024
On Monday, 29 April 2024 at 17:52:55 UTC, jmh530 wrote:
> If this is so annoying...
>
> ```d
> double x = 0;
> ```
>
> why not
>
> ```d
> struct MyDouble
> {
> double x = 0;
> alias this = x;
> }
> ```
This made me realize you *can* force the compiler to throw an
error rather than initializing variables:
```
import std;
void main() {
MyDouble z = 1.0;
writeln(z);
}
struct MyDouble {
double x;
alias this = x;
@disable this();
this(double _x) {
x = _x;
}
}
```
The same can be done to prevent ugly bugs like we discussed in an
earlier thread:
```
struct Foo {
struct Bar {
double x;
}
Bar bar;
@disable this();
alias this = bar;
}
// Neither line will compile now
void main() {
Foo foo;
auto foo = new Foo;
}
More information about the Digitalmars-d
mailing list