Function with static array as parameter

Rene Zwanenburg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 12 05:59:50 PDT 2017


On Wednesday, 12 July 2017 at 12:57:19 UTC, Rene Zwanenburg wrote:
> On Wednesday, 12 July 2017 at 12:20:11 UTC, Miguel L wrote:
>> What is the best way in D to create a function that receives a 
>> static array of any length?
>
> Templatize the array length:
>
> void foo(size_t length)(int[length] arr)
> {
>
> }

That being said, this may lead to template bloat and excessive 
copying. What are you trying to do? Is there a reason you can't 
use a slice?


More information about the Digitalmars-d-learn mailing list