Trip report: Fall ISO C++ standards meeting
herbsutter.com
herbsutter.com
Can someone smarter than I am explain the significance about bit_cast running at compile time?
Here are some videos on the topic: https://www.youtube.com/watch?v=PJwd4JLYJJY https://www.youtube.com/watch?v=rpn_5Mrrxf8
Mostly though, this is fairly unimportant and tedious spec-manship, filling in some obvious gaps.
We had a version of this in chromium a few years ago. This is a proposal just picking that up from what I can tell.
friend bool operator==(const CIString& a, const CIString& b)
{ return ci_compare(a.s.c_str(), b.s.c_str()) != 0; }
friend bool operator< (const CIString& a, const CIString& b)
{ return ci_compare(a.s.c_str(), b.s.c_str()) < 0; }
This way a<b implies a==b.for (auto& x : f().things()) { // dangling reference!
mutate(&x);
}
```
Oh shit I think I have to go through a dozen projects in production and fix some code now. Thanks Herb.
If f() returns a value then you have a problem and should fix it, but if f() instead returns a reference (that is not dangling in itself), then it should be fine.
Now it all makes sense. This is what I get for trying to read technical stuff while drunk at midnight.
[1] https://stackoverflow.com/questions/21861148/what-does-the-s...
Herb Sutter's awesome like that.
body {
animation: -amp-start 8s steps(1,end) 0s 1 normal both;
}
@keyframes -amp-start {
0% {
visibility: hidden;
}
100% {
visibility: visible;
}
} template<typename A, typename B>
bool is_unordered(const A& a, const B& b) {
return !(a<b||a==b||a>b);
}
edit: changed implementation to match name.Coming up with an entirely fresh meaning for <=> involving spaceships and a conglomerated comparative threesome just seems illogical to me, given the original meanings of the component symbols of <=>.
It's also incredibly useful, allowing six functions to be replaced by one. Or, rather, with zero, because in 99.9% of cases you will just be able to declare the signature with '= default;' and let the compiler generate the implementation. Then you have all relational operators available for that type. It makes defining new types much, much easier.
Plus, it provides a place to statically define what sort of ordering the type has, so further compile-time optimizations can be done.
In contrast, <=> as is_ordered is nearly useless. It would basically only be used for floats, where !(isnan(a)||isnan(b)) is both equivalent and IMO more clear.
((a<b)&&(a==b)) is equivalent to (false)
(a<b)||(a==b)||(a>b)
Double ampersand is logical AND, you want double bars for logical OR.And still, that's equivalent to !(std::is_nan()), unless you're suggesting using the operator on other non-floating-point types which have a similar problem...
Why not `is_nan()` insted?
For example, when comparing strings, you could use it to coerce the arguments into spaceship objects, then run a little Space War simulation to lighten the user's day. Just another day of C++ operator overloading.
https://dlang.org/spec/expression.html#floating-point-compar...
You write isnan(x)||isnan(y) but the compilers now optimize the whole thing to one instruction.
If you want specific syntax you can use the builtin unordered(x, y).