return Data[Index];
}
+ /// Disallow accidental assignment from a temporary.
+ ///
+ /// The declaration here is extra complicated so that "arrayRef = {}"
+ /// continues to select the move assignment operator.
+ template <typename U>
+ typename std::enable_if<std::is_same<U, T>::value, ArrayRef<T>>::type &
+ operator=(U &&Temporary) = delete;
+
+ /// Disallow accidental assignment from a temporary.
+ ///
+ /// The declaration here is extra complicated so that "arrayRef = {}"
+ /// continues to select the move assignment operator.
+ template <typename U>
+ typename std::enable_if<std::is_same<U, T>::value, ArrayRef<T>>::type &
+ operator=(std::initializer_list<U>) = delete;
+
/// @}
/// @name Expensive Operations
/// @{
!std::is_convertible<ArrayRef<volatile int *>, ArrayRef<int *>>::value,
"Removing volatile");
+// Check that we can't accidentally assign a temporary location to an ArrayRef.
+// (Unfortunately we can't make use of the same thing with constructors.)
+static_assert(
+ !std::is_assignable<ArrayRef<int *>, int *>::value,
+ "Assigning from single prvalue element");
+static_assert(
+ !std::is_assignable<ArrayRef<int *>, int * &&>::value,
+ "Assigning from single xvalue element");
+static_assert(
+ std::is_assignable<ArrayRef<int *>, int * &>::value,
+ "Assigning from single lvalue element");
+static_assert(
+ !std::is_assignable<ArrayRef<int *>, std::initializer_list<int *>>::value,
+ "Assigning from an initializer list");
+
namespace {
TEST(ArrayRefTest, AllocatorCopy) {
ArgTest12({1, 2});
}
+TEST(ArrayRefTest, EmptyInitializerList) {
+ ArrayRef<int> A = {};
+ EXPECT_TRUE(A.empty());
+
+ A = {};
+ EXPECT_TRUE(A.empty());
+}
+
// Test that makeArrayRef works on ArrayRef (no-op)
TEST(ArrayRefTest, makeArrayRef) {
static const int A1[] = {1, 2, 3, 4, 5, 6, 7, 8};