/sz_ref

Primary LanguageC++

sz_ref

A sometimes handy alternative to boost::string_ref.

Note: I've started a more modern version of this (fisherro::zstring_view) within cpplibxml2

What is it?

Like boost::string_ref† (and built on top of it), but...

  • Does have a c_str function.
  • Can only be constructed from a NUL-terminated string. (Note that std::string counts.)
  • Cannot be constructed from a pointer and a length.
  • Lacks substr.
  • Lacks remove_suffix.

†Or std::experimental::string_view. Not much like gsl::string_view.

Why?

Because I want most of the benefits of boost::string_ref, but with the ability to write...

void legacy_function(const char*);

void my_function(zstring_ref z)
{
    legacy_function(z.c_str());
}

How?

It is just a header: sz_ref.hpp. It requires boost::string_ref.