The rfind challenge

monarch_dodra monarchdodra at gmail.com
Tue Jan 15 13:39:44 PST 2013


On Tuesday, 15 January 2013 at 21:24:19 UTC, H. S. Teoh wrote:
> On Tue, Jan 15, 2013 at 03:59:17PM -0500, Andrei Alexandrescu 
> wrote:
>> On 1/15/13 2:07 PM, Phil Lavoie wrote:
>> >Continuing with reversible ranges:
>> 
>> I don't think .reverse will take us far enough. Won't work with
>> arrays which kinda puts a monkey wrench into everything.
> [...]
>
> Not really. We can define an array wrapper with a .reverse that 
> returns
> the original array, something like:
>
> 	// In std.array
> 	auto reverse(R)(R array)
> 		if (is(R _ : E[], E)
> 	{
> 		static struct ReverseArray {
> 			R[] src;
>
> 			@property auto front() { return src[$-1]; }
> 			@property bool empty() { return src.empty; }
> 			@property void popFront() {
> 				src = src[0..$-1];
> 			}
> 			@property auto reverse() {
> 				return src;
> 			}
> 			... // other wrapper methods
> 		}
> 		return ReverseArray(array);
> 	}
>
> This will let you implement rfind in a way that returns the 
> original
> array.
>
>
> T

I'm having trouble understanding what you guys are going on 
about. Isn't this "reverse" just retro? And how would it solve 
anything, when retro doesn't?

I thought the point of "reverse" was that it preserved type, but 
this adapter doesn't do that...

Sorry for being dense, but I don't get it :/ I may have missed 
something earlier in the thread. Could you elaborate on the 
solution...?


More information about the Digitalmars-d mailing list