2 ms·
Ouch. Can it handle things like conditionally swapping two values or does any conditional assignment break both values? Is there an escape hatch?
by bcoates 14y ago
Ouch. Can it handle things like conditionally swapping two values or does any conditional assignment break both values? Is there an escape hatch?
- pcwalton 14y agoThere is a swap operator built into the language, so that specific example would work (I think; I haven't checked the code). The escape hatch is to use the generic "Cell<T>" type in the standard library, which gives you dynamic behavior much like C++11 move semantics. The nice thing about the static analysis, though, is that the checks don't have to be performed at runtime if the compiler can prove that the value is always moved at the end of the block.