From 21f209898954d32fc63d52143bd9481a6d64c274 Mon Sep 17 00:00:00 2001 From: Soren Lassen Date: Sat, 28 Sep 2013 17:53:52 -0700 Subject: [PATCH] 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 --- folly/Range.h | 4 ++-- folly/test/RangeTest.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/folly/Range.h b/folly/Range.h index 107bdb00..cabd9078 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -152,8 +152,8 @@ public: : b_(start), e_(start + size) { } // Works only for Range - /* 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 /* implicit */ Range(const std::string& str) : b_(str.data()), e_(b_ + str.size()) {} diff --git a/folly/test/RangeTest.cpp b/folly/test/RangeTest.cpp index 1ed678c8..445df424 100644 --- a/folly/test/RangeTest.cpp +++ b/folly/test/RangeTest.cpp @@ -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 a({1, 2, 3, 260, 5}); vector b({2, 3, 4}); -- 2.34.1