Commit cae89fc3 authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Support u8 as char8_t in StringPiece literals

Summary: In C++20, u8 prefixed strings are typed as `char8_t` not `char`, so we need to support that in `StringPiece`.

Reviewed By: yfeldblum

Differential Revision: D19822967

fbshipit-source-id: c3441ba718b40f0781766d4a80c3432b4514a35c
parent 861dfc74
......@@ -1523,6 +1523,14 @@ constexpr Range<char const*> operator"" _sp(
return Range<char const*>(str, len);
}
#if __cpp_char8_t >= 201811L
constexpr Range<char8_t const*> operator"" _sp(
char8_t const* str,
size_t len) noexcept {
return Range<char8_t const*>(str, len);
}
#endif
constexpr Range<char16_t const*> operator"" _sp(
char16_t const* str,
size_t len) noexcept {
......
......@@ -1430,7 +1430,11 @@ TEST(Range, LiteralSuffix) {
constexpr StringPiece piece = "hello";
EXPECT_EQ(literalPiece, piece);
constexpr auto literalPiece8 = u8"hello"_sp;
#if __cpp_char8_t >= 201811L
constexpr Range<char8_t const*> piece8 = u8"hello";
#else
constexpr Range<char const*> piece8 = u8"hello";
#endif
EXPECT_EQ(literalPiece8, piece8);
constexpr auto literalPiece16 = u"hello"_sp;
constexpr Range<char16_t const*> piece16{u"hello", 5};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment