OT: Leaving Rust gamedev after 3 years
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Mon Apr 29 20:47:12 UTC 2024
On Monday, April 29, 2024 1:10:35 PM MDT bachmeier via Digitalmars-d wrote:
> 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;
> }
If you really want to control what's going on, you could make a floating
point equivalent to std.checkedint's Checked.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list