How pretty-print a struct?

2022-03-30 Thread ZZ via Digitalmars-d-learn
Hi, Is there an easy way to pretty-print a struct which also includes arrays? pretty_array does a very good job for arrays. ZZ

Re: How to create delegates with an independent scope?

2022-03-30 Thread Tejas via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote: Consider the following code example: ```d import std.stdio; void main() { alias DelegateT = string delegate(); // An array of delegates, each has their own scope. DelegateT[] funcs; foreach (i; ["ham", "cheese"]) { //

Re: How to unit-test behavior under "version"?

2022-03-30 Thread Andrey Zherikov via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 04:15:24 UTC, Paul Backus wrote: Probably the easiest way is to split it into two functions ```d void f() { version (foo) fVersionFoo(); else fDefault(); } void fVersionFoo() { /* ... */ } void fDefault() { /* ... */ } ``` Then yo

Re: How to create delegates with an independent scope?

2022-03-30 Thread vit via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 12:56:39 UTC, Vijay Nayar wrote: On Wednesday, 30 March 2022 at 12:53:10 UTC, vit wrote: use two delegates :) ```d (){ // Deliberately create a copy to keep in delegate scope. string myStr = i.dup; // The

Re: How to create delegates with an independent scope?

2022-03-30 Thread Vijay Nayar via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 12:53:10 UTC, vit wrote: use two delegates :) ```d (){ // Deliberately create a copy to keep in delegate scope. string myStr = i.dup; // The delegate will hopefully carry this copy around in its own scope.

Re: How to create delegates with an independent scope?

2022-03-30 Thread vit via Digitalmars-d-learn
On Wednesday, 30 March 2022 at 12:46:07 UTC, Vijay Nayar wrote: Consider the following code example: ```d import std.stdio; void main() { alias DelegateT = string delegate(); // An array of delegates, each has their own scope. DelegateT[] funcs; foreach (i; ["ham", "cheese"]) { //

How to create delegates with an independent scope?

2022-03-30 Thread Vijay Nayar via Digitalmars-d-learn
Consider the following code example: ```d import std.stdio; void main() { alias DelegateT = string delegate(); // An array of delegates, each has their own scope. DelegateT[] funcs; foreach (i; ["ham", "cheese"]) { // Deliberately create a copy to keep in delegate scope. string