Re: How make Optional pre determined parameter type without overload function?

2020-12-02 Thread Marcone via Digitalmars-d-learn
Now my slice works fine. // Tipo Nulo. class None {} // Função slice() auto slice(T1, T2, T3 = None)(T1 conteudo, T2 inicio, T3 fim = T3.init) { int start, end, startlen; static if (is(T2 == int)) {inicio = inicio < 0 ? conteudo.length + inicio : inicio;} static if (is(T3 == int))

Re: How make Optional pre determined parameter type without overload function?

2020-11-28 Thread Marcone via Digitalmars-d-learn
On Sunday, 29 November 2020 at 02:55:02 UTC, Ali Çehreli wrote: On 11/28/20 6:40 PM, Marcone wrote: void a(T1, T2)(T1 b, T2 c){ // I need parameter "c" optional, but only (String or int). How can I make it without overload function? } Since it's optional, T2 must have a default type. I

Re: How make Optional pre determined parameter type without overload function?

2020-11-28 Thread Ali Çehreli via Digitalmars-d-learn
On 11/28/20 6:40 PM, Marcone wrote: void a(T1, T2)(T1 b, T2 c){ // I need parameter "c" optional, but only (String or int). How can I make it without overload function? } Since it's optional, T2 must have a default type. I made it 'int' below. void a(T1, T2 = int)(T1 b, T2 c = T2.init)