New discussion

2024-02-05 Thread Kagamin via Digitalmars-d-learn
You can just post with a new title.

Re: Safety is not what you think

2024-02-05 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote: [...] This definitely isn't allowed in C or C++. I wonder what the rationale is for having this behavior in D? [1]: https://dlang.org/spec/expression.html An hypothesis is that this makes codegening the pre and the post variant

Re: real.sizeof

2024-02-05 Thread Paul Backus via Digitalmars-d-learn
On Monday, 5 February 2024 at 16:45:03 UTC, Dom DiSc wrote: Why is real.sizeof == 16 on x86-systems?!? Its the IEEE 754 extended format: 64bit mantissa + 15bit exponent + sign. It should be size 10! I mean, alignment may be different, but why wasting so much memory even in arrays? According

Re: real.sizeof

2024-02-05 Thread Iain Buclaw via Digitalmars-d-learn
On Monday, 5 February 2024 at 16:45:03 UTC, Dom DiSc wrote: Why is real.sizeof == 16 on x86-systems?!? Its the IEEE 754 extended format: 64bit mantissa + 15bit exponent + sign. It should be size 10! I mean, alignment may be different, but why wasting so much memory even in arrays? Padding.

Re: Safety is not what you think

2024-02-05 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 February 2024 at 14:26:45 UTC, Basile B. wrote: On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote: [...] This definitely isn't allowed in C or C++. I wonder what the rationale is for having this behavior in D? [1]: https://dlang.org/spec/expression.html An hypothes

Re: real.sizeof

2024-02-05 Thread Dom DiSc via Digitalmars-d-learn
On Monday, 5 February 2024 at 17:28:38 UTC, Iain Buclaw wrote: Padding. x86 ABI prefers things to be aligned, so on x86 it's 12 bytes, x86_64 16 bytes. In both cases you don't get any extra precision over the 80-bits that x87 gives you. This is exactly what I mean. The ABI may pad it, but

How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
I hope all is well with everyone. I have come to an impasse. What is the best way to unpack a tuple into multiple variables in D similar to this Python code? Thank you! ```python # Example tuple my_tuple = (2010, 10, 2, 11, 4, 0, 2, 41, 0) # Unpack the tuple into separate variables year, month

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread TTK Ciar via Digitalmars-d-learn
I've been using AliasSeq for that (and aliasing it to "put" for easier use): ```d import std.meta; alias put = AliasSeq; auto foo() { return tuple(1, 2, 3); } int main(string[] args) { int x, y, z; put!(x, y, z) = foo(); writeln(x, y, z); return 0; } ``` My mnemonic: "put" is "tup" b

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Sergey via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:12:58 UTC, Gary Chike wrote: I hope all is well with everyone. I have come to an impasse. What is the best way to unpack a tuple into multiple variables in D similar to this Python code? Thank you! ### TL;DR The direct implementation still not presented. But th

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:30:15 UTC, Sergey wrote: In those posts you can find other "solutions", Tuple DIP description and other useful ideas. Thank you Sergey! Still reading through the different 'solutions' - very informative.

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Gary Chike via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:21:33 UTC, TTK Ciar wrote: My mnemonic: "put" is "tup" backwards, and undoes what tuple does. Very clever mnemonic TTK Ciar! :) After reviewing the various solutions, the one I seem to gravitate towards is based on the one you presented, well, at least for now

Re: How to unpack a tuple into multiple variables?

2024-02-05 Thread Profunctor via Digitalmars-d-learn
On Monday, 5 February 2024 at 21:12:58 UTC, Gary Chike wrote: [ ... ] In addition to the methods hitherto provided: ```d auto getUser() => tuple("John Doe", 32); // Name a Tuple's fields post hoc by copying the original's fields into a new Tuple. template named(names...) { auto named(T)