Re: std.bitmanip help - how to combine bitfields and read

2020-03-11 Thread kookman via Digitalmars-d-learn
; uint ackNo; mixin(bitfields!( bool, "flagFin", 1, bool, "flagSyn", 1, bool, "flagRst", 1, bool, "flagPsh", 1, bool, "flagAck", 1, bool, "flagUrg", 1, bool, "fl

std.bitmanip help - how to combine bitfields and read

2020-03-10 Thread kookman via Digitalmars-d-learn
I am using libpcap to read from stored pcap files, and want to use std.bitmanip.bitfields to read TCP flags from the file, using a struct like: struct TcpHeader { align(1): ushort srcPort; ushort dstPort; uint seqNo; uint ackNo; mixin(bitfields!( bool, "fl

Re: Bitfields

2019-05-22 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 22 May 2019 at 08:54:45 UTC, Russel Winder wrote: On Tue, 2019-05-21 at 19:14 +, Era Scarecrow via Digitalmars-d-learn wrote: […] I worked on/with bitfields in the past, the limit sizes is more or less for natural int types that D supports. Rust bitfield crate and it's

Re: Bitfields

2019-05-22 Thread Russel Winder via Digitalmars-d-learn
On Tue, 2019-05-21 at 19:14 +, Era Scarecrow via Digitalmars-d-learn wrote: > […] > I worked on/with bitfields in the past, the limit sizes is more > or less for natural int types that D supports. Rust bitfield crate and it's macros are the same, the underlying type for a bitf

Re: Bitfields

2019-05-22 Thread Russel Winder via Digitalmars-d-learn
/std_bitmanip.html#.peek I'll have to mull that one over. The incoming data is a sequence of bytes that is treated as a bitfield. Although the standard says "big-endian" it is isn't entirely clear how this relates to the bitfields, I guess I need to read the standard more. :-( I guess the

Re: Bitfields

2019-05-21 Thread Era Scarecrow via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: As far as I can see std.bitmanip only caters for 8, 16, 32, and 64 bit long bitfields. I worked on/with bitfields in the past, the limit sizes is more or less for natural int types that D supports. However this limitation

Re: Bitfields

2019-05-21 Thread Boris-Barboris via Digitalmars-d-learn
On Tuesday, 21 May 2019 at 17:16:05 UTC, Russel Winder wrote: Hi, Has anyone used D to work with arbitrary length bitfields with multiple occurences of a sub-bitfield. I am working with DVB Sections and EIT packets are defined as bitfields with loops in them and the header is 112 bits

Bitfields

2019-05-21 Thread Russel Winder via Digitalmars-d-learn
Hi, Has anyone used D to work with arbitrary length bitfields with multiple occurences of a sub-bitfield. I am working with DVB Sections and EIT packets are defined as bitfields with loops in them and the header is 112 bits. The loops are handleable with subfields obviously, assuming you can work

Re: question about bitfields to decode websocket header

2018-11-07 Thread test via Digitalmars-d-learn
On Wednesday, 7 November 2018 at 14:22:43 UTC, lithium iodate wrote: On Wednesday, 7 November 2018 at 13:05:49 UTC, test wrote: I am confused about the bitfields order. The bitfields start with the least significant bits: fin -> 1 rsv1 -> 0 rsv2 -> 0 rsv3 -> 0 opcode -> 1000

Re: question about bitfields to decode websocket header

2018-11-07 Thread lithium iodate via Digitalmars-d-learn
On Wednesday, 7 November 2018 at 13:05:49 UTC, test wrote: I am confused about the bitfields order. mixin(bitfields!( bool, "fin",1, bool, "rsv1", 1, bool, "rsv2", 1, bool, "rsv3",

question about bitfields to decode websocket header

2018-11-07 Thread test via Digitalmars-d-learn
I am confused about the bitfields order. mixin(bitfields!( bool, "fin",1, bool, "rsv1", 1, bool, "rsv2", 1, bool, "rsv3", 1, Opcode, "opcode", 4,

bitfields comparison in opEquals

2018-04-26 Thread Per Nordlöw via Digitalmars-d-learn
I have a struct with a mixin(bitfields) containing many small bitfields. I also have a class member in the struct. And because I want the class member to compare by using `is` I need to define bool opEquals(const scope typeof(this) that) const @safe pure nothrow @nogc

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-22 Thread Jacob Carlborg via Digitalmars-d-learn
On Thursday, 22 March 2018 at 09:55:44 UTC, Russel Winder wrote: I am guessing you mean against DStep rather than D :-) Yes :) Though clearly T and I would prefer version not to be a D keyword. I suspect I have seen one place where DStep has turned version into version_ where version was

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-22 Thread Kagamin via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 19:41:39 UTC, H. S. Teoh wrote: version(all) { ... } version(none) { ... } version(Posix) { ... } version(Windows) { ... } But yeah, using "version" for this purpose makes the very common identifier "version" unavailable for use.

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-22 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2018-03-21 at 22:18 +0100, Jacob Carlborg via Digitalmars-d-learn wrote: > On 2018-03-21 20:30, Russel Winder wrote: > > > Thanks to Adam and Ali, it was clear and obvious. > > Please report and issue so it's not forgotten. I am guessing you mean against DStep rather than D :-) Though

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread Jacob Carlborg via Digitalmars-d-learn
On 2018-03-21 20:30, Russel Winder wrote: Thanks to Adam and Ali, it was clear and obvious. Please report and issue so it's not forgotten. -- /Jacob Carlborg

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Mar 21, 2018 at 07:30:28PM +, Russel Winder via Digitalmars-d-learn wrote: [...] > But :-( > > Why does version have to be a keyword? [...] version(all) { ... } version(none) { ... } version(Posix) { ... } version(Windows) { ... } But yeah, using

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread Russel Winder via Digitalmars-d-learn
On Wed, 2018-03-21 at 18:11 +, Adam D. Ruppe via Digitalmars-d- learn wrote: > On Wednesday, 21 March 2018 at 18:00:38 UTC, Russel Winder wrote: > > ubyte, "version", 5, > > > version is a D keyword, so I would suggest trying "version_" > there instead and see if it works. (I'm

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread Ali Çehreli via Digitalmars-d-learn
On 03/21/2018 11:00 AM, Russel Winder wrote: > The code I am playing with generated by DStep involves lots of lots of > structs with mixin bitfields. All of them seem to compile file, except > one. How is it that: > > mixin(bitfields!( > ubyte, "current_nex

Re: OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 21 March 2018 at 18:00:38 UTC, Russel Winder wrote: ubyte, "version", 5, version is a D keyword, so I would suggest trying "version_" there instead and see if it works. (I'm guessing btw, the error message was way to long and illegible, but this is an easy first guess

OK, I'm stumped on this one: dstep, struct, mixin, bitfields

2018-03-21 Thread Russel Winder via Digitalmars-d-learn
The code I am playing with generated by DStep involves lots of lots of structs with mixin bitfields. All of them seem to compile file, except one. How is it that: mixin(bitfields!( ubyte, "current_next", 1, ubyte, "version", 5, ubyte, "one

Re: iterating through members of bitfields

2017-01-21 Thread Nestor via Digitalmars-d-learn
Thank you both!

Re: iterating through members of bitfields

2017-01-20 Thread Ali Çehreli via Digitalmars-d-learn
On 01/19/2017 05:21 PM, Nestor wrote: On Wednesday, 18 January 2017 at 12:52:56 UTC, drug wrote: I've "solved" the same problem by using AliasSeq to generate bitfields so that for iterating over bitfields I can iterate over alias sequence and mixin code. Not very good bu

Re: iterating through members of bitfields

2017-01-20 Thread drug via Digitalmars-d-learn
20.01.2017 15:04, Nestor пишет: Where does one define the size for a field using AliasSeq, and in this example, why does it take 1 bit if the size is not declared anywhere? Something like that https://goo.gl/zV8T23

Re: iterating through members of bitfields

2017-01-20 Thread drug via Digitalmars-d-learn
(Fields...) { import std.bitmanip : bitfields; mixin(makeBitfields!Fields); // <-- Fields instead of UAP } ``` Where does one define the size for a field using AliasSeq, and in this example, why does it take 1 bit if the size is not declared anywhere? I have fie

Re: iterating through members of bitfields

2017-01-20 Thread Nestor via Digitalmars-d-learn
On Friday, 20 January 2017 at 08:13:08 UTC, drug wrote: Something like that https://goo.gl/C4nOqw Because you generate code iterating over AliasSeq you can do almost everything you need - for example generate setters/getters. Interesting site, I wouldn't implemente something like this in a

Re: iterating through members of bitfields

2017-01-20 Thread drug via Digitalmars-d-learn
20.01.2017 04:21, Nestor пишет: On Wednesday, 18 January 2017 at 12:52:56 UTC, drug wrote: I've "solved" the same problem by using AliasSeq to generate bitfields so that for iterating over bitfields I can iterate over alias sequence and mixin code. Not very good but it works. I

Re: iterating through members of bitfields

2017-01-19 Thread Nestor via Digitalmars-d-learn
On Wednesday, 18 January 2017 at 12:52:56 UTC, drug wrote: I've "solved" the same problem by using AliasSeq to generate bitfields so that for iterating over bitfields I can iterate over alias sequence and mixin code. Not very good but it works. Interesting, could you provide a working example?

Re: iterating through members of bitfields

2017-01-18 Thread drug via Digitalmars-d-learn
I've "solved" the same problem by using AliasSeq to generate bitfields so that for iterating over bitfields I can iterate over alias sequence and mixin code. Not very good but it works.

Re: iterating through members of bitfields

2017-01-18 Thread Nestor via Digitalmars-d-learn
; writeln("Please improve this function by parsing fieldImpl. :)"); } }; } struct S { enum myFields = bitfields!(int, "a", 24, byte, "b", 8); pragma(msg, "This is the mixed-in bit field code\n

Re: iterating through members of bitfields

2017-01-17 Thread Ali Çehreli via Digitalmars-d-learn
; if (max < temp) max = temp; } max += 1; foreach (index, value; values) { writefln("%-" ~ to!string(max) ~ "s %s", T.tupleof[index].stringof, value); } } Can something similar be done for bitfields? I tried running this and I only get something like this:

iterating through members of bitfields

2017-01-17 Thread Nestor via Digitalmars-d-learn
emp; } max += 1; foreach (index, value; values) { writefln("%-" ~ to!string(max) ~ "s %s", T.tupleof[index].stringof, value); } } Can something similar be done for bitfields? I tried running this and I only get something like this: _f01_f02_f03 25312 _f04_f05_f06_

Re: BitArray/BitFields - Review

2014-08-06 Thread Era Scarecrow via Digitalmars-d-learn
(Moved from: What have I missed?) If this is the wrong place to ask these questions I apologize, getting back into this takes some work. So I guess I need to ask: Should I try to resume work on the BitManip library? (So far it seems none of my code has been integrated to phobos)

Re: BitArray/BitFields - Review

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 01:10:06AM +, Era Scarecrow via Digitalmars-d-learn wrote: (Moved from: What have I missed?) If this is the wrong place to ask these questions I apologize, getting back into this takes some work. Since this is about contributing to Phobos, probably a better

Re: BitArray/BitFields - Review

2014-08-06 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. Yeah posted in my 'what have i missed?' as well... Do you have a pull request? Which one is it?

Re: BitArray/BitFields - Review

2014-08-06 Thread Era Scarecrow via Digitalmars-d-learn
into a single request i think... Looks like that pull is just the bitfields... but the actual bitmanip one i listed has the whole source.

Re: BitArray/BitFields - Review

2014-08-06 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Aug 07, 2014 at 02:04:12AM +, Era Scarecrow via Digitalmars-d-learn wrote: On Thursday, 7 August 2014 at 01:51:46 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Since this is about contributing to Phobos, probably a better place to ask is on the main D forum. Yeah posted in my

Re: BitArray/BitFields - Review

2014-08-06 Thread Era Scarecrow via Digitalmars-d-learn
On Thursday, 7 August 2014 at 02:12:20 UTC, H. S. Teoh via Digitalmars-d-learn wrote: Hold on a sec... that's a pull for your own fork of Phobos. You need to submit a pull to the main Phobos repo in order to get it reviewed and merged. :-) Well, no wonder, your pull was submitted against

Re: BitArray/BitFields - Resumed and polishing

2013-01-06 Thread Era Scarecrow
On Thursday, 3 January 2013 at 21:45:24 UTC, Era Scarecrow wrote: K, I'll likely re-work my multi-level huffman algorithmn and a LZW compression, although the LZW wouldn't make use of the more exotic features. Got half the LZW written, but I likely won't get this done for a few days. Nearly

Re: BitArray/BitFields - Resumed and polishing

2013-01-06 Thread Dmitry Olshansky
07-Jan-2013 00:51, Era Scarecrow пишет: On Thursday, 3 January 2013 at 21:45:24 UTC, Era Scarecrow wrote: K, I'll likely re-work my multi-level huffman algorithmn and a LZW compression, although the LZW wouldn't make use of the more exotic features. Got half the LZW written, but I likely won't

Re: BitArray/BitFields - Resumed and polishing

2013-01-03 Thread Era Scarecrow
On Thursday, 3 January 2013 at 07:57:46 UTC, Dmitry Olshansky wrote: 1/3/2013 6:05 AM, Era Scarecrow wrote: Hm, I'd think that having Slice type be: BitArraySlice{ BitArray* bp; size_t start, end; // all else forwards to the pointed array } should work avoiding the most of code duplication.

Re: BitArray/BitFields - Resumed and polishing

2013-01-03 Thread Dmitry Olshansky
1/3/2013 2:20 PM, Era Scarecrow пишет: On Thursday, 3 January 2013 at 07:57:46 UTC, Dmitry Olshansky wrote: 1/3/2013 6:05 AM, Era Scarecrow wrote: Hm, I'd think that having Slice type be: BitArraySlice{ BitArray* bp; size_t start, end; // all else forwards to the pointed array } should work

Re: BitArray/BitFields - Resumed and polishing

2013-01-03 Thread Era Scarecrow
On Thursday, 3 January 2013 at 15:48:50 UTC, Dmitry Olshansky wrote: 1/3/2013 2:20 PM, Era Scarecrow wrote: Suddenly it won't work and slicing is only a range and can only be used in foreach. No surprise here. Basically container != range over it. It all flows from there. Range doesn't have

Re: BitArray/BitFields - Resumed and polishing

2013-01-03 Thread Dmitry Olshansky
04-Jan-2013 00:11, Era Scarecrow пишет: On Thursday, 3 January 2013 at 15:48:50 UTC, Dmitry Olshansky wrote: 1/3/2013 2:20 PM, Era Scarecrow wrote: Suddenly it won't work and slicing is only a range and can only be used in foreach. No surprise here. Basically container != range over it. It

Re: BitArray/BitFields - Resumed and polishing

2013-01-03 Thread Era Scarecrow
On Thursday, 3 January 2013 at 21:15:19 UTC, Dmitry Olshansky wrote: 04-Jan-2013 00:11, Era Scarecrow wrote: Appending a slice *to* BitArray is perfectly fine as in fact any range of bool (or bit if you like). Any array-like or string-like container has to support appending a range of

Re: BitArray/BitFields - Resumed and polishing

2013-01-02 Thread Dmitry Olshansky
12/31/2012 9:35 PM, Era Scarecrow пишет: As BitArray is coming back up and my resumed work I'll comment a few questions and suggestions and go from there. I'll polish up the code and try to resubmit it. Yay! On Saturday, 28 July 2012 at 21:07:31 UTC, Jonathan M Davis wrote: I would point

Re: BitArray/BitFields - Resumed and polishing

2013-01-02 Thread Era Scarecrow
be cool ;) https://github.com/rtcvb32/phobos/blob/BitArray-Updates/std/bitmanip.d There's a merge issue due to having tried to keep the bitfields and bitarray separated; That seems to have made more problems than solutions. Working on it but may have to wait until I've read my Git book when

BitArray/BitFields - Resumed and polishing

2012-12-31 Thread Era Scarecrow
As BitArray is coming back up and my resumed work I'll comment a few questions and suggestions and go from there. I'll polish up the code and try to resubmit it. On Saturday, 28 July 2012 at 21:07:31 UTC, Jonathan M Davis wrote: I would point out that while hasSlicing doesn't currently check

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread monarch_dodra
On Wednesday, 1 August 2012 at 07:24:09 UTC, Era Scarecrow wrote: On Tuesday, 31 July 2012 at 20:41:55 UTC, Dmitry Olshansky wrote: Great to see things moving. Could you please do a separate pull for bitfields it should get merged easier and it seems like a small but important bugfix

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread Era Scarecrow
On Thursday, 2 August 2012 at 09:03:54 UTC, monarch_dodra wrote: I had an (implementation) question for you: Does the implementation actually require knowing what the size of the padding is? eg: struct A { int a; mixin(bitfields!( uint, x,2, int, y,3

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread monarch_dodra
(bitfields!( uint, x,2, int, y,3, ulong, ,3 // - This line right there )); } It that highlighted line really mandatory? I'm fine with having it optional, in case I'd want to have, say, a 59 bit padding, but can't the implementation figure it out on it's own

bitfields - Padding needed?

2012-08-02 Thread Era Scarecrow
) If your using bitfields, then you are going for space, and to be as small as reasonably possible. Especially important for packets of information like headers for compression, and making it compatible with C/C++'s bitpacking. That said, something that could fix the above problem could be: *Bitfields

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread Andrei Alexandrescu
On 8/2/12 5:14 AM, Era Scarecrow wrote: On Thursday, 2 August 2012 at 09:03:54 UTC, monarch_dodra wrote: I had an (implementation) question for you: Does the implementation actually require knowing what the size of the padding is? eg: struct A { int a; mixin(bitfields!( uint, x, 2, int, y, 3

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread Andrei Alexandrescu
On 8/2/12 5:26 AM, monarch_dodra wrote: One of the *big* reasons I'm against having a hand chosen padding, is that the implementation *should* be able to find out what the most efficient padding is on the current machine (could be 32 on some, could be 64 on some) In my neck of the woods they

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread Era Scarecrow
On Thursday, 2 August 2012 at 12:35:20 UTC, Andrei Alexandrescu wrote: Please don't. The effort on the programmer side is virtually nil, and keeps things in check. In no case would the use of bitfields() be so intensive that the bloat of one line gets any significance. If you're using

bitfields - 4425 bells whistles

2012-08-02 Thread Era Scarecrow
Following from issue list: bearophile_hugs 2010-10-04 18:16:44 PDT Another possible feature is to make std.bitmanip.bitfields generate two versions of the code, that get compiled conditionally according to the CPU endianess: static if (std.system.endian == std.system.Endian.BigEndian) {

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread monarch_dodra
On Thursday, 2 August 2012 at 12:38:10 UTC, Andrei Alexandrescu wrote: On 8/2/12 5:26 AM, monarch_dodra wrote: One of the *big* reasons I'm against having a hand chosen padding, is that the implementation *should* be able to find out what the most efficient padding is on the current machine

Re: Why must bitfields sum to a multiple of a byte?

2012-08-02 Thread Andrei Alexandrescu
On 8/2/12 9:48 AM, monarch_dodra wrote: On Thursday, 2 August 2012 at 12:38:10 UTC, Andrei Alexandrescu wrote: On 8/2/12 5:26 AM, monarch_dodra wrote: One of the *big* reasons I'm against having a hand chosen padding, is that the implementation *should* be able to find out what the most

Re: Why must bitfields sum to a multiple of a byte?

2012-08-01 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 20:41:55 UTC, Dmitry Olshansky wrote: Great to see things moving. Could you please do a separate pull for bitfields it should get merged easier and it seems like a small but important bugfix. https://github.com/rtcvb32/phobos/commit

Re: BitArray/BitFields - Reworking with templates

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 05:27:58 UTC, Philippe Sigaud wrote: No. Use a 3-params template or a tuple: void func(A,B,C)(X!(A,B,C) x) {} or void func(Ts...)(X!(Ts) x) {} I don't know how many arguments it will have (depends on how many options I give it), and I honestly don't; It should be

Re: BitArray/BitFields - Review

2012-07-31 Thread Don Clugston
On 29/07/12 23:36, bearophile wrote: Era Scarecrow: Another commonly needed operation is a very fast bit count. There are very refined algorithms to do this. Likely similar to the hamming weight table mentioned in TDPL. Combined with the canUseBulk I think I could make it fairly fast.

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread monarch_dodra
/issues/show_bug.cgi?id=8474 The bug is only when the field is EXACTLY 32 bits BTW. bitfields works quite nice with 33 or whatever. More details in the report.

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Andrej Mitrovic
On 7/31/12, monarch_dodra monarchdo...@gmail.com wrote: The bug is only when the field is EXACTLY 32 bits BTW. bitfields works quite nice with 33 or whatever. More details in the report. Yeah 32 or 64 bits, thanks for changing the title.

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 15:25:55 UTC, Andrej Mitrovic wrote: On 7/31/12, monarch_dodra monarchdo...@gmail.com wrote: The bug is only when the field is EXACTLY 32 bits BTW. bitfields works quite nice with 33 or whatever. More details in the report. Yeah 32 or 64 bits, thanks for changing

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Andrej Mitrovic
++. I haven't used bitfields myself in my own code.

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
don't really know, I'm looking at this from a point of wrapping C++. I haven't used bitfields myself in my own code. I'd say it's not a bug since C/C++ is free to reorder the fields you'd need to tinker with it anyways; HOWEVER if you still need to be able to have it then who's to stop you from

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread monarch_dodra
On Tuesday, 31 July 2012 at 16:16:00 UTC, Era Scarecrow wrote: On Tuesday, 31 July 2012 at 15:25:55 UTC, Andrej Mitrovic wrote: On 7/31/12, monarch_dodra monarchdo...@gmail.com wrote: The bug is only when the field is EXACTLY 32 bits BTW. bitfields works quite nice with 33 or whatever. More

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 16:59:11 UTC, monarch_dodra wrote: No, it's a bug. There is no reason for it to fail (and it certainly isn't a feature). If I made two fields in a 64bit bitfield, each 32bits int's I'd like it to complain; If it's calculated from something else then finding the

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Timon Gehr
? You could just declare it separately. I don't really know, I'm looking at this from a point of wrapping C++. I haven't used bitfields myself in my own code. I'd say it's not a bug since C/C++ is free to reorder the fields you'd need to tinker with it anyways; HOWEVER if you still need to be able

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 17:17:43 UTC, Timon Gehr wrote: (Also IMO, the once-in-a-year wtf that is caused by accidentally assigning in an if condition does not justify special casing assignment expressions inside if conditions. Also, what is an useless compare?) I've noticed in my

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread monarch_dodra
: struct A { mixin(bitfields!( ushort, a, 24, uint,, 8 ) ); } I don't see any way how that could make sense... But it *is* legal in C and C++... But it does generates warnings... I think it should static assert in D. On Tuesday, 31 July

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
A { mixin(bitfields!( ushort, a, 24, uint,, 8 ) ); } I don't see any way how that could make sense... But it *is* legal in C and C++... But it does generates warnings... Maybe so ushort has extra padding for expansion at some later date when

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 17:17:43 UTC, Timon Gehr wrote: This is obviously a mistake in the bitfield implementation. What else could be concluded from the error message: std\bitmanip.d(76): Error: shift by 32 is outside the range 0..31 Requesting a 32 bit or 64 bit member on the other

fixing the bitfields implimentation

2012-07-31 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 17:17:43 UTC, Timon Gehr wrote: This is obviously a mistake in the bitfield implementation. What else could be concluded from the error message: std\bitmanip.d(76): Error: shift by 32 is outside the range 0..31 Requesting a 32 bit or 64 bit member on the other

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Ali Çehreli
On 07/31/2012 09:15 AM, Era Scarecrow wrote: On Tuesday, 31 July 2012 at 15:25:55 UTC, Andrej Mitrovic wrote: On 7/31/12, monarch_dodra monarchdo...@gmail.com wrote: The bug is only when the field is EXACTLY 32 bits BTW. bitfields works quite nice with 33 or whatever. More details

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Dmitry Olshansky
of consequence? Great to see things moving. Could you please do a separate pull for bitfields it should get merged easier and it seems like a small but important bugfix. -- Dmitry Olshansky

Re: Why must bitfields sum to a multiple of a byte?

2012-07-31 Thread Era Scarecrow
? Great to see things moving. Could you please do a separate pull for bitfields it should get merged easier and it seems like a small but important bugfix. Guess this means I'll be working on BitArrays a bit later and work instead on the bitfields code. What fun... :) I thought I had bitfields

BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Sunday, 29 July 2012 at 12:39:13 UTC, Era Scarecrow wrote: But having them statically separated by name/type seems much more likely to be safer in the long run with reliable results. A question regarding templates. A template with different parameters is completely incompatible correct?

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 30-Jul-12 23:50, Era Scarecrow wrote: On Sunday, 29 July 2012 at 12:39:13 UTC, Era Scarecrow wrote: But having them statically separated by name/type seems much more likely to be safer in the long run with reliable results. A question regarding templates. A template with different

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Philippe Sigaud
On Mon, Jul 30, 2012 at 9:50 PM, Era Scarecrow rtcv...@yahoo.com wrote: A question regarding templates. A template with different parameters is completely incompatible correct? Correct. They have no reason, in general, too even generate the same code: template Chameleon(T) { static if

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 21:03:39 UTC, Era Scarecrow wrote: Alright... Considered a major (Maybe even blocking). http://d.puremagic.com/issues/show_bug.cgi?id=8475

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 20:48:26 UTC, Philippe Sigaud wrote: Now if all that is correct, say I want to make two functions that both use X, but are not compatible, but template functions will allow it. So... I'm not sure I understand what you're trying to do. Do you mean you want a

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 01:03, Era Scarecrow wrote: On Monday, 30 July 2012 at 20:19:51 UTC, Dmitry Olshansky wrote: Not sure what you would like to accomplish here. Than an example... You can go for simpler separation: struct BitArray{ //() - is an empty template spec ref

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: You can go for simpler separation: struct BitArray{ //() - is an empty template spec ref BitArrayopSliceAssign()(const BitArray ba, int start, int end) { //two bit array can try balk mode etc. I'll give it a try, it may very

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 22:23:46 UTC, Era Scarecrow wrote: On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: in == scope const not sure what scope buys here but couldn't hurt. If it can avoid making a new copy, then it likely would help. I'll need to test it. I actually am

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Dmitry Olshansky
On 31-Jul-12 02:40, Era Scarecrow wrote: On Monday, 30 July 2012 at 22:23:46 UTC, Era Scarecrow wrote: On Monday, 30 July 2012 at 21:56:20 UTC, Dmitry Olshansky wrote: in == scope const not sure what scope buys here but couldn't hurt. If it can avoid making a new copy, then it likely would

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 22:44:21 UTC, Dmitry Olshansky wrote: Fixed : void func(bool smth)(X!(smth).XT x){ By default XT is deduced as X!(current value of smth).XT Doesn't really fix it... a.func(b); //65 - doesn't match declaration. a.func(ba); //66 //other template

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 17:43:28 UTC, Ali Çehreli wrote: On 07/30/2012 10:15 AM, Andrej Mitrovic wrote: import std.bitmanip; struct Foo { mixin(bitfields!( uint, bits1, 32, )); } D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\bitmanip.d(76): Error: shift by 32

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow rtcv...@yahoo.com wrote: And likely one I'll be working on fairly soon. I've been concentrating on the BitArray, but I'll get more of the bitfields very very soon. Cool. What about the max limit of 64bits per bitfield instantiation? I don't suppose this is common

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Monday, 30 July 2012 at 23:41:39 UTC, Andrej Mitrovic wrote: On 7/31/12, Era Scarecrow rtcv...@yahoo.com wrote: And likely one I'll be working on fairly soon. I've been concentrating on the BitArray, but I'll get more of the bitfields very very soon. Cool. What about the Max limit

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Era Scarecrow
On Tuesday, 31 July 2012 at 00:00:24 UTC, Era Scarecrow wrote: Corrections: So, 2 variables using 4 bit ints would be void a(int v) @property { value = ~(0x7 4); value |= (v 0x7) 4; } the second setter should be void b(int v) @property {

Re: Why must bitfields sum to a multiple of a byte?

2012-07-30 Thread Andrej Mitrovic
On 7/31/12, Era Scarecrow rtcv...@yahoo.com wrote: It assumes the largest type we can currently use which is ulong Ah yes, it makes sense now. Thanks for the brain cereal. :p

Re: BitArray/BitFields - Reworking with templates

2012-07-30 Thread Philippe Sigaud
On Mon, Jul 30, 2012 at 11:19 PM, Era Scarecrow rtcv...@yahoo.com wrote: void func(T)(X!T x) {} void main() { X!bool b; X!int i; func(b); func(i); } Hmmm i do think that seems right... but if it contains multiple parameters, then...? template X(x1, x2, x3) {

Re: BitArray/BitFields - Review

2012-07-29 Thread Dmitry Olshansky
in the container itself. No it doesn't. bitfields are used to handle the beginning/ending offsets, equaling a total of 14 bits. It's the most confusing part (aside from [offset + sliceoffset + i[ formulas). canExpand and isCompact fill the other two bits. OK, finally I think I understand how your

Re: BitArray/BitFields - Review

2012-07-29 Thread Era Scarecrow
only propagate to a new true copy, otherwise it's read-only as a slice. Because of d, I proposed that slices be separate type that is always a reference to original. Then only coping arrays themselves involves dup. Mmmm... i think you're right... No it doesn't. bitfields are used to handle

Re: BitArray/BitFields - Review

2012-07-29 Thread Era Scarecrow
On Sunday, 29 July 2012 at 06:27:32 UTC, Dmitry Olshansky wrote: Thus BitArray either becomes value type (that may come as unexpected, see your option c/d). Or it becomes full reference type as in option a (though it sucks). Sorry but b is no go, as it makes code unpredictable I'd rather take

Re: BitArray/BitFields - Review

2012-07-29 Thread Dmitry Olshansky
On 29-Jul-12 12:55, Era Scarecrow wrote: On Sunday, 29 July 2012 at 06:27:32 UTC, Dmitry Olshansky wrote: Thus BitArray either becomes value type (that may come as unexpected, see your option c/d). Or it becomes full reference type as in option a (though it sucks). Sorry but b is no go, as it

Re: BitArray/BitFields - Review

2012-07-29 Thread Era Scarecrow
On Sunday, 29 July 2012 at 09:03:08 UTC, Dmitry Olshansky wrote: On 29-Jul-12 12:55, Era Scarecrow wrote: Doing it this way the arguments being passed as reference slices would ensure unneeded copies wouldn't be made. On the other hand a smaller portion of the code would need to be updated.

Re: BitArray/BitFields - Review

2012-07-29 Thread Dmitry Olshansky
On 29-Jul-12 13:18, Era Scarecrow wrote: On Sunday, 29 July 2012 at 09:03:08 UTC, Dmitry Olshansky wrote: On 29-Jul-12 12:55, Era Scarecrow wrote: Doing it this way the arguments being passed as reference slices would ensure unneeded copies wouldn't be made. On the other hand a smaller portion

Re: BitArray/BitFields - Review

2012-07-29 Thread Dmitry Olshansky
On 29-Jul-12 14:28, Era Scarecrow wrote: On Sunday, 29 July 2012 at 09:30:06 UTC, Dmitry Olshansky wrote: I have simpler suggestion. Maybe doing it as 2 containers: BitSet is a plain value type with small array optimization (what you called BitArray in last 2 posts) and no slicing (only as

  1   2   >