Re: Type Parameter Deduction

2022-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 5/10/22 08:40, Salih Dincer wrote: > void inclusiveRange(T)(T Args...) if(is(T == bool)) { >assert(0, "\nBoolean type cannot be used!"); > } Of course, 'static assert' is better there because it will catch the issue at compile time. static assert(0, "\nBoolean type cannot be

Re: Type Parameter Deduction

2022-05-10 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 14:42:31 UTC, Ali Çehreli wrote: What would you like to see instead? [...] Here that is: ```d void inclusiveRange(T)(T Args...) if(is(T == bool)) { assert(0, "\nBoolean type cannot be used!"); }/* core.exception.AssertError@InclusiveRangev2.d(79): Boolean type

Re: Type Parameter Deduction

2022-05-10 Thread frame via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 13:14:20 UTC, Salih Dincer wrote: must satisfy the following constraint: That is your type protection here, a constraint. Alternatively you can put the constraint in a function and make it more verbose: ```d bool isAllowedType(T)() { static assert(!is(T ==

Re: Type Parameter Deduction

2022-05-10 Thread Ali Çehreli via Digitalmars-d-learn
On 5/10/22 06:14, Salih Dincer wrote: > Not compiled, the compiler returns: What would you like to see instead? The compiler can reject code only by "not compiling". :) >> InclusiveRange.d(48): Error: template instance >> `InclusiveRange.ir!bool` does not match > template declaration >>

Re: Type Parameter Deduction

2022-05-10 Thread Salih Dincer via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 12:56:50 UTC, frame wrote: On Tuesday, 10 May 2022 at 09:26:46 UTC, Salih Dincer wrote: However, the compiler catches other errors! How can I solve this problem? Thanks... SDB@79 What about something like this? ```d auto inclusiveRange(T = int)(T f = T(0), T l

Re: Type Parameter Deduction

2022-05-10 Thread frame via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 09:26:46 UTC, Salih Dincer wrote: However, the compiler catches other errors! How can I solve this problem? Thanks... SDB@79 What about something like this? ```d auto inclusiveRange(T = int)(T f = T(0), T l = T(0), T s = T(1)) if(!is(T == bool)) { //... }