Is there a standard for whar opAssign/opOpAssign should return?

2016-03-06 Thread HSteffenhagen via Digitalmars-d-learn

In the https://dlang.org/spec/operatoroverloading.html opAssign
is declared as

void opAssign(S rhs);

in the example.

From C++ I'm used to return *this when overloading assignment 
operators to allow chaining of assignments (or somewhat more 
rarely, weird tricks for if and while statements), is that not 
done in D as a rule or is the example just weird? Same question 
for the

opOpAssign family.




Re: std.range: Lockstep vs. Zip

2016-03-02 Thread HSteffenhagen via Digitalmars-d-learn

On Wednesday, 2 March 2016 at 08:51:07 UTC, Manuel Maier wrote:

Hi there,

I was wondering why I should ever prefer std.range.lockstep 
over std.range.zip. In my (very limited) tests std.range.zip 
offered the same functionality as std.range.lockstep, i.e. I 
was able to iterate using `foreach(key, value; 
std.range.zip(...)) {}` which, according to the docs, is what 
std.range.lockstep was supposed to be designed for. On top of 
that, std.range.zip is capable of producing a 
RandomAccessRange, but std.range.lockstep only produces 
something with opApply.


Cheers


I'm not entirely sure, but I get the impression lockstep is a 
special case of zip. I suspect if you don't need anything zip 
offers over lockstep (mutability, random access) you won't gain 
anything from using it.


I'm usually using zip in this circumstance, but if all you're 
doing is iterating there doesn't seem to be a reason to not use 
lockstep.