Re: Passing functions as template parameter and assigning default values to them

2015-06-21 Thread kerdemdemir via Digitalmars-d-learn
On Sunday, 21 June 2015 at 10:06:15 UTC, biozic wrote: You can use a template alias parameter with a default value that is your default lambda: int indexOfMax(alias fun = a => a, R)(R range) { // Use `fun` here like a function. } -- Nico Thanks a lot, it works !!

Re: Passing functions as template parameter and assigning default values to them

2015-06-21 Thread biozic via Digitalmars-d-learn
On Sunday, 21 June 2015 at 09:34:51 UTC, kerdemdemir wrote: Hi, I need to find the index of maximum element so my code: int indexOfMax(R)(R range) { alias Type = typeof(range.front().re); > I don't like .re here Type max = 0; size_t maxIndex = 0; foreach ( index,el

Passing functions as template parameter and assigning default values to them

2015-06-21 Thread kerdemdemir via Digitalmars-d-learn
Hi, I need to find the index of maximum element so my code: int indexOfMax(R)(R range) { alias Type = typeof(range.front().re); > I don't like .re here Type max = 0; size_t maxIndex = 0; foreach ( index,elem; range ) { if ( elem.re > max )-> And