On Tuesday, 7 April 2015 at 14:20:58 UTC, Jens Bauer wrote:
On Tuesday, 7 April 2015 at 08:33:58 UTC, John Colvin wrote:
@property isn't really about parentheses-less calls
(parentheses are optional for all function calls), it's more
for this sort of thing:
[snip]
@property void val(int v)
{
a_ = (a_ & flagMask) & (v & ~flagMask);
}
This is *really* cool and very useful on microcontrollers and
is superior to C's bit-fields.
Imagine that your microcontroller has 24 GPIO pins.
Such pins are usually grouped in 'ports', for instance Port A
and Port B.
Each port could for instance support up to 32 pins: PA0 ...
PA31 and PB0 ... PB31.
But there's a problem here: Our microcontroller has only 24
pins, and our microcontroller vendor chose to make the
following pins available to us:
PA1 ... PA5, PA7, PA13, PA17, PA18 .. PA19, PA23 ... PA28
PB0 ... PB3, PB8 ... PB12
Every developer will think this is annoying. We want to write a
byte to a port, but it has to be converted first.
If just incrementing a value, one could do as follows:
PortB = (PortB | 0x00f0) + 1;
... oposite for decrementing:
PortB = (PortB & 0xff0f) - 1;
But the @property can make all this transparent, so our sources
become very easy to overview and understand.
and, for convenience there is
http://dlang.org/phobos/std_bitmanip.html#.bitfields