I would hope you wouldn't find that in C++ as that would defeat the purpose of an if else statement and is possibly a slower method of accomplishing such a task.
bool readWrite(bob &something, bob if_not)
{
if (something)
returnfalse;
else
something = if_not;
}
To begin, functions themselves have overhead. By not using such a function, you do not incur the overhead of both passing variables onto a stack and then calling the function.
Using the above function, I've illustrated a possible implementation of such a function. Please try and do better so as to make cycle usage and "seek latency" go down. There *might* be some assembly that could outperform basic syntax but compilers tend to be pretty smart. Who knows?
This topic rings only one bell to me: Interlocked functions in the Windows API. There are certain functions that are only available in certain architectures, so I guess they do have something to do with the hardware. I don't know assembly so I just can't be sure.
I also know they provide atomic operations, but I don't know if they are faster at all than a non-atomic counterpart.
If this is Windows and you would like to investigate, an example of such functions is InterlockedIncrement().
There is in hardware a command that does the following in an atomic fashion:
T oldValue = readWrite(T* memorylocation, T newValue);
The result of doing it is for example:
1 2
int i = 5;
int value = readWrite(&i, 1);
then i = 1 and value = 5.
The idea is that no matter what, the memorylocation's value is changed to newValue. However, I wanted to know the old value as well. In essense the hardware function reads the old value, stores the new one, and returns the old (all in one disk access). Unfortunately I forgot the name...
I think I get what your saying... I can think it out in my fugly idea of CQ's assembly but I'm not sure its worth your time. Maybe suggest a new syntax to support such an idea? You still have function overhead so using a function for such a thing probably doesn't pan out well. Using inline assembly in an inline function doesn't really make sense to me either.