-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Portability
-
Server Programmability
I want to collect some notes on differences in StringData that could complicate a migration to std::string_view.
The BIG one: as of its introduction in C++17, std::string_view(cp) is UB for null-valued cp, but this is tolerated for StringData. This will be very difficult to audit for, as this is an implicit constructor.
Renames:
- rawData() should be called data().
- startsWith,endsWith (slated for C++20 as starts_with and ends_with).
Several public members must be brought outside the class:
- The range constructor.
- toString.
- (
SERVER-48429) StringData::ComparatorInterface. - equalCaseInsensitive
- copyTo
Behavior:
Exception behavior should match. std::string_view throws std::out_of_range.
Noexcept and constexpr annotations should be aligned with string_view.
- char operator[](unsigned) should take size_type and return const_reference.
Needs more members:
- Several typedefs need to be added.
- many more find/rfind variants, and these need offset parameters.
- remove_prefix / remove_suffix
- string_view has its own npos
- (
SERVER-38248) explicit operator std::string instead of .toString, to approximate the string(string_view) ctor. - member swap
- at, front, back, max_size, length
- (c?r?)(begin|end) iterator accessors.
- `explicit operator std::string() const`
Apparatus:
- needs std::hash specialization.
- nonmember swap.
- (
SERVER-32434) put-to-stream operator<< needs to be made FormattedOutputFunction compliant.
See https://en.cppreference.com/w/cpp/named_req/FormattedOutputFunction
It's not as simple as the current stream.write(), unfortunately.
- is related to
-
SERVER-48429 Remove StringData::ComparatorInterface from StringData
- Closed
- related to
-
SERVER-55180 Remove StringData <=> std::string_view implicit conversions
- Closed