Thread overview |
---|
April 03, 2018 Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
wchar[10] buffer; toUTF8(buffer); Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713): `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))` I know buffer.idup is OK. But why? That's very inconvenient. |
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domain | On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote:
> wchar[10] buffer;
> toUTF8(buffer);
>
> Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are:
> /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713): `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))`
>
>
> I know buffer.idup is OK. But why? That's very inconvenient.
What you need to do is slice your buffer. So your call will become like this:
---
toUTF8(buffer[]);
---
Now it will work as expected.
|
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uknown | On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote:
> On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote:
>> wchar[10] buffer;
>> toUTF8(buffer);
>>
>> Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are:
>> /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713):
>> `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))`
>>
>>
>> I know buffer.idup is OK. But why? That's very inconvenient.
>
> What you need to do is slice your buffer. So your call will become like this:
>
> ---
> toUTF8(buffer[]);
> ---
>
> Now it will work as expected.
I should mention that you need to slice any static array when passing to functions that expect ranges
|
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uknown | On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote:
> On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote:
>> wchar[10] buffer;
>> toUTF8(buffer);
>>
>> Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are:
>> /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713):
>> `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))`
>>
>>
>> I know buffer.idup is OK. But why? That's very inconvenient.
>
> What you need to do is slice your buffer. So your call will become like this:
>
> ---
> toUTF8(buffer[]);
> ---
>
> Now it will work as expected.
I see. Maybe the error message could be improved.
|
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domain | On Tuesday, 3 April 2018 at 02:46:51 UTC, Domain wrote:
> On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote:
>> On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote:
>>> wchar[10] buffer;
>>> toUTF8(buffer);
>>>
>>> Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are:
>>> /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713):
>>> `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))`
>>>
>>>
>>> I know buffer.idup is OK. But why? That's very inconvenient.
>>
>> What you need to do is slice your buffer. So your call will become like this:
>>
>> ---
>> toUTF8(buffer[]);
>> ---
>>
>> Now it will work as expected.
>
> I see. Maybe the error message could be improved.
Well depends. The error message is correct and if you took a look at each constraint you'd understand it.
Once you understand that static arrays don't work with functions expecting ranges, then it kinda becomes common sense as to why it doesn't work.
|
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Domain | On Tuesday, 3 April 2018 at 02:46:51 UTC, Domain wrote: > On Tuesday, 3 April 2018 at 02:31:15 UTC, Uknown wrote: >> On Tuesday, 3 April 2018 at 02:24:08 UTC, Domain wrote: >>> wchar[10] buffer; >>> toUTF8(buffer); >>> >>> Error: template `std.utf.toUTF8` cannot deduce function from argument types `!()(wchar[10])`, candidates are: >>> /dlang/dmd/linux/bin64/../../src/phobos/std/utf.d(2713): >>> `std.utf.toUTF8(S)(S s) if (isInputRange!S && !isInfinite!S && isSomeChar!(ElementEncodingType!S))` >>> >>> >>> I know buffer.idup is OK. But why? That's very inconvenient. >> >> What you need to do is slice your buffer. So your call will become like this: >> >> --- >> toUTF8(buffer[]); >> --- >> >> Now it will work as expected. > > I see. Maybe the error message could be improved. Yep, I opened an enhancement request for you: https://issues.dlang.org/show_bug.cgi?id=18711 Better diagnostics and error messages is a key goal in 2018 for dmd ;-) |
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Tuesday, 3 April 2018 at 05:20:55 UTC, Seb wrote:
> Better diagnostics and error messages is a key goal in 2018 for dmd ;-)
Awesome! How about telling the user which of the template constraints failed? Would be so awesome. Currently, there's a need to check every single one (as mentioned by bauss) which can sometimes be a hassle.
|
April 03, 2018 Re: Why toUTF8 not accept wchar[] as argument? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Timoses | On Tuesday, 3 April 2018 at 13:12:05 UTC, Timoses wrote: > On Tuesday, 3 April 2018 at 05:20:55 UTC, Seb wrote: >> Better diagnostics and error messages is a key goal in 2018 for dmd ;-) > > Awesome! How about telling the user which of the template constraints failed? Would be so awesome. Currently, there's a need to check every single one (as mentioned by bauss) which can sometimes be a hassle. I guess related issues are: https://issues.dlang.org/show_bug.cgi?id=9626 https://issues.dlang.org/show_bug.cgi?id=4970 |
Copyright © 1999-2021 by the D Language Foundation