> 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.
Code: Select all
uint3 a = opcode >> 0;
uint1 b = opcode >> 3;
uint4 c = opcode >> 4;
I know you can rewrite it like this:
Code: Select all
uint3 a = opcode & 0x07;
uint1 b = opcode & 0x08;
uint4 c = (opcode & 0xf0) >> 4;
It's nice for the consistency. And you can also say:
For this reason, I have both uint1 and boolean types to represent the two differences -and- allow for member functions to do whatever on the types.
> No per-application bit twiddling or operator overloads--all that crap is done by the bitfield template.
So your method would disallow treating the parent as the whole object.
Okay, 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
Ick.
I see why the type is mandatory with this style. That's a shame, but no way around that.
> So if you use these for CPU flags you can't have a generic set_flag(flag &which) opcode handler
EDIT: oh, nevermind. I didn't read the flag part. Yeah, that's a shame.
Type erasure or template functions are the only possible workarounds. The latter is an absolute "fuck no" for obvious reasons.
> your vector that's also a deque is exhibit #1
nall::vector is as fast as std::vector on both accesses and appends, and is O(1) vs O(n) for prepends/pop_fronts.
My goal is to keep code size small. nall::vector is 8.86KiB of code. Without the deque-stuff, it'd be ~7.5KiB. Duplicating it all and then changing a small bit for a deque would make it ~16KiB, and I'd have to keep the APIs in parity. When I wanted to read a file, I'd get a vector<uint8_t> from file::read, and then when I wanted to use that with prepend/pop_front for some reason, I'd need to convert a vector to a deque, or write a file::readAsDeque function.
Further, nall::vector isn't a deque. std::deque does not guarantee contigious storage. deque is slightly faster as a result, but you can't grab a raw memory pointer to the array which is a deal breaker for a huge amount of use cases.
The only overhead the prepend/pop_front functionality adds to nall::vector right now is an extra 4 bytes for the container object. It doesn't even waste any extra space on size growth amortization if you don't use that functionality.
For once ... instead of just saying, "this thing you're doing is dumb", I'd like to have you give a strong rationale for why having prepend functionality in my vector class is such a terrible thing. Please elaborate on all the problems caused by this functionality.
> I've noticed that you really, really, really like property semantics
You mean the readonly<> templates? I've been slowly removing those. I like the idea, but it's too ugly in the code.
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.
Example:
Code: Select all
size.width += size.height + 4;
size.setWidth(size.width() + size.height() + 4);
Ick ick ick ick ick. And not hyperbole. This kind of code is all over hiro with the Geometry class.
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
};
Of course, the thing I'd really, really kill for is unified function call syntax. But that got tanked by ... short-sighted people on the C++17 Jacksonville panel.
> Tough. If you like them so much then learn Python
Okay then. I'll get to work on rewriting bsnes in Python, so that I can have properties :P