You know, that's a damn good point. Instead of specializing on size, I'll use a separate bitbool<type, position> template for the boolean-semantics version. That lets the parameters to the regular bitfield template be <type, lo, hi>, which is easier to eyeball for correctness.byuu wrote:> The bit size is required so that 1-bit bitfields can be specialized to have boolean semantics (you want flags.cy = 2 to set the bit to 1, not 0)
That's actually debatable. In most cases that is what you want, but there are fun things you can do with a uint1 type.
Add a cast operator that returns a reference to the all-the-bits member. You have to define this operator for each bitfieldy union you define, but it's only two trivial one-liners, one for rvalue and one for lvalue.So your method would disallow treating the parent as the whole object.
Make a, y and ya an anonymous union inside regs. Problem solved. Anyway, I thought we agreed we weren't going to use these for byte-aligned stuffOkay, but what about the SPC700's YA register? You're going to end up with:
regs.ya.a
regs.ya.y
regs.ya.ya = yayaya.iAmLorde
(snip stuff about nall::vector, I haven't really looked at it in detail, I'll acknowledge that maybe it's not as bad as I thought it was)
No, I don't mean the readonly<> crap. I mean properties in the Python sense, which look, walk and quack exactly like data members to the outside world, but transparently wrap a getter and setter method of the class they're a property of. I think there are other dynamic programming languages with a similar feature, Python is just the one I'm familiar with.What I really want are getter/setters. We shouldn't need to have Foo::value(), Foo::setValue(Value), Foo::_value. This breaks all of our math.
Code: Select all
struct Size {
int width; //our first iteration of our class; we're fine treating this as a variable
property<int> height { //a later iteration, turns out if height changes we need to do other stuff
operator int() { return *this; }
auto& operator=(int value) { *this = value; doStuff(); return *this; }
};
//the layout of the struct is the same after we changed height;
//all existing code that used size.height still compiles and is backward-compatible;
//although .o files that use Size::height will need to be recompiled for obvious reasons
};There's no requirement that Python properties have an "underlying data member" at all; you can have a readonly property that calculates some result on the fly, or a property whose getter and setter do completely unrelated things (though I'm not sure why you'd want to do the latter except to write obfuscated code) Since properties are invisible to client code, you can start with class.a as a property that's calculated on the fly from class.b which is a real data member, and later change it so class.a is the data member and class.b is calculated on the fly, and none of your clients will care (unless they try to assign to one of them)
