Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 21:45:39 UTC, Paul Backus wrote: On Monday, 13 June 2022 at 19:48:06 UTC, JG wrote: Hi, I reduced my code to the following. Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? Reduced

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread Paul Backus via Digitalmars-d-learn
On Monday, 13 June 2022 at 19:48:06 UTC, JG wrote: Hi, I reduced my code to the following. Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? Reduced further: ```d import std.sumtype; struct Tuple { void

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 20:25:00 UTC, Steven Schveighoffer wrote: On 6/13/22 4:09 PM, JG wrote: Thanks. It seems to be something to do with the variadic template since this works: ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 4:09 PM, JG wrote: Thanks. It seems to be something to do with the variadic template since this works: ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto parseErrorOr(T)(T x) { return ParseErrorOr!T(x); } auto parserOr(I,alias

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
On Monday, 13 June 2022 at 19:59:16 UTC, Steven Schveighoffer wrote: On 6/13/22 3:48 PM, JG wrote: Hi, I reduced my code to the following.  Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct

Re: Failure due to memcpy being called at compile time

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 3:48 PM, JG wrote: Hi, I reduced my code to the following.  Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) =

Failure due to memcpy being called at compile time

2022-06-13 Thread JG via Digitalmars-d-learn
Hi, I reduced my code to the following. Could anyone help me to discover why the line marked with //THIS LINE causes memcpy to be called, and how can I avoid this? ```d import std; struct ParseError { string msg; } alias ParseErrorOr(T) = SumType!(ParseError,T); auto parseErrorOr(T)(T x)

Re: Dynamic chain for ranges?

2022-06-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 13 June 2022 at 14:03:13 UTC, Steven Schveighoffer wrote: Merge sort only works if it's easy to manipulate the structure, like a linked-list, or to build a new structure, like if you don't care about allocating a new array every iteration. The easiest option is to have two buffers

Re: Dynamic chain for ranges?

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 9:44 AM, Ola Fosheim Grøstad wrote: On Monday, 13 June 2022 at 13:22:52 UTC, Steven Schveighoffer wrote: I would think sort(joiner([arr1, arr2, arr3])) should work, but it's not a random access range. Yes, I got the error «must satisfy the following constraint:

Re: Dynamic chain for ranges?

2022-06-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 13 June 2022 at 13:22:52 UTC, Steven Schveighoffer wrote: I would think sort(joiner([arr1, arr2, arr3])) should work, but it's not a random access range. Yes, I got the error «must satisfy the following constraint: isRandomAccessRange!Range`». It would be relatively easy to make

Re: Comparing Exceptions and Errors

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 9:15 AM, Steven Schveighoffer wrote: Yes. If you don't execute the rollback and start executing more DB calls, they all get included in the transaction (and might be expected to be). Should have said "might *not* be expected to be" -Steve

Re: Dynamic chain for ranges?

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/13/22 4:51 AM, Ola Fosheim Grøstad wrote: Is there a dynamic chain primitive, so that you can add to the chain at runtime? Context: the following example on the front page is interesting. ```d void main() {     int[] arr1 = [4, 9, 7];     int[] arr2 = [5, 2, 1, 10];     int[] arr3 =

Re: Comparing Exceptions and Errors

2022-06-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/12/22 4:11 PM, kdevel wrote: On Tuesday, 7 June 2022 at 18:37:13 UTC, Steven Schveighoffer wrote: [...] My very common use of `scope(failure)` for my DB code: ```d conn.exec("START TRANSACTION"); scope(success) conn.exec("COMMIT"); scope(failure) conn.exec("ROLLBACK"); ``` Are there

Re: Dynamic chain for ranges?

2022-06-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Monday, 13 June 2022 at 09:08:40 UTC, Salih Dincer wrote: On Monday, 13 June 2022 at 08:51:03 UTC, Ola Fosheim Grøstad wrote: But it would be much more useful in practice if "chain" was a dynamic array. Already so: I meant something like: chain = [arr1, arr2, …, arrN] I don't use

Re: Dynamic chain for ranges?

2022-06-13 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 13 June 2022 at 08:51:03 UTC, Ola Fosheim Grøstad wrote: But it would be much more useful in practice if "chain" was a dynamic array. Already so: ```d int[] arr = [4, 9, 7, 5, 2, 1, 10, 6, 8, 3]; int[] arr1 = arr[0..3]; int[] arr2 = arr[3..7]; int[] arr3 = arr[7..$];

Dynamic chain for ranges?

2022-06-13 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
Is there a dynamic chain primitive, so that you can add to the chain at runtime? Context: the following example on the front page is interesting. ```d void main() { int[] arr1 = [4, 9, 7]; int[] arr2 = [5, 2, 1, 10]; int[] arr3 = [6, 8, 3]; sort(chain(arr1, arr2, arr3));

Re: Generating unique identifiers at compile time

2022-06-13 Thread user1234 via Digitalmars-d-learn
On Monday, 13 June 2022 at 07:38:54 UTC, user1234 wrote: On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: [...] No, for now there if there are other ways they are as hacky as yours. The compiler usually uses a global counter to

Re: Generating unique identifiers at compile time

2022-06-13 Thread user1234 via Digitalmars-d-learn
On Thursday, 9 June 2022 at 23:50:10 UTC, user1234 wrote: On Thursday, 9 June 2022 at 21:20:27 UTC, JG wrote: [...] No, for now there if there are other ways they are as hacky as yours. The compiler usually uses a global counter to generate temporaries. There's [been attempts] to expose

Re: Can I create a package with friendly modules

2022-06-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 12 June 2022 at 05:05:46 UTC, forkit wrote: Is it possible to create a package.d, consisting of (for example), two modules, where each module can access private declarations within each other. In essence, declaring 'a module level friendship', or a kind of 'extended module' if you