"in" everywhere

Stewart Gordon smjg_1998 at yahoo.com
Sat Oct 9 06:54:31 PDT 2010


On 07/10/2010 15:22, Steven Schveighoffer wrote:
<snip>
> The problem is with generic code. Generic code that accepts some type
> that defines the "in" operator. What can that generic code expect for
> performance when using "in"? As a general rule, generic programming must
> always assume the worst case, and if we have no rules for 'in', the
> worst case is linear. Which means generic code may not use 'in' when it
> would be a fast operation. Same thing with indexing. Try sorting a
> 'random access' range which uses a linear search on opIndex, and see
> what the performance is.
<snip>

Surely, what matters most for generic code is that in has consistent 
_semantics_, rather than the computational complexity?

Stewart.


More information about the Digitalmars-d mailing list