Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-32422

convert StringData to std::string_view

    • Service Arch

      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:

            Assignee:
            backlog-server-servicearch [DO NOT USE] Backlog - Service Architecture
            Reporter:
            billy.donahue@mongodb.com Billy Donahue
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated: