Commit e3ed6d7c authored by Yiding Jia's avatar Yiding Jia Committed by Facebook Github Bot

Fix folly::Range compile error when using non-POD value type, c++17, and libc++

Summary:
When using clang, libc++, and c++17, merely mentioning a Range with a non-pod
value-type will give a compile error due to a static assert while attemption to
instantiate a basic_string_view. Using a StrictConjunction seems to fix this
issue.

Reviewed By: yfeldblum

Differential Revision: D10472408

fbshipit-source-id: 28d50d0a99994049bfcd9ac29168fb2f1d1c5867
parent 47039856
......@@ -543,9 +543,10 @@ class Range {
template <
typename Tgt,
std::enable_if_t<
std::is_same<Tgt, StringViewType>::value &&
std::is_constructible<StringViewType, Iter const&, size_type>::
value,
StrictConjunction<
std::is_same<Tgt, StringViewType>,
std::is_constructible<StringViewType, Iter const&, size_type>>::
value,
int> = 0>
constexpr operator Tgt() const noexcept(
std::is_nothrow_constructible<Tgt, Iter const&, size_type>::value) {
......
......@@ -1620,4 +1620,16 @@ TEST(StringPiece, StringViewConversion) {
TrickierTarget tt3(deqRange);
EXPECT_EQ(tt3.which, 1);
}
namespace {
// Range with non-pod value type should not cause compile errors.
class NonPOD {
public:
NonPOD() {}
};
void test_func(Range<const NonPOD*>) {}
} // anonymous namespace
#endif
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