How to convert this function into a template ?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Oct 2 11:49:06 UTC 2018


On Tuesday, October 2, 2018 5:40:18 AM MDT Vinod K Chandran via Digitalmars-
d-learn wrote:
> Hi all,
> I have a function and i want to convert this into a template so
> that i can use this function for more than one data type.
> This is my function.
> ```D
> void ArrayAdd( ref int[] x, int value) {
>      int index = x.length ;
>      x.length += 1 ;
>      x[index] = value ;
> }
> ```

Why do you have a function for that? All you need to do is use the append
operator. e.g.

x ~= value;

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list