Alternative for the = sign
I'm not sure what is meant
how person C is, but if they are just integers, then how about:
x |= y; // all bits set in y now definitely set in x x &= y; // all bits not set in y now definitely not set in x
Or, as per Oli Charlworth's comment below, if you don't want the = symbol, then:
x or_eq y; // all bits set in y now definitely set in x x and_eq y; // all bits not set in y now definitely not set in x
source to share
Warning: this is getting ugly ... firmly in fragile hacker land; -P.
An assignment to an arbitrary type sometimes has to call a function — the assignment operator or the [copy] constructor. Placement
is a statement, not a function call, although you may need to pass parameters to the constructor. To recreate the object as a whole, you need to know that it was destroyed beforehand, which requires a function call but not for assignment - is that allowed or not? :-) Anyway, the idea still breaks down if reconstruction can throw, since the destructor can be called a second time on an already destroyed object. In practice, you can write a destructor to make this safe (e.g. NULL pointers after
) or don't throw the constructor, but this behavior is undefined and not really general (the kinds of complications you might expect: the virtual dispatch pointer may have already been returned to the base class from destructors that were deleted, virtual bases were destroyed, etc. .) ....
T x = a, y = b; // "background" // hacked pseudo-assignment x.~T(); // should make this function call though, if it exists! new (&x)(y); // x = y
Another bizaare approach that may or may not be accepted, depending on whether indirect function calls are allowed:
std::stringstream ss; ss << y; ss >> y;
More generally, the only mutating operators that don't include the "=" sign in their typical form are placement
, and alternative forms such as
have also been discussed in other answers, so I'm thinking about it ....
source to share