Re: Why code failed to compile for foo2?

2021-12-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 15:14:40 UTC, Steven Schveighoffer wrote: On 12/14/21 12:04 AM, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am I wrong

Re: Why code failed to compile for foo2?

2021-12-14 Thread Tejas via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 13:25:04 UTC, apz28 wrote: On Tuesday, 14 December 2021 at 05:04:46 UTC, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am

Re: Why code failed to compile for foo2?

2021-12-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/14/21 12:04 AM, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am I wrong in using `Unconst` over `Unqual`? Isn't `Unqual` overkill if you just want

Re: Why code failed to compile for foo2?

2021-12-14 Thread apz28 via Digitalmars-d-learn
On Tuesday, 14 December 2021 at 05:04:46 UTC, Tejas wrote: Is there anything wrong with the answer I posted? Can you please tell me if there's anything dissatisfactory about it? I feel like it does everything the OP wants. Also, am I wrong in using `Unconst` over `Unqual`? Isn't `Unqual`

Re: Why code failed to compile for foo2?

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Monday, 13 December 2021 at 20:43:51 UTC, Steven Schveighoffer wrote: On 12/11/21 10:02 PM, apz28 wrote: On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only

Re: Why code failed to compile for foo2?

2021-12-13 Thread apz28 via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:44:59 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway.

Re: Why code failed to compile for foo2?

2021-12-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/11/21 10:02 PM, apz28 wrote: On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be altered in body hence

Re: Why code failed to compile for foo2?

2021-12-13 Thread Tejas via Digitalmars-d-learn
On Sunday, 12 December 2021 at 03:02:28 UTC, apz28 wrote: On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be

Re: Why code failed to compile for foo2?

2021-12-11 Thread apz28 via Digitalmars-d-learn
On Sunday, 12 December 2021 at 00:02:25 UTC, Stanislav Blinov wrote: @apz28, I can't figure out the intent here. To convert result of abs to an unsigned? The function logic works only for unsigned type and the parameter value can be altered in body hence Unqual. If not Unqual, must declare a

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:44:59 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway.

Re: Why code failed to compile for foo2?

2021-12-11 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 11 December 2021 at 23:17:17 UTC, Stanislav Blinov wrote: ? No. If it was unsatisfied constraint, the error would've shown that. And if you try to instantiate it, you'll see it is an unsatisfied constraint anyway. There's two layers of failure here. Using Unqual there is pretty

Re: Why code failed to compile for foo2?

2021-12-11 Thread Stanislav Blinov via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:59:52 UTC, Adam Ruppe wrote: On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote: void foo2(T)(Unqual!T x) if(isUnsigned!T) {} This means it treats foo2 as if it doesn't exist unless T is unsigned... onlineapp.d(15): Error: template

Re: Why code failed to compile for foo2?

2021-12-11 Thread Adam Ruppe via Digitalmars-d-learn
On Saturday, 11 December 2021 at 22:50:45 UTC, apz28 wrote: void foo2(T)(Unqual!T x) if(isUnsigned!T) {} This means it treats foo2 as if it doesn't exist unless T is unsigned... onlineapp.d(15): Error: template `onlineapp.foo2` cannot deduce function from argument types `!()(int)`

Why code failed to compile for foo2?

2021-12-11 Thread apz28 via Digitalmars-d-learn
void foo1(ubyte x) {} void foo1(ushort x) {} void foo1(uint x) {} void foo1(ulong x) {} import std.traits : isUnsigned, Unqual; void foo2(T)(Unqual!T x) if(isUnsigned!T) {} void main() { import std.math; int s = 1; foo1(abs(s)); foo2(abs(s)); //failed?