|
|
|
|
|
by mgaunard
813 days ago
|
|
I've been involved with the C++ standards committee for 12+ years and my experience is that it is largely political; championing a proposal is more of a demagogic endeavor than anything else. Influential players have been priming contracts (that have been in the works forever) as a core objective this cycle and giving it a lot of momentum for it to happen this time. Of course if people still can't be convinced it's good enough before the deadline, it won't make the cut, but it's on track. Now regarding undefined behaviour, it's always been the reason why the proposal isn't moving forward. Some people believe religiously undefined behaviour is evil and will oppose anything tied to it. The kind of clause you mentioned is just to appease them and attain a compromise. But ultimately, contracts and undefined behaviour (depending on the definition you go for) are intimately linked. Consider lower_bound. The behaviour is undefined if the input is not sorted. That's just the way it is. You can't magically make a program well-formed if you breach preconditions even if you say optimizers are not allowed to make additional assumptions. |
|
No, it's a classic WG21 choice in that it's pointlessly worse, that's not "the way it is" it's just the way WG21 decided to define it in C++. More reasonable choices would obviously include the choice made over in std::set where lower_bound gives you a past-the-end iterator if there isn't an apparent answer for your inputs.
Undefined Behaviour is the worst choice, which is why in a horrible way it makes sense as WG21's default - a group known for always choosing bad defaults.
> You can't magically make a program well-formed if you breach preconditions
Of course you can, it's not even hard.