Ada to D - an array for storing values of each of the six bits which are sufficient
    Dennis Ritchie via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Sat May  2 18:26:12 PDT 2015
    
    
  
On Friday, 1 May 2015 at 23:22:31 UTC, Dennis Ritchie wrote:
> Maybe someone will show a primitive packed array. I really can 
> not imagine how to do it on D.
		
Maybe you can somehow use bitfields. While what happened is 
something like this:
-----
import std.stdio, std.bitmanip;
struct A
{
	mixin(bitfields!(
			uint, "bit",  6,
			bool, "flag1", 1,
			bool, "flag2", 1));
}
void main() {
	A obj;
	int[] a;
	foreach (e; 0 .. 64) {
		obj.bit = e;
		a ~= e;
	}
	writeln(a);
	// obj.bit = 64; // Value is greater than
	//the maximum value of bitfield 'bit'
}
-----
http://ideone.com/Opr4zM
    
    
More information about the Digitalmars-d-learn
mailing list