Re: union initalization

2016-07-22 Thread Johannes Pfau via Digitalmars-d-learn
Am Fri, 22 Jul 2016 01:48:52 + schrieb Rufus Smith : > I would like to combine two types > > > template Foo(A, B = 4) > { > union > { > byte b = B; > int a = A << 8; > } > } > > > I get an error about overlapping default initialization.

Re: union initalization

2016-07-22 Thread Ali Çehreli via Digitalmars-d-learn
On 07/21/2016 08:00 PM, Rufus Smith wrote: >> Bitfields may actually be useful in this case: >> >> https://dlang.org/phobos/std_bitmanip.html#.bitfields >> > > They don't allow default assignment though? A factory function can help: import std.bitmanip; struct S(int a_init, byte b_init) {

Re: union initalization

2016-07-21 Thread Rufus Smith via Digitalmars-d-learn
On Friday, 22 July 2016 at 02:08:06 UTC, Ali Çehreli wrote: On 07/21/2016 06:48 PM, Rufus Smith wrote: > I would like to combine two types > > > template Foo(A, B = 4) > { > union > { > byte b = B; > int a = A << 8; > } > } > > This packs a and b together in to an

Re: union initalization

2016-07-21 Thread Ali Çehreli via Digitalmars-d-learn
On 07/21/2016 06:48 PM, Rufus Smith wrote: > I would like to combine two types > > > template Foo(A, B = 4) > { > union > { > byte b = B; > int a = A << 8; > } > } > > This packs a and b together in to an int bytes, saving an int(rather > than storing a and b in an

union initalization

2016-07-21 Thread Rufus Smith via Digitalmars-d-learn
I would like to combine two types template Foo(A, B = 4) { union { byte b = B; int a = A << 8; } } This packs a and b together in to an int bytes, saving an int(rather than storing a and b in an int each) and makes it easier to access. I get an error about