From 7756a098ce442cca96e32dd6fe14372284b3402f Mon Sep 17 00:00:00 2001 From: Philip Pronin Date: Thu, 17 Jul 2014 13:05:02 -0700 Subject: [PATCH] make folly::Range literal type Summary: 7.1.5 [dcl.constexpr] / 9 (N3337) requires type to be literal to use it in `constexpr` object declaration (seems to be not enforced by GCC 4.8?) Currently `folly::Range<>` fails one of the requirements: * is an aggregate type, or has at least one constexpr constructor or constructor template that is not a copy or move constructor, Test Plan: fbconfig folly/test:range_test && fbmake runtests_opt -j32 Reviewed By: lucian@fb.com Subscribers: chaoyc, search-fbcode-diffs@, unicorn-diffs@ FB internal diff: D1441646 Tasks: 4720575 --- folly/Range.h | 12 ++++++------ folly/test/RangeTest.cpp | 9 ++++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/folly/Range.h b/folly/Range.h index f5569865..4d7b1bcb 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -163,21 +163,21 @@ public: static const size_type npos; // Works for all iterators - Range() : b_(), e_() { + constexpr Range() : b_(), e_() { } public: // Works for all iterators - Range(Iter start, Iter end) : b_(start), e_(end) { + constexpr Range(Iter start, Iter end) : b_(start), e_(end) { } // Works only for random-access iterators - Range(Iter start, size_t size) + constexpr Range(Iter start, size_t size) : b_(start), e_(start + size) { } #if FOLLY_HAVE_CONSTEXPR_STRLEN // Works only for Range - /* implicit */ constexpr Range(Iter str) + constexpr /* implicit */ Range(Iter str) : b_(str), e_(str + strlen(str)) {} #else // Works only for Range @@ -291,7 +291,7 @@ public: template ::value && std::is_convertible::value), int>::type = 0> - /* implicit */ Range(const Range& other) + constexpr /* implicit */ Range(const Range& other) : b_(other.begin()), e_(other.end()) { } @@ -302,7 +302,7 @@ public: (!std::is_same::value && !std::is_convertible::value && std::is_constructible::value), int>::type = 0> - explicit Range(const Range& other) + constexpr explicit Range(const Range& other) : b_(other.begin()), e_(other.end()) { } diff --git a/folly/test/RangeTest.cpp b/folly/test/RangeTest.cpp index 0bf328ab..78e881a1 100644 --- a/folly/test/RangeTest.cpp +++ b/folly/test/RangeTest.cpp @@ -19,16 +19,17 @@ #include +#include #include -#include #include -#include #include #include #include #include -#include +#include #include +#include +#include namespace folly { namespace detail { @@ -44,6 +45,8 @@ size_t qfind_first_byte_of_byteset(const StringPiece& haystack, using namespace folly; using namespace std; +static_assert(std::is_literal_type::value, ""); + BOOST_CONCEPT_ASSERT((boost::RandomAccessRangeConcept)); TEST(StringPiece, All) { -- 2.34.1