Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 17:37:58 UTC, Ali Çehreli wrote: On 10/02/2018 07:39 AM, Vinod K Chandran wrote: > Thanks a lot. Great help !. I will sure the check the link. :) I find the Index section useful (yes, can be improved). For example, just seach for "append" on this page:

Re: How to convert this function into a template ?

2018-10-02 Thread Ali Çehreli via Digitalmars-d-learn
On 10/02/2018 07:39 AM, Vinod K Chandran wrote: > Thanks a lot. Great help !. I will sure the check the link. :) I find the Index section useful (yes, can be improved). For example, just seach for "append" on this page: http://ddili.org/ders/d.en/ix.html > The doumentation did not tell me

Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 12:23:47 UTC, Jonathan M Davis wrote: The template equivalent would have been something like void arrayAdd(T)(ref T[] x, T value) { auto index = x.length; x.length += 1; x[index] = value; } But if you're new to the language, I'd suggest that you read

Re: How to convert this function into a template ?

2018-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 2, 2018 6:09:53 AM MDT Vinod K Chandran via Digitalmars- d-learn wrote: > On Tuesday, 2 October 2018 at 11:49:06 UTC, Jonathan M Davis > > wrote: > > Why do you have a function for that? All you need to do is use > > the append operator. e.g. > > > > x ~= value; > > > > -

Re: How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
On Tuesday, 2 October 2018 at 11:49:06 UTC, Jonathan M Davis wrote: 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 Thanks for the reply. I did not find that it in documentation. Ofcourse i lost a chance to learn

Re: How to convert this function into a template ?

2018-10-02 Thread Jonathan M Davis via Digitalmars-d-learn
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)

How to convert this function into a template ?

2018-10-02 Thread Vinod K Chandran via Digitalmars-d-learn
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 ; } ```