nogc Array

Igor via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 25 21:53:29 PST 2016


On Tuesday, 26 January 2016 at 04:38:13 UTC, Adam D. Ruppe wrote:
> On Tuesday, 26 January 2016 at 04:31:07 UTC, Igor wrote:
>> then std.algorithm.find!("a.myInt == b")(classes, 3)
>
> Try
>
> std.algorithm.find!("a.myInt == b")(classes[], 3)
>
> notice the [] after classes
>
>
>> I guess std.container.array isn't a range? Or am I using it 
>> wrong?
>
> Containers aren't really ranges, they instead *offer* ranges 
> that iterate over them. Built in arrays are a bit special in 
> that they do this implicitly so the line is more blurred there, 
> but it is a general rule that you need to get a range out of a 
> container.
>
> Otherwise, consider that iterating over it with popFront would 
> result in the container being automatically emptied and not 
> reusable!

Ok, does the [] do any conversion or any thing I don't want or 
does it just make the template know we are working over an array?

Are there any performance issues? I am already using a for loop 
to find the type, it's 6 lines of code. I was hoping to get that 
down to one or 2 and make it a bit easier to understand.

	App app = null;
	for(int i = 0; i < Apps.length(); i++)
		if ((Apps[i] !is null) && (Apps[i].hWnd == hWnd))
		{
			app = Apps[i];
			break;
		}

versus

find!("a.hWnd == b")(Apps[], hWnd);

Does [] take time to convert to a built in a array or range or 
whatever or will it be just as fast as the above code?




More information about the Digitalmars-d-learn mailing list