Builtin Support for Comparison Function for Primitive Types

2015-05-02 Thread via Digitalmars-d-learn
Why doesn't std.algorithm.comparison.cmp support primitive types such as assert(cmp(0,1) == true); ?

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 02, 2015 01:21:14 Ali Çehreli via Digitalmars-d-learn wrote: 2) void foo(const(int[]) arr); // cannot affect anything // (even capacity) Actually, you can modify the capacity of arr quite easily. All you have to do is slice it

Re: Merging one Array with Another

2015-05-02 Thread via Digitalmars-d-learn
On Friday, 1 May 2015 at 19:30:08 UTC, Ilya Yaroshenko wrote: Both variants are wrong because uniq needs sorted ranges. Probably you need something like that: x = x.chain(y).sort.uniq.array; Interesting. Is x = x.chain(y).sort faster than x ~= y; x.sort; ? If so why?

Re: Builtin Support for Comparison Function for Primitive Types

2015-05-02 Thread via Digitalmars-d-learn
On Saturday, 2 May 2015 at 08:29:11 UTC, Per Nordlöw wrote: Why doesn't std.algorithm.comparison.cmp support primitive types such as assert(cmp(0,1) == true); ? Correction if mean assert(cmp(0,1) == -1);

Re: Builtin Support for Comparison Function for Primitive Types

2015-05-02 Thread via Digitalmars-d-learn
On Saturday, 2 May 2015 at 08:29:11 UTC, Per Nordlöw wrote: Why doesn't std.algorithm.comparison.cmp support primitive types such as assert(cmp(0,1) == true); ? I just found some forgotten code of my that solves it through import std.range: only; assert(cmp(only(0), only(1)) ==

Re: Merging one Array with Another

2015-05-02 Thread Meta via Digitalmars-d-learn
On Saturday, 2 May 2015 at 10:18:07 UTC, Per Nordlöw wrote: On Friday, 1 May 2015 at 19:30:08 UTC, Ilya Yaroshenko wrote: Both variants are wrong because uniq needs sorted ranges. Probably you need something like that: x = x.chain(y).sort.uniq.array; Interesting. Is x =

A slice can lose capacity simply by calling a function

2015-05-02 Thread Ali Çehreli via Digitalmars-d-learn
This is related to a discussion[1] that I had started recently but I will give an even shorter example here: void main() { // Two slices to all element auto a = [ 1, 2, 3, 4 ]; auto b = a; // Initially, they both have capacity (strange! :) ) assert(a.capacity == 7);

Re: Merging one Array with Another

2015-05-02 Thread via Digitalmars-d-learn
On Saturday, 2 May 2015 at 11:16:30 UTC, Meta wrote: Probably the latter is slower than the former, at the very least because the latter requires memory allocation whereas the former does not. Ahh!, auto x = [11, 3, 2, 4, 5, 1]; auto y = [0, 3, 10, 2, 4, 5, 1]; auto z =

Re: stdx.data.json - enhancement suggestions

2015-05-02 Thread Laeeth Isharc via Digitalmars-d-learn
On Friday, 1 May 2015 at 20:04:58 UTC, Ilya Yaroshenko wrote: This line can be removed: .map!(ch = ch.idup) On Friday, 1 May 2015 at 20:02:46 UTC, Ilya Yaroshenko wrote: Current std.stdio is deprecated. This ad-hoc should works. auto json = File(fileName)

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Ali Çehreli via Digitalmars-d-learn
On 05/02/2015 01:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote: I really don't think that it's reasonable in the general case to expect to be able to guarantee that the capacity of a dynamic array won't change. Yes, it is very different from other languages like C and C++ that

Re: Reducing source code: weak+alias values in array

2015-05-02 Thread Jens Bauer via Digitalmars-d-learn
On Saturday, 2 May 2015 at 13:08:27 UTC, Artur Skawina wrote: On 05/02/15 05:28, Jens Bauer via Digitalmars-d-learn wrote: On Saturday, 2 May 2015 at 03:21:38 UTC, Jens Bauer wrote: For some reason, my build time has increased dramatically... Building with 1 vector takes 0.6 seconds. Building

Re: stdx.data.json - enhancement suggestions

2015-05-02 Thread Laeeth Isharc via Digitalmars-d-learn
It doesn't like it. Any thoughts ? lexer.d(257): Error: safe function 'stdx.data.json.parser.JSONLexerRange!(MapResult!(__lambda3, Result), cast(LexOptions)0, __lambda31).JSONLexerRange.empty' cannot call system function 'app.lookupTickers.MapResult!(__lambda3, Result).MapResult.empty'

Reading bzipped files

2015-05-02 Thread via Digitalmars-d-learn
Have anybody cooked up any range adaptors for on the fly decoding of bzipped files? Preferable compatible with phobos standard interfaces for file io. Should probably be built on top of http://code.dlang.org/packages/bzip2

Re: Reducing source code: weak+alias values in array

2015-05-02 Thread Artur Skawina via Digitalmars-d-learn
On 05/02/15 05:28, Jens Bauer via Digitalmars-d-learn wrote: On Saturday, 2 May 2015 at 03:21:38 UTC, Jens Bauer wrote: For some reason, my build time has increased dramatically... Building with 1 vector takes 0.6 seconds. Building with 2 vector takes 0.7 seconds. Building with 4 vector

Re: Destruction in D

2015-05-02 Thread via Digitalmars-d-learn
On Friday, 1 May 2015 at 18:37:41 UTC, Idan Arye wrote: On Friday, 1 May 2015 at 17:45:02 UTC, bitwise wrote: On Friday, 1 May 2015 at 02:35:52 UTC, Idan Arye wrote: On Thursday, 30 April 2015 at 23:27:49 UTC, bitwise wrote: Well, the third thing was just my reasoning for asking in the first

Re: What wrong?

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42 11 Compiled by DMD v2.067.1 the program crashes: $ ./aa TUQLUE

Re: A slice can lose capacity simply by calling a function

2015-05-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, May 02, 2015 07:46:27 Ali Çehreli via Digitalmars-d-learn wrote: On 05/02/2015 01:56 AM, Jonathan M Davis via Digitalmars-d-learn wrote: I really don't think that it's reasonable in the general case to expect to be able to guarantee that the capacity of a dynamic array won't

Re: Destruction in D

2015-05-02 Thread bitwise via Digitalmars-d-learn
On Fri, 01 May 2015 14:37:40 -0400, Idan Arye generic...@gmail.com wrote: Structs allow you to implement ref-counting smart pointers like you can do in C++. There is an implementation in the standard library: http://dlang.org/phobos/std_typecons.html#.RefCounted Yeah, I guess I should have

Re: Reading bzipped files

2015-05-02 Thread tom via Digitalmars-d-learn
On Saturday, 2 May 2015 at 13:50:10 UTC, Per Nordlöw wrote: Have anybody cooked up any range adaptors for on the fly decoding of bzipped files? Preferable compatible with phobos standard interfaces for file io. Should probably be built on top of http://code.dlang.org/packages/bzip2 i use

Re: What wrong?

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Saturday, 2 May 2015 at 19:38:01 UTC, Fyodor Ustinov wrote: I see it by the lack of 42. :) But why is this receive breaks down? Report, please, about it (D)evepopers :) https://issues.dlang.org/

