Re: Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 10:11 AM, Bahman Movaqar wrote: > Alright...further experiments. The following works: > > sort!((pp1, pp2) => cmp(pp1.price, pp2.price) > 0)(theRange) > > So it may be something about what kind of range I'm passing to `sort`. > Am I right? > I meant sort!((pp1, pp2) =>

Re: Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/26/2016 09:35 AM, Bahman Movaqar wrote: > I have a range which is the result of a couple of chained range > operations, and each element is: > > Tuple!(string, "product", double, "price") > > Now I'd like to sort the range by "price" using: > > sort!((pp1, pp2) => cmp(pp1.price,

Trouble using 'sort'

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
I have a range which is the result of a couple of chained range operations, and each element is: Tuple!(string, "product", double, "price") Now I'd like to sort the range by "price" using: sort!((pp1, pp2) => cmp(pp1.price, pp2.price) > 0)(theRange) But I get a compile time error:

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread ketmar via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 04:05:22 UTC, Charles Hixson wrote: Yes, but I really despise the syntax they came up with. It's probably good if most of your I/O is ranges, but mine hasn't yet ever been. (Combining ranges with random I/O?) that's why i wrote iv.stream, and then iv.vfs, with

Re: Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
Ahh I see, thanks guys.

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 07:11 PM, ketmar via Digitalmars-d-learn wrote: On Tuesday, 26 July 2016 at 01:19:49 UTC, Charles Hixson wrote: then I will prefer the core.stdc.stdio approach. I find it's appearance extremely much cleaner... only if you are really used to write C code. when you see pointer,

Re: Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/25/2016 05:47 PM, Adam D. Ruppe wrote: > On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote: >> From what I could gather, it's not possible to check for `null` at >> runtime for reference based types. Am I right? > > No, it is only possible to check for null for reference based

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread ketmar via Digitalmars-d-learn
On Tuesday, 26 July 2016 at 01:19:49 UTC, Charles Hixson wrote: then I will prefer the core.stdc.stdio approach. I find it's appearance extremely much cleaner... only if you are really used to write C code. when you see pointer, or explicit type size argument in D, it is a sign of C

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
On 07/25/2016 05:18 PM, ketmar via Digitalmars-d-learn wrote: On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary random io? What are the advantages? In particular, if one is

Re: Static ternary if

2016-07-25 Thread Michael Coulombe via Digitalmars-d-learn
On Monday, 25 July 2016 at 22:57:05 UTC, Gorge Jingale wrote: On Monday, 25 July 2016 at 22:27:11 UTC, Cauterite wrote: On Monday, 25 July 2016 at 02:15:12 UTC, Gorge Jingale wrote: Is there a static ternary if? (A == B) ? C : D; for compile type that works like static if. You can pretty

Re: randomIO, std.file, core.stdc.stdio

2016-07-25 Thread ketmar via Digitalmars-d-learn
On Monday, 25 July 2016 at 18:54:27 UTC, Charles Hixson wrote: Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary random io? What are the advantages? In particular, if one is reading and writing structs rather than arrays or ranges, are

Re: Static ternary if

