Created
March 29, 2015 11:28
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// $ 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