proper range usage

Alex via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 2 23:59:53 PST 2015


Hi everybody,

first of all: this question is going to be unclear, because I'm 
lack of the "buzz word" I would like to ask about, sorry for this 
in advance.

I try to describe the problem, where I stuck and hope somebody 
could think just a step further. Just a hint where to read about 
the way of solution would be enough, I think.

Starting with chapter 73 in the recent "Programming in D" book 
(the revision of 2015-10-24), about "foreach with structs and 
classes" I would like to implement either the opAssign method or 
the three range member functions in a simple struct.
Let's say, the example of NumberRange struct in the example on 
page 486 is enough. In terms of .front(), .popFront() and .empty: 
I understand what the first two things do, but I have a problem 
with the empty property:

In my case, the container class can't become empty. Even if it 
contains one single element, in this case the example should 
return true for begin == end, it is not empty. At the same time, 
my container is surely always finite, so I can't define the empty 
property to false as shown on page 568, last line.

A further problem/wish is: I don't want to store my elements 
explicitly as members. So taking the simplest example on page 486 
has a further meaning for me: It does not contain an array as 
member and it is not meant to.

So far from me. I hope, I could describe my problem good enough 
and I hope somebody could help me out. Still, the solution is 
important, but I also would like to know what a weird thing I'm 
describing in terms of... well... some structure... not to say 
pattern :)

Thanks in advance
Alex


More information about the Digitalmars-d-learn mailing list