Re: incorrect data when returning static array in place of dynamic

2015-07-06 Thread sigod via Digitalmars-d-learn
On Monday, 6 July 2015 at 05:30:46 UTC, thedeemon wrote: On Sunday, 5 July 2015 at 18:57:46 UTC, sigod wrote: Why does function return incorrect data? Using `.dup` in return expression or using `ubyte[20]` as return type fixes problem, but why? Because sha1Of() returns ubyte[20], this is a

Re: incorrect data when returning static array in place of dynamic

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 07:48:17 UTC, sigod wrote: Aren't compiler smart enough to prevent it? ``` ubyte[] test1() { auto b = sha1Of(); return b; // Error: escaping reference to local b } ubyte[] test2() { return sha1Of(); // works, but returns incorrect data } ```

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: Hi, I have a struct with arithmetic operations defined using opBinary but array operations with arrays of it don't work. struct Vector3 { public double[3] _p; ... Vector3 opBinary(string op)(in Vector3 rhs) const if (op ==

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 03:02:59 UTC, Nicholas Wilson wrote: On Monday, 6 July 2015 at 01:16:54 UTC, Peter wrote: [...] unittest{ auto a = Vector3([2.0, 2.0, 0.0]); auto b = Vector3([1.0, 2.0, 1.0]); Vector3[] c = [a]; Vector3[] d = [b]; Vector3 e = a + b; // works

Which XMM are safe to erase in asm{} blocks?

2015-07-06 Thread ponce via Digitalmars-d-learn
What registers can I safely modify in asm {} blocks? Especially XMM registers. I can't find the information on http://dlang.org/iasm.html Note that this question isn't for function-call boundaries but asm{} boundaries since I do not use naked;

Re: How to strip struct/class invariants?

2015-07-06 Thread John Colvin via Digitalmars-d-learn
On Sunday, 5 July 2015 at 15:39:50 UTC, Artem Tarasov wrote: On Sunday, 5 July 2015 at 14:44:30 UTC, John Colvin wrote: struct A { ubyte[B.sizeof] mem; @property ref B b() { return *cast(B*)(mem.ptr); } mixin std.typecons.Proxy!b; } Thanks, I followed your

Re: code review based on what I learned from D

2015-07-06 Thread Bogdan via Digitalmars-d-learn
On Sunday, 5 July 2015 at 09:46:19 UTC, ketmar wrote: On Sun, 05 Jul 2015 21:39:23 +1200, Rikki Cattermole wrote: Of course of course. Valid options in failing gracefully include resetting the data and informing the user. Also giving them an option to send a bug report to the devs. Point

Re: code review based on what I learned from D

2015-07-06 Thread ponce via Digitalmars-d-learn
On Sunday, 5 July 2015 at 06:53:36 UTC, Szabo Bogdan wrote: you don't want to crash the user app, because this will make the user unhappy. This type reasoning is always flawed. It's like saying that the Earth is flat. http://p0nce.github.io/d-idioms/#Unrecoverable-vs-recoverable-errors

Re: Array operations with array of structs

2015-07-06 Thread Peter via Digitalmars-d-learn
On Monday, 6 July 2015 at 10:29:35 UTC, anonymous wrote: Works for me with various versions of dmd on linux. What compiler are you using, what version of it, what operating system, etc? dmd 2.066.1, windows 7 64bit

Re: How to strip struct/class invariants?

2015-07-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/5/15 8:15 AM, Artem Tarasov wrote: OK, so there was an old bug fixed in 2.067 (https://issues.dlang.org/show_bug.cgi?id=4421) so that now unions apparently can't contain a struct that has invariants. It kinda makes sense, although I don't see why the invariants can be simply ignored, as

Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread Gary Willoughby via Digitalmars-d-learn
How do you correctly implement a bidirectional range on a linked list? I have a linked list implementation and I've added a range interface to it but after a while I've realized it not quite right. The problem is when I call the save method of the forward range interface I don't get a copy I

Re: Array operations with array of structs

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 12:15:22 UTC, Peter wrote: dmd 2.066.1, windows 7 64bit Tested it on Windows 7, using dmd 2.066.1: works for me. The exact code I tested (just commented those ... out): struct Vector3 { public double[3] _p; //... Vector3 opBinary(string op)(in

Re: turning an array of structs into a struct of arrays

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Sunday, 5 July 2015 at 00:07:59 UTC, Laeeth Isharc wrote: Posted short write-up here. Please make it better... http://wiki.dlang.org/Transforming_slice_of_structs_into_struct_of_slices In John Colvin's solution, should alias TransformMembers(alias TypeTransform, alias

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 July 2015 at 20:50:19 UTC, Gary Willoughby wrote: The problem is when I call the save method of the forward range interface I don't get a copy I only get another view to the same state. So when i remove nodes from the original list the range becomes invalid. This is why

FFMPEG Bindings

2015-07-06 Thread via Digitalmars-d-learn
Have anybody used the FFMPEG bindings at https://bitbucket.org/sumitraja/ffmpeg-d ? Specifically do I have to check for a specific version of the libraries to stay in sync with the version bindings? How stable has the FFMPEG API since beginning 2015? What's the policy on future API

Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
Say I'm trying to expand an array of file and directory paths (such as ones given as command line args) into a range of file paths I can iterate over. A simplified example might be: auto getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p = p.isFile); if

Malloc struct

2015-07-06 Thread codenstuff via Digitalmars-d-learn
I need to create following struct using malloc struct Map { int **entries; int rows; int cols; } Map *map_create(int rows, int cols) { Map *that = cast(Map*)malloc(Map.sizeof); that.entries = cast(int**)malloc(rows * int.sizeof); foreach(row; 0..rows) { that.entries[row] =

Re: Malloc struct

2015-07-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/6/15 2:15 PM, codenstuff wrote: I need to create following struct using malloc struct Map { int **entries; int rows; int cols; } Map *map_create(int rows, int cols) { Map *that = cast(Map*)malloc(Map.sizeof); that.entries = cast(int**)malloc(rows * int.sizeof); (int *).sizeof

Re: How to setup GDC with Visual D?

2015-07-06 Thread Guy Gervais via Digitalmars-d-learn
On Sunday, 5 July 2015 at 19:50:41 UTC, Johannes Pfau wrote: GDC uses a slightly older phobos version. It seems quite some imports changed in the last phobos version. You need to import std.algorithm and your code should work with gdc: http://goo.gl/l4zKki Thanks. Turns out my imports are

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
As it turns out, inputRangeObject does an excellent job at this task. The solution then becomes something like: InputRange!string getEntries(string[] paths, bool recursive) { auto files = paths.filter!(p = p.isFile); if (recursive) { auto expandedDirs = paths

optimizing struct/class members

2015-07-06 Thread lobo via Digitalmars-d-learn
Hi, In C++ it's important to layout struct/class members correctly for performance reasons. Is the same true in D? Thanks, lobo

Re: optimizing struct/class members

2015-07-06 Thread John Colvin via Digitalmars-d-learn
On Monday, 6 July 2015 at 23:24:00 UTC, lobo wrote: Hi, In C++ it's important to layout struct/class members correctly for performance reasons. Is the same true in D? Thanks, lobo Short answer: yes.

Re: Coercing ranges to the same type

2015-07-06 Thread Matt Kline via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:35:53 UTC, Alex Parrill wrote: They aren't actually the same types I understand the problem - I was just wondering if there was a standard library solution to this or if I would have to roll my own. use a class wrapper in std.range.interface [1]. [1]:

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 20:50:19 UTC, Gary Willoughby wrote: How do you correctly implement a bidirectional range on a linked list? I have a linked list implementation and I've added a range interface to it but after a while I've realized it not quite right. The problem is when I call the

Re: Coercing ranges to the same type

2015-07-06 Thread Alex Parrill via Digitalmars-d-learn
On Monday, 6 July 2015 at 19:46:51 UTC, Matt Kline wrote: Say I'm trying to expand an array of file and directory paths (such as ones given as command line args) into a range of file paths I can iterate over. A simplified example might be: auto getEntries(string[] paths, bool recursive) {

Re: Correctly implementing a bidirectional range on a linked list?

2015-07-06 Thread anonymous via Digitalmars-d-learn
On Monday, 6 July 2015 at 21:58:31 UTC, anonymous wrote: To make your removal methods stable, it may be enough to not free the removed node. That is, don't do this: https://github.com/nomad-software/etcetera/blob/master/source/etcetera/collection Looks like I messed up the URL. Here's the

Re: turning an array of structs into a struct of arrays

2015-07-06 Thread John Colvin via Digitalmars-d-learn
On Monday, 6 July 2015 at 17:35:22 UTC, Vlad Levenfeld wrote: On Sunday, 5 July 2015 at 00:07:59 UTC, Laeeth Isharc wrote: Posted short write-up here. Please make it better... http://wiki.dlang.org/Transforming_slice_of_structs_into_struct_of_slices In John Colvin's solution, should

Re: optimizing struct/class members

2015-07-06 Thread lobo via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 00:23:38 UTC, John Colvin wrote: On Monday, 6 July 2015 at 23:24:00 UTC, lobo wrote: Hi, In C++ it's important to layout struct/class members correctly for performance reasons. Is the same true in D? Thanks, lobo Short answer: yes. thanks, lobo

documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation.

Re: FFMPEG Bindings

2015-07-06 Thread ketmar via Digitalmars-d-learn
On Mon, 06 Jul 2015 16:42:08 +, Per Nordlöw wrote: How stable has the FFMPEG API since beginning 2015? don't know, but various players stop bundling ffmpeg long time ago. i assume that API is stable enough to stop worrying about it. warning. information deduced, but not checked.

Re: FFMPEG Bindings

2015-07-06 Thread ketmar via Digitalmars-d-learn
p.s. stop bundling means stop bundling their own private versions in source tree, and started to use system version here. signature.asc Description: PGP signature

Re: documenting compile-time constants

2015-07-06 Thread Vlad Levenfeld via Digitalmars-d-learn
On Tuesday, 7 July 2015 at 03:30:40 UTC, Rikki Cattermole wrote: On 7/07/2015 1:05 p.m., Vlad Levenfeld wrote: How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation. If: /// enum MyValue

Re: documenting compile-time constants

2015-07-06 Thread Rikki Cattermole via Digitalmars-d-learn
On 7/07/2015 1:05 p.m., Vlad Levenfeld wrote: How do I ddoc an enum constant? Putting ddoc comments above functions and structs woorks fine but ddocing an enum constant doesn't generate any documentation. If: /// enum MyValue = 8.2f; does not generate documentation upon its creation, please

Squaring Arrays without Overlapping Array Error

2015-07-06 Thread jmh530 via Digitalmars-d-learn
If I call a function like int[] square_array(int[] x) { return x[] *= x[]; } I get an error that there is an overlapping array in a vector operation. I guess this makes sense as the lhs and rhs are occupying the same memory. Nevertheless, I find it a little frustrating. I tried two

Re: incorrect data when returning static array in place of dynamic

2015-07-06 Thread via Digitalmars-d-learn
On Monday, 6 July 2015 at 10:20:28 UTC, anonymous wrote: dmd 2.068.0 catches this. You can get the beta here: http://downloads.dlang.org/pre-releases/2.x/2.068.0/ ... and it already contains a std.digest.hmac module :-)