Re: Does the default opEquals include padding in the comparison? If so, how can the problems that arise with C++ interoperabilty be solved?

2020-10-21 Thread Simon van Bernem via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 20:10:03 UTC, Paul Backus wrote: On Wednesday, 21 October 2020 at 19:23:43 UTC, Simon van Bernem wrote: The only explanation I can think of is that D memcmps the entire struct including the padding. Is this correct? If so, what can I do about this? Why doesn't

Re: More elaborate asserts in unittests?

2020-10-21 Thread Mathias LANG via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:48:04 UTC, IGotD- wrote: On Wednesday, 21 October 2020 at 22:41:42 UTC, Adam D. Ruppe wrote: try compiling with dmd -checkaction=context Thanks, that was simple and it worked. Speaking of this, shouldn't this be documented here for example.

Re: More elaborate asserts in unittests?

2020-10-21 Thread IGotD- via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 23:54:41 UTC, bachmeier wrote: Click the "Improve this page" link in the upper right corner and add what you think needs to be there. Those PRs usually get a fast response. Will do, thank you for the direction.

Re: More elaborate asserts in unittests?

2020-10-21 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:48:04 UTC, IGotD- wrote: On Wednesday, 21 October 2020 at 22:41:42 UTC, Adam D. Ruppe wrote: try compiling with dmd -checkaction=context Thanks, that was simple and it worked. Speaking of this, shouldn't this be documented here for example.

Re: Question about: ("1.1").to!int;

2020-10-21 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:50:27 UTC, matheus wrote: Since (1.1).to!int = 1, shouldn't the string value ("1.1").to!int at least try to convert to float/double and then to int? I don't think so. A silent string->double conversion isn't IMO consistent with D's design.

Question about: ("1.1").to!int;

2020-10-21 Thread matheus via Digitalmars-d-learn
Hi, import std.stdio, std.conv; void main(string[ ] args) { auto a = (1).to!int; // this works auto b = ("1").to!int; // this works auto c = (1.1).to!int; // this works and c = 1 auto d = ("1.1").to!int; // Doesn't work } The forth line gives me:

Re: More elaborate asserts in unittests?

2020-10-21 Thread IGotD- via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:41:42 UTC, Adam D. Ruppe wrote: try compiling with dmd -checkaction=context Thanks, that was simple and it worked. Speaking of this, shouldn't this be documented here for example. https://dlang.org/spec/unittest.html Just adding a friendly tip that

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread DMon via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 16:38:34 UTC, Ferhat Kurtulmuş wrote: ş UTF-8: Å Numeric: Ansi: ÅŸ √

Re: More elaborate asserts in unittests?

2020-10-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 22:30:11 UTC, IGotD- wrote: When an assert fails in a unittest, I only get which line that failed. However, it would be very useful to see what the values are on either side of the unary boolean expression. Is this possible? try compiling with dmd

More elaborate asserts in unittests?

2020-10-21 Thread IGotD- via Digitalmars-d-learn
When an assert fails in a unittest, I only get which line that failed. However, it would be very useful to see what the values are on either side of the unary boolean expression. Is this possible?

Re: Does the default opEquals include padding in the comparison? If so, how can the problems that arise with C++ interoperabilty be solved?

2020-10-21 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 19:23:43 UTC, Simon van Bernem wrote: The only explanation I can think of is that D memcmps the entire struct including the padding. Is this correct? If so, what can I do about this? Why doesn't the opEquals get modified appropriately even though the struct is

Does the default opEquals include padding in the comparison? If so, how can the problems that arise with C++ interoperabilty be solved?

2020-10-21 Thread Simon van Bernem via Digitalmars-d-learn
I ask this question because I chased a very very nasty bug all the way down, and I think I found the offender: I have a extern(C++) struct that contains an 8-byte integer followed by a 4-byte enum value. I came across two variables of that type, that are not equal by comparison (no opEquals

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 14:03:54 UTC, DMon wrote: On Wednesday, 21 October 2020 at 13:04:40 UTC, Ferhat Kurtulmuş wrote: import std.range; import std.stdio; void main(){ auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; auto chunks = chunks(source, 2); writeln(chunks[0]); //

Re: Druntime without pthreads?

2020-10-21 Thread Denis Feklushkin via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 16:04:20 UTC, Denis Feklushkin wrote: On Tuesday, 20 October 2020 at 16:58:12 UTC, Severin Teona wrote: My curiosity is what would change if I removed from the druntime everything that has to do with mutexes As I remember, your plan is to use some type of

Re: Druntime without pthreads?

2020-10-21 Thread Denis Feklushkin via Digitalmars-d-learn
On Tuesday, 20 October 2020 at 16:58:12 UTC, Severin Teona wrote: My curiosity is what would change if I removed from the druntime everything that has to do with mutexes or threads. Nothing if you don't plan to use multithreading. I temporary disabled threading and appropriate unittests from

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread DMon via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 13:04:40 UTC, Ferhat Kurtulmuş wrote: import std.range; import std.stdio; void main(){ auto source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; auto chunks = chunks(source, 2); writeln(chunks[0]); // [1, 2] foreach(c; chunks) writeln(c[1]); }

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread DMon via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 13:43:51 UTC, matheus wrote: foreach (i,j;a){ if(i%2==0){ write(j, ", ");} } Thank you, matheus. for each on the list.

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread matheus via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 12:06:00 UTC, drug wrote: There are two other way: ... // using foreach foreach (i; 0..a.length) write(a[i], ", "); ... Yes you can use foreach, but in this case will not act the way the OP wanted. In his for loop example the "i" is incremented

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread Ferhat Kurtulmuş via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 11:55:54 UTC, DMon wrote: What is the simplest way to output every nth element of an array? I can do it using a for loop: void main() { int[5] a = [1,2,3,4,5]; for (int i = 0 ; i <= 4 ; i += 2) { writeln(a[i]); } } Basically, I am

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread DMon via Digitalmars-d-learn
On Wednesday, 21 October 2020 at 12:06:00 UTC, drug wrote: There are two other way: Thanks, drug. stride was what I was looking for.

Re: Skipping or Stepping Through an Array?

2020-10-21 Thread drug via Digitalmars-d-learn
There are two other way: ```D import std; void main() { int[] a = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ]; // using foreach foreach (i; 0..a.length) write(a[i], ", "); writeln; // using stride writeln(stride(a, 2)); } ```

Skipping or Stepping Through an Array?

2020-10-21 Thread DMon via Digitalmars-d-learn
What is the simplest way to output every nth element of an array? I can do it using a for loop: void main() { int[5] a = [1,2,3,4,5]; for (int i = 0 ; i <= 4 ; i += 2) { writeln(a[i]); } } Basically, I am wondering if I missed something.

Re: Druntime without pthreads?

2020-10-21 Thread Jacob Carlborg via Digitalmars-d-learn
On Tuesday, 20 October 2020 at 16:58:12 UTC, Severin Teona wrote: Hi guys. I have a curiosity, regarding [1] - I had encountered some "undefined reference" errors when trying to link the druntime (compiled for an embedded architecture) without some implementation of the POSIX thread calls