cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
<string_view>

Backports related to Standard header <string_view>

#include <cxxomfort/string_view.hpp>
// or as part of:

Interfaces

Interfaces defined here:

For differences between the implementation of string_view here vs standard, check the notices at basic_string_view

Fixes / Interfaces not in std:

"sv" user-defined literal

C++17 onwards defines operator"" sv as the user-defined literal to create basic_string_view objects. The cxxomfort library backports the string_view and wstring_view capable versions of this user-defined literal.

using namespace std::literals; // or using namespace cxxomfort::fix
auto s2 = "Hello World"sv; // post-C++11 in cxxomfort, depending on compiler
Warning
The compiler might issue a warning or an error in C++11/14 mode that the literal ""sv is reserved. While this means the library is functioning correctly in that it can add the literal operator, it is compiler-dependent whether it is possible to disable this warning or error (see eg.: https://stackoverflow.com/questions/31509434/gcc-does-not-honor-pragma-gcc-diagnostic-to-silence-warnings ).
Note
To try and bypass this error use one of the following options:
  • add the cxxomfort include directory to system headers eg.: -isystem.
  • code intended to be cross-Standard compatible should use "sv" helper instead (see the next section).

"sv" helper

The helper function sv() creates a basic_string_view . It is provided to serve as a supplement to the "user-defined literal" ""sv where it is not available:

using cxxomfort::fix::sv; // or using namespace cxxomfort::fix
auto s1 = sv("Hello World");
using namespace std::literals;
auto s2 = "Hello World"sv;
static_assert( std::is_same< decltype(s1) , decltype(s2) >::value, "?");

"basic_string_view nonmember helpers"

C++20 and C++23 add new member functions to basic_string and basic_string_view. Since it is not possible in C++ to extend a class with new methods, and the interface for basic_string is already crap (see []), cxxomfort implements them as nonmember accessors à-la-<iterator>.

For relevant documentation see Nonmember helpers for string types .

"See Also"