How to return range constructs?

anonymous anonymous at example.com
Fri Feb 28 15:32:01 PST 2014


On Friday, 28 February 2014 at 23:06:24 UTC, Robin wrote:
> sorry for the double post but I can't find an edit button.

Don't worry, there is none. Replying to yourself is proper
etiquette around here.

> I have managed to write a custom ForwardRange based on your 
> code as I wished it to behave. However, the assertion fails on 
> compilation, now. The only thing I have changed is that I have 
> added a constructor as well as changing the type of T[] to 
> Matrix!T pointer type.
>
> The general layout stayed the same and I don't think that a 
> constructor may break the ForwardRange interface.
>
> Do you know what's wrong here?
>
> Here is the code:
> http://dpaste.dzfl.pl/8718b09cb825

Lines 43, 44:
---
static assert(isForwardRange!(ColumnVectorForwardRange!double(new
Matrix!double(5, 5), 2)));
//static assert(isForwardRange!(ColumnVectorForwardRange!double));
---
isForwardRange works on types, not values. The commented version
is correct.

> Besides that ... are there nicer workarounds to prevent using 
> matrix by value instead of storing it as a pointer which is 
> kind of unsafe?

Make it a class.


More information about the Digitalmars-d-learn mailing list