Skip to content

Instantly share code, notes, and snippets.

@tuket
Last active November 14, 2023 11:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuket/d4c09344a2173b1acc1651d416733fbd to your computer and use it in GitHub Desktop.
Save tuket/d4c09344a2173b1acc1651d416733fbd to your computer and use it in GitHub Desktop.
proposal for ztring_view
#include <string>
#include <string_view>
struct zstring_view : public std::string_view {
zstring_view() {}
zstring_view(std::string_view s) = delete;
zstring_view(const char* s) : std::string_view(s) {}
zstring_view(const std::string& s) : std::string_view(s) {}
operator const char* ()const { return data(); }
operator std::string()const { return std::string(begin(), end()); }
const char* c_str()const { return data(); }
};
void foo_string(const std::string& s) {}
void foo_string_view(std::string_view s) {}
int main()
{
std::string myString = "myString";
std::string_view myStringView = "myStringView";
zstring_view a("a");
zstring_view b;
b = myString;
b = a;
//zstring_view c = myStringView; // ERROR
// b = myStringView; // ERROR
foo_string(a);
foo_string_view(a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment