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