cxxomfort  rel.20210622
Simple backports for C++ - http://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

Fix (non-backport) interfaces:

"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 can add the backport correctly, it could be that the compiler is blocking its use. 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 be using cxxomfort::fix::sv() 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, "?");

See Also