#ifndef FOLLY_PORTABILITY_H_
#define FOLLY_PORTABILITY_H_
+#include <string.h>
+
#include <cstddef>
#ifndef FOLLY_NO_CONFIG
#endif
}
+constexpr size_t constexpr_strlen(const char* s) {
+#if defined(__clang__)
+ return __builtin_strlen(s);
+#else
+ return strlen(s);
+#endif
}
+} // namespace folly
#endif // FOLLY_PORTABILITY_H_
constexpr Range(Iter start, size_t size)
: b_(start), e_(start + size) { }
-#if FOLLY_HAVE_CONSTEXPR_STRLEN
template <class T = Iter, typename detail::IsCharPointer<T>::type = 0>
constexpr /* implicit */ Range(Iter str)
- : b_(str), e_(str + strlen(str)) {}
-#else
- template <class T = Iter, typename detail::IsCharPointer<T>::type = 0>
- /* implicit */ Range(Iter str)
- : b_(str), e_(str + strlen(str)) {}
-#endif
+ : b_(str), e_(str + constexpr_strlen(str)) {}
+
template <class T = Iter, typename detail::IsCharPointer<T>::const_type = 0>
/* implicit */ Range(const std::string& str)
: b_(str.data()), e_(b_ + str.size()) {}
EXPECT_THROW(a.subpiece(6), std::out_of_range);
}
-#if FOLLY_HAVE_CONSTEXPR_STRLEN
constexpr char helloArray[] = "hello";
TEST(StringPiece, Constexpr) {
constexpr StringPiece hello2(helloArray);
EXPECT_EQ("hello", hello2);
}
-#endif
TEST(StringPiece, Prefix) {
StringPiece a("hello");