Re: Is it possible to return mutable and const range from a single method?

2022-08-22 Thread realhet via Digitalmars-d-learn
On Monday, 22 August 2022 at 19:35:11 UTC, Steven Schveighoffer wrote: It is possible to write the same function for both const and mutable overloads by using the `this` template parameter: I guess before the "inout", "this This" was the only way to do this. I must remember this, it's really

Re: Is it possible to return mutable and const range from a single method?

2022-08-22 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/22/22 12:36 PM, realhet wrote: Hello, I managed to make a universal getParent() function which can preserve constness. I also had success with inout functions that work with this inout getParent method. Is it possible to do something like this but for the allParents input range producer

Re: Is it possible to return mutable and const range from a single method?

2022-08-22 Thread Ali Çehreli via Digitalmars-d-learn
On 8/22/22 09:36, realhet wrote: > It gives the protection I was needed but is it possible to make this > prettier? > auto allParents(){ >struct ParentRange{ > A act; > @property bool empty() const{ return act is null; } > @property A front() { return

Is it possible to return mutable and const range from a single method?

2022-08-22 Thread realhet via Digitalmars-d-learn
Hello, I managed to make a universal getParent() function which can preserve constness. I also had success with inout functions that work with this inout getParent method. Is it possible to do something like this but for the allParents input range producer method? In the const range