Skip to content

Instantly share code, notes, and snippets.

@s3rvac
Created March 29, 2015 11:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save s3rvac/cffd945c02014e1a6b74 to your computer and use it in GitHub Desktop.
Save s3rvac/cffd945c02014e1a6b74 to your computer and use it in GitHub Desktop.
Emulation of the standard std::string literal from C++14 in C++11.
// $ g++ -std=c++11 -pedantic -Wall -Wextra cpp11-string-literal.cpp -o cpp11-string-literal
// $ ./cpp11-string-literal
#include <string>
// Emulates the standard std::string literal ("..."s) from C++14. Since 's' is
// reserved by the standard, we have to use '_s' instead of 's'.
std::string operator "" _s(const char *str, size_t length) {
return std::string(str, length);
}
int main() {
std::string s1 = "abc\x00xyz"; // "abc"
std::string s2 = "abc\x00xyz"_s; // "abc\x00xyz"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment