Thread overview
Re: Boy, std.bitmanip.bigEndianToNative is annoying to use
May 22, 2015
H. S. Teoh
May 22, 2015
H. S. Teoh
May 22, 2015
Jonathan M Davis
May 22, 2015
Kagamin
May 22, 2015
Kagamin
May 22, 2015
Jonathan M Davis
May 23, 2015
Kagamin
May 23, 2015
H. S. Teoh
May 23, 2015
Rikki Cattermole
May 22, 2015
On Fri, May 22, 2015 at 07:21:40PM +0000, Jonathan M Davis via Digitalmars-d wrote: [...]
> Isn't the problem that you're trying to convert to a ushort, and a ushort is _2_ bytes, not 4? If you sliced it correctly, it would compile. For instance, this code compiles just fine for me with dmd master:
> 
> void main()
> {
>     import std.bitmanip;
>     auto buf = new ubyte[](32);
>     auto result = bigEndianToNative!ushort(buf[0 .. 2]);
> }
> 
> But if I change it to buf[0 .. 4], then it fails to compile. So, the fact that bigEndianToNative is taking a static array is actually catching a bug for you.
[...]

	face.palm();
	head.hang!inShame();
	self.crawlBackTo(hole);


T

-- 
Perhaps the most widespread illusion is that if we were in power we would behave very differently from those who now hold it---when, in truth, in order to get power we would have to become very much like them. -- Unknown
May 22, 2015
On Fri, May 22, 2015 at 12:39:12PM -0700, H. S. Teoh via Digitalmars-d wrote: [...]
> 	face.palm();
> 	head.hang!inShame();
> 	self.crawlBackTo(hole);
[...]

Truth be told, though, the error message was very unhelpful about it. It just says no templates were matched, no indication about the fact that the problem was caused by mismatched type lengths.


T

-- 
Verbing weirds language. -- Calvin (& Hobbes)
May 22, 2015
On Friday, 22 May 2015 at 19:44:59 UTC, H. S. Teoh wrote:
> On Fri, May 22, 2015 at 12:39:12PM -0700, H. S. Teoh via Digitalmars-d wrote:
> [...]
>> 	face.palm();
>> 	head.hang!inShame();
>> 	self.crawlBackTo(hole);
> [...]
>
> Truth be told, though, the error message was very unhelpful about it. It
> just says no templates were matched, no indication about the fact that
> the problem was caused by mismatched type lengths.

Well, I'm not sure how we could fix that. That's a general problem with template constraints. You know that they aren't passing, but you don't know _why_ they aren't passing. Though maybe in this case, the docs could be improved to make it clearer that if you're getting compilation errors, there's a decent chance that you got the type sizes wrong.

- Jonathan M Davis
May 22, 2015
On 5/22/15 12:48 PM, Jonathan M Davis wrote:
> On Friday, 22 May 2015 at 19:44:59 UTC, H. S. Teoh wrote:
>> On Fri, May 22, 2015 at 12:39:12PM -0700, H. S. Teoh via Digitalmars-d
>> wrote:
>> [...]
>>>     face.palm();
>>>     head.hang!inShame();
>>>     self.crawlBackTo(hole);
>> [...]
>>
>> Truth be told, though, the error message was very unhelpful about it. It
>> just says no templates were matched, no indication about the fact that
>> the problem was caused by mismatched type lengths.
>
> Well, I'm not sure how we could fix that. That's a general problem with
> template constraints. You know that they aren't passing, but you don't
> know _why_ they aren't passing. Though maybe in this case, the docs
> could be improved to make it clearer that if you're getting compilation
> errors, there's a decent chance that you got the type sizes wrong.

Yah, improving the documentation has maximum impact here. Navigating to github.com/pulls?user=D-Programming-Language... F5... F5... F5... F5... -- Andrei

May 22, 2015
On Friday, 22 May 2015 at 19:48:21 UTC, Jonathan M Davis wrote:
> Well, I'm not sure how we could fix that.

Remove filter n == T.sizeof ?
May 22, 2015
Hmm, now that I look at it, the declaration of bigEndianToNative is weird: http://dpaste.dzfl.pl/6fad7c9ef22d
May 22, 2015
On Friday, 22 May 2015 at 20:21:59 UTC, Kagamin wrote:
> Hmm, now that I look at it, the declaration of bigEndianToNative is weird: http://dpaste.dzfl.pl/6fad7c9ef22d

What's weird about it?

- Jonathan M Davis
May 23, 2015
On 23/05/2015 7:48 a.m., Jonathan M Davis wrote:
> On Friday, 22 May 2015 at 19:44:59 UTC, H. S. Teoh wrote:
>> On Fri, May 22, 2015 at 12:39:12PM -0700, H. S. Teoh via Digitalmars-d
>> wrote:
>> [...]
>>>     face.palm();
>>>     head.hang!inShame();
>>>     self.crawlBackTo(hole);
>> [...]
>>
>> Truth be told, though, the error message was very unhelpful about it. It
>> just says no templates were matched, no indication about the fact that
>> the problem was caused by mismatched type lengths.
>
> Well, I'm not sure how we could fix that. That's a general problem with
> template constraints. You know that they aren't passing, but you don't
> know _why_ they aren't passing. Though maybe in this case, the docs
> could be improved to make it clearer that if you're getting compilation
> errors, there's a decent chance that you got the type sizes wrong.
>
> - Jonathan M Davis


template X(T, string v) if (is(T == class) && v.length == 2) {

} else {
	pragma(msg, "X must have two template arguments, where the first is a class symbol and the second is a string with a length of two characters.");
}

Or

template X() if (false) {
	pragma(msg, "X must have two template arguments, where the first is a class symbol and the second is a string with a length of two characters.");
}

Humm, the first would be abused a lot. The second would be highly limiting. The first, but all overloads must be in the style of if, else template, else. But how to limit it to one name..

Anyway just some random thoughts.
May 23, 2015
On Friday, 22 May 2015 at 21:03:43 UTC, Jonathan M Davis wrote:
> On Friday, 22 May 2015 at 20:21:59 UTC, Kagamin wrote:
>> Hmm, now that I look at it, the declaration of bigEndianToNative is weird: http://dpaste.dzfl.pl/6fad7c9ef22d
>
> What's weird about it?

Why it has a separate n parameter? It makes no sense. If it was like in the paste, it would give proper error message.
May 23, 2015
On Sat, May 23, 2015 at 09:54:35AM +0000, Kagamin via Digitalmars-d wrote:
> On Friday, 22 May 2015 at 21:03:43 UTC, Jonathan M Davis wrote:
> >On Friday, 22 May 2015 at 20:21:59 UTC, Kagamin wrote:
> >>Hmm, now that I look at it, the declaration of bigEndianToNative is weird: http://dpaste.dzfl.pl/6fad7c9ef22d
> >
> >What's weird about it?
> 
> Why it has a separate n parameter? It makes no sense. If it was like in the paste, it would give proper error message.

Submit a PR?


T

-- 
MAS = Mana Ada Sistem?