Why function template 'among' is of complexity O(1) and not O(n)?

Jakob Ovrum jakobovrum at gmail.com
Wed Feb 19 13:57:01 PST 2014


On Wednesday, 19 February 2014 at 21:52:06 UTC, anonymous wrote:
> Nope. v and vals are runtime parameters, their values are not
> known at compile time. What's known at compile time is
> vals.length.

While this is correct, note that there is also an overload that 
takes `values` as compile-time parameters, generating a switch 
statement, which is especially interesting because the switch 
statement is a good opportunity for the compiler to optimise.


More information about the Digitalmars-d-learn mailing list