2016-07-25 Thread Gorge Jingale via Digitalmars-d-learn
On Monday, 25 July 2016 at 22:27:11 UTC, Cauterite wrote: On Monday, 25 July 2016 at 02:15:12 UTC, Gorge Jingale wrote: Is there a static ternary if? (A == B) ? C : D; for compile type that works like static if. You can pretty easily make your own; template staticIf(bool cond, alias a,

Re: Static ternary if

2016-07-25 Thread Cauterite via Digitalmars-d-learn
On Monday, 25 July 2016 at 02:15:12 UTC, Gorge Jingale wrote: Is there a static ternary if? (A == B) ? C : D; for compile type that works like static if. You can pretty easily make your own; template staticIf(bool cond, alias a, alias b) { static if (cond) { alias staticIf = a;

randomIO, std.file, core.stdc.stdio

2016-07-25 Thread Charles Hixson via Digitalmars-d-learn
Are there reasons why one would use rawRead and rawWrite rather than fread and fwrite when doiing binary random io? What are the advantages? In particular, if one is reading and writing structs rather than arrays or ranges, are there any advantages?

Re: Default implementations in inherited interfaces

2016-07-25 Thread Saurabh Das via Digitalmars-d-learn
On Sunday, 24 July 2016 at 07:54:11 UTC, Jonathan Marler wrote: On Thursday, 21 July 2016 at 13:37:30 UTC, Saurabh Das wrote: On Thursday, 21 July 2016 at 12:42:14 UTC, Adam D. Ruppe wrote: On Thursday, 21 July 2016 at 09:41:27 UTC, Saurabh Das wrote: Java 8 has a 'default' keyword that allows

Re: Trouble checking for null-ness

2016-07-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Monday, 25 July 2016 at 13:09:22 UTC, Bahman Movaqar wrote: From what I could gather, it's not possible to check for `null` at runtime for reference based types. Am I right? No, it is only possible to check for null for reference based types. But map's result is not a reference based

Re: Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
On 07/25/2016 05:07 PM, Bahman Movaqar wrote: > Suppose I have the following function: > > public auto max(alias comp, Range)(Range r) > in { > assert(r !is null && !r.empty); > } > body { > // ... > } > > When the function after a series of chained `map`

Re: Static ternary if

2016-07-25 Thread lqjglkqjsg via Digitalmars-d-learn
On Monday, 25 July 2016 at 05:00:23 UTC, Ali Çehreli wrote: On 07/24/2016 07:15 PM, Gorge Jingale wrote: Is there a static ternary if? (A == B) ? C : D; for compile type that works like static if. The way to force an expression at compile time is to use it for something that's needed at

Re: Trouble checking for null-ness

2016-07-25 Thread Mike Parker via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote: Suppose I have the following function: public auto max(alias comp, Range)(Range r) in { assert(r !is null && !r.empty); } body { // ... } When the function after a series of chained `map` operations,

Re: Trouble checking for null-ness

2016-07-25 Thread Cauterite via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:47:25 UTC, Cauterite wrote: (!__traits(compiles, r is null) || r !is null) && !r.empty Ah, whoops that's wrong, looks like ketmar had the right idea.

Re: Trouble checking for null-ness

2016-07-25 Thread Cauterite via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote: But I'm curious; how can I check for a `null` in this case? Well, if you're happy with assertion failure by access violation, you may not even need to check for null, because generally if you try to call .empty on a null pointer

Re: Trouble checking for null-ness

2016-07-25 Thread ag0aep6g via Digitalmars-d-learn
On Monday, 25 July 2016 at 12:37:18 UTC, Bahman Movaqar wrote: Error: incompatible types for ((r) !is (null)): 'MapResult!(__lambda2, SInvoiceLine[])' and 'typeof(null)' Of course if I remove `r !is null` from the `in` block, everything will work. But I'm curious; how can I check for a

Re: Trouble checking for null-ness

2016-07-25 Thread ketmar via Digitalmars-d-learn
static if (is(typeof(r is null))) { ...you can do your assert here... }

Trouble checking for null-ness

2016-07-25 Thread Bahman Movaqar via Digitalmars-d-learn
Suppose I have the following function: public auto max(alias comp, Range)(Range r) in { assert(r !is null && !r.empty); } body { // ... } When the function after a series of chained `map` operations, I get the following error: Error: incompatible types for

Re: Getting most derived type of object that implements interface

2016-07-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/25/16 5:54 AM, Kagamin wrote: Cast it to Object: FooInterface a = new BarImplementsInterface(); FooBaseClass b = new BarDerivedClass(); Object o = cast(Object)a; writefln("a class: %s", a.classinfo.name); writefln("b class: %s", b.classinfo.name); writefln("o class:

dub set default compiler for project

2016-07-25 Thread Nicholas Wilson via Digitalmars-d-learn
dub build has the --compiler= option. Is there any way to set it to default a custom version (own branch, resides in ../../ldcbuild/bin/ldc2 ) of ldc2 in the dub.json (or .sdl)? The project will only compile with that compiler.

Re: Cannot compare object.opEquals is not nogc

2016-07-25 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/23/16 5:44 PM, Rufus Smith wrote: On Saturday, 23 July 2016 at 17:27:24 UTC, Lodovico Giaretta wrote: On Saturday, 23 July 2016 at 17:04:42 UTC, Jonathan Marler wrote: On Saturday, 23 July 2016 at 16:46:20 UTC, Jonathan Marler wrote: [...] Actually Im going to disagree with myself.

Re: How to pause terminal in D on Linux?

2016-07-25 Thread lqjglkqjsg via Digitalmars-d-learn
On Sunday, 24 July 2016 at 00:54:21 UTC, Zekereth wrote: On Saturday, 23 July 2016 at 19:08:00 UTC, WhatMeWorry wrote: What I thought would be trivial is becoming a nightmare. Can anybody set me straight. Thanks in advance. [...] Use the getchar() function. void pause(const string msg =

Re: Singletons importing each other?

2016-07-25 Thread Jack via Digitalmars-d-learn
On Sunday, 24 July 2016 at 15:38:13 UTC, lqjglkqjsg wrote: On Sunday, 24 July 2016 at 15:07:20 UTC, Jack wrote: [...] - You can use a 3rd module that imports the two that "cycle". - You can use another singleton implementation that doesn't rely on a static this. e.g a kind of "lazy factory"

Re: Getting most derived type of object that implements interface

2016-07-25 Thread ketmar via Digitalmars-d-learn
yep, cast it. without the cast, compiler assuming that it knows the type in runtime, and is using well-known classinfo address instead of really looking into instance for that.

Re: Getting most derived type of object that implements interface

2016-07-25 Thread Kagamin via Digitalmars-d-learn
Cast it to Object: FooInterface a = new BarImplementsInterface(); FooBaseClass b = new BarDerivedClass(); Object o = cast(Object)a; writefln("a class: %s", a.classinfo.name); writefln("b class: %s", b.classinfo.name); writefln("o class: %s",

Re: debug public release private

2016-07-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, July 25, 2016 04:58:55 Gorge Jingale via Digitalmars-d-learn wrote: > debug mixin("public"); else mixin("private"); > > Doesn't work. > > It's nice to have public members when debugging because they show > up in the debugger and one can access internals for checking. One > can enable

Getting most derived type of object that implements interface

2016-07-25 Thread cc via Digitalmars-d-learn
I'm having trouble getting the full name of an object of a class that implements an interface, using typeid() or .classinfo, the behavior seems to be different from that of a class that simply derives other classes. interface FooInterface {} class BarImplementsInterface : FooInterface {}

Re: JSON Serialization with runtime filtering.

2016-07-25 Thread Alexander Milushev via Digitalmars-d-learn
On Saturday, 23 July 2016 at 21:30:52 UTC, yawniek wrote: On Friday, 22 July 2016 at 12:36:31 UTC, Alexander Milushev wrote: I there any json serialization library which allow to make decision about ignoring fields in runtime? I trying to write rest client but server accept either 'cmd' or

Re: Transform/Compile to C/CPP as a target

2016-07-25 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 23 July 2016 at 12:27:24 UTC, ParticlePeter wrote: Is there any kind of project or workflow that converts D (subset) to C/CPP ? The short answer is no, not for any recent version of D.