Re: stdx.data.json - enhancement suggestions

2015-05-02 Thread Ilya Yaroshenko via Digitalmars-d-learn
You can use std.json or create TrustedInputRangeShell template with @trasted methods: struct TrustedInputRangeShell(Range) { Range* data; auto front() @property @trusted { return (*data).front; } //etc } But I am not sure about other parseJSONStream bugs.

How to I translate this C++ structure/array

2015-05-02 Thread WhatMeWorry via Digitalmars-d-learn
This is probably trivial but I just can't make a break thru. I've got C++ code using glm like so: struct Vertex { glm::vec3 position; glm::vec3 color; } Vertex triangle[] = [ glm::vec3(0.0, 1.0, 0.0), glm::vec3(1.0, 0.0, 0.0), // red

why std.process.Pid std.process.Environment are classes ?

2015-05-02 Thread Baz via Digitalmars-d-learn
In std.process, the following declarations: - final class Pid - abstract final class environment could be struct, couldn't they ? Any particular reason behind this choice ?

Re: How to I translate this C++ structure/array

2015-05-02 Thread anonymous via Digitalmars-d-learn
On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote: struct Vertex { vec3 position; vec3 color; } Vertex triangle[6] = [ vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), // red // code removed for brevity. ]; I keep getting

Parameter storage class 'in' transitive like 'const'?

2015-05-02 Thread Ali Çehreli via Digitalmars-d-learn
We know that 'in' is equivalent to const scope: http://dlang.org/function.html#parameters So, the constness of 'in' is transitive as well, right? Ali

Re: What wrong?

2015-05-02 Thread Fyodor Ustinov via Digitalmars-d-learn
On Saturday, 2 May 2015 at 19:13:45 UTC, Dennis Ritchie wrote: On Saturday, 2 May 2015 at 02:51:52 UTC, Fyodor Ustinov wrote: Simple code: http://pastebin.com/raw.php?i=7jVeMFXQ This code works compiled by DMD v2.066.1 and LDC2 (0.15.1) based on DMD v2.066.1 and LLVM 3.5.0. $ ./z TUQLUE 42

Re: Ada to D - an array for storing values of each of the six bits which are sufficient

2015-05-02 Thread Dennis Ritchie via Digitalmars-d-learn
On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote: Maybe someone will show a primitive packed array. I really can not imagine how to do it on D. Maybe you can somehow use bitfields. While what happened is something like this: - import std.stdio, std.bitmanip;

Re: How to I translate this C++ structure/array

2015-05-02 Thread WhatMeWorry via Digitalmars-d-learn
On Saturday, 2 May 2015 at 22:36:29 UTC, anonymous wrote: On Saturday, 2 May 2015 at 22:01:10 UTC, WhatMeWorry wrote: struct Vertex { vec3 position; vec3 color; } Vertex triangle[6] = [ vec3(0.0, 1.0, 0.0), vec3(1.0, 0.0, 0.0), // red //