mclow / String-Algo

Noodling with Boost.StringAlgo
3 stars 0 forks source link

string_view::remove_prefix(npos) #10

Open OlafvdSpek opened 6 years ago

OlafvdSpek commented 6 years ago

Undefined behavior for std, defined behavior for Boost.

Wouldn't it be better to have the same behavior for both?

mclow commented 6 years ago

I'm confused. Are you asking for "consistent undefined behavior"?

OlafvdSpek commented 6 years ago

Maybe A debug assert or maybe even a trap in release might be nice to avoid any surprises when substituting boost::string_view for the std one.

mclow commented 6 years ago

The whole point of undefined behavior is that you have no guarantees - of anything. The C people used to say "and demons will fly out of my nose". You can run a program with UB twice in a row on the same machine with the same inputs, and once it might give you the right answer, and the second time it might cause your cat to become pregnant.

OlafvdSpek commented 6 years ago

I know. The problem is that boost::string_view::remove_prefix(npos) is well-defined, while std::string_view::remove_prefix(npos) is undefined. So people that rely on the boost one and will be bitten when they switch to the std one.