Re: Super easy struct construction question that I'm embarrassed to ask.

2025-01-12 Thread Jim Balter via Digitalmars-d-learn
On Thursday, 9 January 2025 at 22:08:31 UTC, Dennis wrote: On Thursday, 9 January 2025 at 22:01:59 UTC, WhatMeWorry wrote: this(Location locaction, uint f) { this.location = location; this.f = f; } You misspelled the parameter name 'locaction', so your assignment in t

Re: Simplify some C-style code

2024-12-25 Thread Jim Balter via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 18:25:57 UTC, sfp wrote: kind of weird that it doesn't work inside `enum`. Seems like an obvious application... It's not weird at all when you understand that it's an AST that is being mixed in, not just a string as if it were an C preprocessor macro. The in

Re: Simplify some C-style code

2024-12-25 Thread Jim Balter via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 21:34:00 UTC, monkyyy wrote: On Wednesday, 25 December 2024 at 21:23:00 UTC, Jim Balter wrote: I suggest reading the spec rather than just trying random things. I suggest trying random things instead of reading the spec. The spec is full of lies and slander,

Re: Simplify some C-style code

2024-12-25 Thread Jim Balter via Digitalmars-d-learn
On Wednesday, 25 December 2024 at 16:41:05 UTC, sfp wrote: On Wednesday, 25 December 2024 at 07:57:04 UTC, monkyyy wrote: static foreach, traits and mixin I was looking into this but I think I need some help getting off the ground... This doesn't compile: ``` enum Test { mixin("A, B, C") }

Re: How to iterate string enum values?

2024-12-23 Thread Jim Balter via Digitalmars-d-learn
On Monday, 23 December 2024 at 20:32:58 UTC, Anton Pastukhov wrote: On Monday, 23 December 2024 at 20:26:47 UTC, bauss wrote: Simply cast el to a string instead of using std.conv.to Thanks much, it worked! Though I'm confused why. Could you please elaborate? I had the exact same issue yest

Re: User defined type and foreach

2024-01-25 Thread Jim Balter via Digitalmars-d-learn
On Friday, 19 January 2024 at 18:13:55 UTC, Jonathan M Davis wrote: On Friday, January 19, 2024 3:49:29 AM MST Jim Balter via Digitalmars-d-learn wrote: On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis wrote: > When you have > > foreach(e; range) > > it gets lower

Re: Error "Outer Function Context is Needed" when class declared in unittest

2024-01-21 Thread Jim Balter via Digitalmars-d-learn
On Thursday, 5 January 2023 at 13:47:24 UTC, Adam D Ruppe wrote: On Thursday, 5 January 2023 at 13:27:23 UTC, Vijay Nayar wrote: Why is this error only found when declaring a class in the unittest? A unittest is just a special function, it can run code and have local variables. classes and

Re: User defined type and foreach

2024-01-19 Thread Jim Balter via Digitalmars-d-learn
On Friday, 17 November 2017 at 17:55:30 UTC, Jonathan M Davis wrote: When you have foreach(e; range) it gets lowered to something like for(auto r = range; !r.empty; r.popFront()) { auto e = r.front; } So, the range is copied when you use it in a foreach. Indeed, and the language spec

Re: What's the proper way to add a local file dependence to dub?

2024-01-06 Thread Jim Balter via Digitalmars-d-learn
On Monday, 12 March 2018 at 10:20:20 UTC, Seb wrote: On Sunday, 4 March 2018 at 16:46:56 UTC, Marc wrote: then copy it to sources folder? let's say I have a small library folder at C:\mylibrary\D where I want to use dir.d from it. How do I add that file dependence to dub? But I do not want to

Re: Are properties mature enough?

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Monday, 20 August 2018 at 00:49:02 UTC, Jonathan M Davis wrote: On Sunday, August 19, 2018 12:32:17 PM MDT QueenSvetlana via Digitalmars-d- learn wrote: In the D Style Guide, it says: Properties https://dlang.org/dstyle.html#properties Functions should be property functions whenever appropr

Re: ushort + ushort = int?

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Monday, 20 August 2018 at 08:34:56 UTC, Andrey wrote: Hello, Here is a code that you can execute using online compiler https://run.dlang.io/: import std.stdio; void main() { ushort first = 5; ushort second = 1000; ushort result = first + second; writeln(result); } I hae thi

Re: Auto keyword and when to use it

2018-08-21 Thread Jim Balter via Digitalmars-d-learn
On Tuesday, 21 August 2018 at 18:18:25 UTC, QueenSvetlana wrote: On Tuesday, 21 August 2018 at 16:15:32 UTC, XavierAP wrote: Only if someone likes "Type x = new Type()" instead of "auto x = new Type()" I would say they're clearly wrong. As you stated it's up to the programmer to decided. I'm

Re: Disabling struct destructor illegal?

2018-07-20 Thread Jim Balter via Digitalmars-d-learn
On Thursday, 19 July 2018 at 10:04:34 UTC, RazvanN wrote: On Thursday, 19 July 2018 at 09:50:32 UTC, Jim Balter wrote: On Thursday, 19 July 2018 at 08:50:15 UTC, RazvanN wrote: struct A { int a; @disable ~this() {} } void main() { A a = A(2); } Currently, this code yields: Error:

Re: Disabling struct destructor illegal?

2018-07-19 Thread Jim Balter via Digitalmars-d-learn
On Thursday, 19 July 2018 at 08:50:15 UTC, RazvanN wrote: struct A { int a; @disable ~this() {} } void main() { A a = A(2); } Currently, this code yields: Error: destructor `A.~this` cannot be used because it is annotated with @disable I was expecting that disabling the destruct