My question is regarding C++17: http://en.cppreference.com/w/cpp/string/basic_string_view/basic_string_view
What's the caveat of implicit conversion from std::basic_string to std::basic_string_view that it wasn't included in the interface of the latter?
I believe it would greatly improve this class. Especially the family of comparison operators that, also do not accept std::string as neither lhs nor rhs.
There is such conversion in library fundamentals TS specification: http://en.cppreference.com/w/cpp/experimental/basic_string_view/basic_string_view
This question is about why it was removed. Or rather not adopted.
basic_string_view
is considered the lower level class. It's the providers of string containers who have the responsibility of providing implicit conversions to string_view
. If you have your own string type, then you would give it a possibly explicit
operator string_view()
overload to perform implicit conversion.
As such, it was decided (PDF) that basic_string
would provide the conversion to basic_string_view
. The original Library Fundamentals version put the implicit conversion on basic_string_view
, because a TS is usually an extension. It can't affect an existing type without effectively forking that type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With