Commit 21f20989 authored by Soren Lassen's avatar Soren Lassen Committed by Peter Griess

Support constexpr StringPiece.

Test Plan: fbconfig folly/test --platform=gcc-4.8.1-glibc-2.17 && fbmake dbg _bin/folly/test/range_test && _bin/folly/test/range_test

Reviewed By: tudorb@fb.com

FB internal diff: D989142
parent 14fde8ae
......@@ -152,8 +152,8 @@ public:
: b_(start), e_(start + size) { }
// Works only for Range<const char*>
/* implicit */ Range(Iter str)
: b_(str), e_(b_ + strlen(str)) {}
/* implicit */ constexpr Range(Iter str)
: b_(str), e_(str + strlen(str)) {}
// Works only for Range<const char*>
/* implicit */ Range(const std::string& str)
: b_(str.data()), e_(b_ + str.size()) {}
......
......@@ -290,6 +290,16 @@ TEST(StringPiece, InvalidRange) {
EXPECT_THROW(a.subpiece(6), std::out_of_range);
}
constexpr char helloArray[] = "hello";
TEST(StringPiece, Constexpr) {
constexpr StringPiece hello1("hello");
EXPECT_EQ("hello", hello1);
constexpr StringPiece hello2(helloArray);
EXPECT_EQ("hello", hello2);
}
TEST(qfind, UInt32_Ranges) {
vector<uint32_t> a({1, 2, 3, 260, 5});
vector<uint32_t> b({2, 3, 4});
......
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