Is InputRange intentionally more restrictive than isInputRange?

2018-12-22 Thread balddenimhero via Digitalmars-d-learn
I recently required a function to return an input range over some 
base element type E. I was under the impression that this is 
exactly what the interfaces in std.range.interface are for but 
found that these are more restrictive than the checks from 
std.range.primitives.


In particular, isInputRange(R) only requires R to implement 
front, empty and popFront, while InputRange!E requires moveFront 
and opApply in addition. To me this was unexpected and seems 
inconsistent, but maybe there's a good reason for that.


Can someone explain whether (and why) this is intentional.


Re: BinaryHeap as member

2017-11-14 Thread balddenimhero via Digitalmars-d-learn

On Tuesday, 14 November 2017 at 04:13:16 UTC, Era Scarecrow wrote:
On Monday, 13 November 2017 at 16:26:20 UTC, balddenimhero 
wrote:
In the course of writing a minimal example I removed more than 
necessary in the previous pastebin (the passed IntOrder has 
not even been used). Thus here is the corrected one: 
https://pastebin.com/SKae08GT. I'm trying to port this to D.


 Throwing together a sample involves wrapping the value in a 
new value. Still the idea is put across...


 Not sure if this is the best way to do this, but only takes a 
little dereferencing to access the value.


Thanks for actually implementing the workaround you suggested on 
the IRC for my minmal example. I'm using this for now as it seems 
that using delegates as predicates is problematic in my use case.


It still feels kind of dirty though, and maybe I'll eventually 
just implement a standard min-heap that is templated with a 
comparator (as in C++).


Re: BinaryHeap as member

2017-11-13 Thread balddenimhero via Digitalmars-d-learn

On Monday, 13 November 2017 at 15:43:35 UTC, balddenimhero wrote:
On Monday, 13 November 2017 at 14:38:35 UTC, balddenimhero 
wrote:
I need a priority queue of integers whose elements are not 
ordered by the default `opCmp` but some delegate.


The following gist illustrates the problem I'm having:
https://run.dlang.io/gist/92876b2c4d8c77cdc68f1ca61e7e8e44?compiler=dmd

The `Foo` class is supposed to wrap a binary heap (to be used 
as priority queue) and order its contents according to 
`o.isLess`. However I do not manage to initialise the 
according member variable.


Obviously, with the `h` member having type `BinaryHeap(int[], 
"a

Re: BinaryHeap as member

2017-11-13 Thread balddenimhero via Digitalmars-d-learn

On Monday, 13 November 2017 at 14:38:35 UTC, balddenimhero wrote:
I need a priority queue of integers whose elements are not 
ordered by the default `opCmp` but some delegate.


The following gist illustrates the problem I'm having:
https://run.dlang.io/gist/92876b2c4d8c77cdc68f1ca61e7e8e44?compiler=dmd

The `Foo` class is supposed to wrap a binary heap (to be used 
as priority queue) and order its contents according to 
`o.isLess`. However I do not manage to initialise the according 
member variable.


Obviously, with the `h` member having type `BinaryHeap(int[], 
"a

BinaryHeap as member

2017-11-13 Thread balddenimhero via Digitalmars-d-learn
I need a priority queue of integers whose elements are not 
ordered by the default `opCmp` but some delegate.


The following gist illustrates the problem I'm having:
https://run.dlang.io/gist/92876b2c4d8c77cdc68f1ca61e7e8e44?compiler=dmd

The `Foo` class is supposed to wrap a binary heap (to be used as 
priority queue) and order its contents according to `o.isLess`. 
However I do not manage to initialise the according member 
variable.


Obviously, with the `h` member having type `BinaryHeap(int[], 
"a