-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: Portability
-
Server Programmability
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
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:
- ✅ (
SERVER-48429) StringData::ComparatorInterface. - ✅ equalCaseInsensitive
- ✅ copyTo
- (SERVER-105843) toString (rewrite all callers to use std::string casts).
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
- (SERVER-106029) The range constructor.
- (SERVER-106029) contains()
- (SERVER-106029) C++20 style defaulted operator<=>, operator==.
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.
- depends on
-
SERVER-106029 enable StringData C++20 features
-
- In Code Review
-
-
SERVER-105843 StringData: convert `sd.toString()` to `std::string{sd}`
-
- In Progress
-
- is related to
-
SERVER-32434 operator<<(ostream,StringData) ignores stream state.
-
- Closed
-
-
SERVER-48429 Remove StringData::ComparatorInterface from StringData
-
- Closed
-
-
SERVER-38248 StringMap should be implemented as absl::flat_hash_map
-
- Closed
-
-
SERVER-106029 enable StringData C++20 features
-
- In Code Review
-
- related to
-
SERVER-55180 Remove StringData <=> std::string_view implicit conversions
-
- Closed
-
-
SERVER-105109 Rename StringData rawData() to data()
-
- Closed
-