#include <algorithm>
#include <cstddef>
#include <iostream>
#include <iterator>
#include <string>
class string_literal
{
char const* begin_;
char const* end_;
static constexpr std::size_t str_len(char const* begin, std::size_t len) {
return *begin == 0? len: str_len(begin + 1, len + 1);
}
public:
constexpr string_literal(char const* b)
: begin_(b), end_(b + str_len(b, 0)) {
}
constexpr string_literal(char const* b, char const* e)
: begin_(b), end_(e) {
}
constexpr char const* begin() const { return this->begin_; }
constexpr char const* end() const { return this->end_; }
bool operator== (std::string const& other) const {
return other.size() == std::size_t(std::distance(begin_, end_))
&& std::equal(begin_, end_, other.begin());
}
bool operator!= (std::string const& other) const {
return !(*this == other);
}
};
std::ostream& operator<< (std::ostream& out, string_literal const& s) {
std::ostream::sentry cerberos(out);
if (cerberos) {
out << '\'';
std::copy(s.begin(), s.end(), std::ostreambuf_iterator<char>(out));
out << '\'';
}
return out;
}
constexpr string_literal operator"" _sl(char const* begin, std::size_t)
{
return string_literal(begin);
}
constexpr string_literal hello_1("hello"_sl);
constexpr string_literal hello_2("hello");
int main()
{
std::cout << "hello\0world"_sl << '\n';
std::cout << hello_1 << '\n';
}
I2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRkZWY+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGl0ZXJhdG9yPgojaW5jbHVkZSA8c3RyaW5nPgoKY2xhc3Mgc3RyaW5nX2xpdGVyYWwKewogICAgY2hhciBjb25zdCogYmVnaW5fOwogICAgY2hhciBjb25zdCogZW5kXzsKICAgIHN0YXRpYyBjb25zdGV4cHIgc3RkOjpzaXplX3Qgc3RyX2xlbihjaGFyIGNvbnN0KiBiZWdpbiwgc3RkOjpzaXplX3QgbGVuKSB7CiAgICAgICAgcmV0dXJuICpiZWdpbiA9PSAwPyBsZW46IHN0cl9sZW4oYmVnaW4gKyAxLCBsZW4gKyAxKTsKICAgIH0KcHVibGljOgogICAgY29uc3RleHByIHN0cmluZ19saXRlcmFsKGNoYXIgY29uc3Q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