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

Backports related to Standard header <string>

// or as part of:

Interfaces

Interfaces defined in this section:

Interfaces not in std:

"s" user-defined literal

C++14 onwards defines operator"" s as the user-defined literal to create basic_string objects. The cxxomfort library backports the string and wstring capable versions to C++11, directly into namespace std (as std::literals::s).

using namespace std::literals; // or using namespace cxxomfort::fix
auto s2 = L"Hello World"s; // is a std::wstring
Warning
The compiler might issue a warning or an error in C++11 mode that the literal ""s 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::s() instead (see the next section).

"s" helper

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

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

"basic_string nonmember helpers"

C++20 adds 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