convert StringData to std::string_view

XMLWordPrintableJSON

    • 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:

            Assignee:
            Unassigned
            Reporter:
            Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated: