Re: Make IN Dlang

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Nov 02, 2022 at 09:16:22PM +0100, Christian Köstlin via Digitalmars-d-learn wrote: > On 02.11.22 20:16, H. S. Teoh wrote: [...] > > IMO, the ideal situation is a hybrid situation: the underlying build > > mechanism should be purely declarative, because otherwise the > > complexity just

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/3/22 1:46 PM, Tejas wrote: Check my post, `A& a;` refuses to compile in C++20 atleast, asking to be explicitly initialized, thus averting the problem altogether That's different, `A&` cannot be rebound in C++, whereas a class reference can. Try `A* a;` and see if it compiles -Steve

Re: Hipreme's #3 Tip of the day - Changing DMD linker on Windows

2022-11-03 Thread Imperatorn via Digitalmars-d-learn
On Tuesday, 1 November 2022 at 16:17:08 UTC, Hipreme wrote: The linker used on Windows when installing DMD is pretty much decided on how your PC was setup. [...] Do you have a blog?

Re: Unit testing a function returning void

2022-11-03 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:26:04 UTC, Imperatorn wrote: On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Tejas via Digitalmars-d-learn
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote: On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: [...] ```D @safe: import std.stdio; class A { void foo() { writeln("foo"); } } void main() { auto a1 = new A; a1.foo(); // prints

Re: Unit testing a function returning void

2022-11-03 Thread Sergey via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I would like to unit test the print function (yes, I know, not very useful on the above example since print is merely a duplicate of writeln...). Is there a way to use assert to test the output of the print

Re: Unit testing a function returning void

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 03, 2022 at 08:51:52AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 11/3/22 03:00, Bruno Pagis wrote: > > >void print() { > > writeln("array = ", this.array); > >} > > Similar to Paul Backus's program but I would try to avoid the file system > for unit tests

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 08:40, H. S. Teoh wrote: > D does not have the equivalent of C++'s allocating a class instance on > the stack. Not by default but we have two different ways, either may be discouraged: import std.typecons : scoped; import std.stdio; class C { int i; } void main() { //

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Adam D Ruppe via Digitalmars-d-learn
On Thursday, 3 November 2022 at 15:40:02 UTC, H. S. Teoh wrote: D does not have the equivalent of C++'s allocating a class instance on the stack. In D, all class instances are allocated on the heap and class variables are references to them. well there is scope Object o = new Object; which

Re: Unit testing a function returning void

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 03:00, Bruno Pagis wrote: >void print() { > writeln("array = ", this.array); >} Similar to Paul Backus's program but I would try to avoid the file system for unit tests when possible. In this case, you can print into a sink, which can be useful in other ways as well:

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 03, 2022 at 04:41:14AM +, Siarhei Siamashka via Digitalmars-d-learn wrote: [...] > ```D > @safe: > import std.stdio; > class A { > void foo() { writeln("foo"); } > } > void main() { > auto a1 = new A; > a1.foo(); // prints "foo" > A a2; > a2.foo(); // Segmentation fault

Re: save() feature for iota

2022-11-03 Thread Ali Çehreli via Digitalmars-d-learn
On 11/3/22 04:58, Paul Backus wrote: > https://issues.dlang.org/show_bug.cgi?id=23453 Even though iterating over UTF value ranges don't make sense in general, they would work for some values including the ASCII range. Ali

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Tejas via Digitalmars-d-learn
On Thursday, 3 November 2022 at 04:41:14 UTC, Siarhei Siamashka wrote: C++ code: ```C++ #include class A { public: void foo() { std::cout << "foo" << std::endl; } }; int main() { auto a1 = new A; a1->foo(); // prints "foo" A a2; a2.foo(); // prints "foo" delete a1; } ``` D code:

Re: save() feature for iota

2022-11-03 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 3 November 2022 at 06:26:22 UTC, Salih Dincer wrote: Hi All, Isn't there a save feature for `iota()`? Looking at the source, it seems that only the numeric overloads of `iota` implement `save`. I think this is probably just an oversight, though, since I can't see any reason why

Re: Unit testing a function returning void

2022-11-03 Thread Paul Backus via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit test the print function (yes, I know, not very useful on the

Re: Unit testing a function returning void

2022-11-03 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 3 November 2022 at 10:00:27 UTC, Bruno Pagis wrote: Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit test the print function (yes, I know, not very useful on the

Re: Unit testing a function returning void

2022-11-03 Thread rikki cattermole via Digitalmars-d-learn
You could redirect stdout to a file of your choosing and test against that. Although ideally you would instead take as an argument to print some sort of output range or Appender. Then you could test against that instead.

Unit testing a function returning void

2022-11-03 Thread Bruno Pagis via Digitalmars-d-learn
Good morning, I have the following class: ``` class A { int[] array; ... void print() { writeln("array = ", this.array); } } ``` I would like to unit test the print function (yes, I know, not very useful on the above example since print is merely a duplicate of writeln...). Is

Re: How to pass noncopyable variadic arguments with ref?

2022-11-03 Thread tchaloupka via Digitalmars-d-learn
On Friday, 21 October 2022 at 12:05:28 UTC, ryuukk_ wrote: On Thursday, 20 October 2022 at 14:03:10 UTC, tchaloupka wrote: void test(Foo..)(Foo foos) I don't know if that's the 1:1 alternative, but that doesn't compile onlineapp.d(23): Error: struct `onlineapp.Foo` is not copyable

save() feature for iota

2022-11-03 Thread Salih Dincer via Digitalmars-d-learn
Hi All, Isn't there a save feature for `iota()`? ```d import std.stdio; import std.range; void main() { foreach(num; iota!char('a', 'f').chunks(3)/* "onetwosixfour".chunks(3)//*/ ) { //auto n = num.save(); num.writeln(": ", num.walkLength); }

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 November 2022 at 06:02:13 UTC, Mike Parker wrote: are in C++. D enforces the distinction that C++ ...that C++ programmers often follow by convention.

Re: What's the correct way of creating an instance of class in D?

2022-11-03 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 3 November 2022 at 05:41:06 UTC, Siarhei Siamashka wrote: Thanks for the link and also thanks for confirming that you have no clue what's going on. I think that what actually That's not necessary. He does know what's going on and pointed you to the correct place. The second