pw_span: Update to latest version from Chromium

- Make updates to more closely match the C++20 draft standard:
  * Remove swap.
  * Use size_type instead of index_type.
- Add comment noting that pw_span does not fully follow Pigweed's style
  guide in order to minimize differences from the Chromium version.

Fixed: 10

Change-Id: Ic54613087c20faceaa88fa99d52043e466903200
diff --git a/pw_span/public/pw_span/span.h b/pw_span/public/pw_span/span.h
index bcc8a5d..1a5e1d8 100644
--- a/pw_span/public/pw_span/span.h
+++ b/pw_span/public/pw_span/span.h
@@ -1,4 +1,4 @@
-// Copyright 2019 The Pigweed Authors
+// Copyright 2020 The Pigweed Authors
 //
 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
 // use this file except in compliance with the License. You may obtain a copy of
@@ -19,7 +19,10 @@
 // a template parameter, so this class can be used to without stating its size.
 //
 // This file a modified version of base::span from Chromium:
-// https://chromium.googlesource.com/chromium/src/+/66a87fb20314bc73ff8466f12e28899ae28c1c9d/base/containers/span.h
+//   https://chromium.googlesource.com/chromium/src/+/ef71f9c29f0dc6eddae474879c4ca5232ca93a6c/base/containers/span.h
+//
+// In order to minimize changes from the original, this file does NOT fully
+// adhere to Pigweed's style guide.
 //
 // A few changes were made to the Chromium version of span. These include:
 //   - Use std::data and std::size instead of base::* versions.
@@ -142,7 +145,6 @@
  public:
   constexpr explicit ExtentStorage(size_t /* size */) noexcept {}
   constexpr size_t size() const noexcept { return Extent; }
-  constexpr void swap(ExtentStorage& /* other */) noexcept {}
 };
 
 // Specialization of ExtentStorage for dynamic extents, which do require
@@ -151,12 +153,6 @@
 struct ExtentStorage<dynamic_extent> {
   constexpr explicit ExtentStorage(size_t size) noexcept : size_(size) {}
   constexpr size_t size() const noexcept { return size_; }
-  constexpr void swap(ExtentStorage& other) noexcept {
-    // Note: Can't use std::swap here, as it's not constexpr prior to C++20.
-    size_t size = size_;
-    size_ = other.size_;
-    other.size_ = size;
-  }
 
  private:
   size_t size_;
@@ -243,7 +239,7 @@
  public:
   using element_type = T;
   using value_type = std::remove_cv_t<T>;
-  using index_type = size_t;
+  using size_type = size_t;
   using difference_type = ptrdiff_t;
   using pointer = T*;
   using reference = T&;
@@ -251,7 +247,7 @@
   using const_iterator = const T*;
   using reverse_iterator = std::reverse_iterator<iterator>;
   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
-  static constexpr index_type extent = Extent;
+  static constexpr size_t extent = Extent;
 
   // [span.cons], span constructors, copy, assignment, and destructor
   constexpr span() noexcept : ExtentStorage(0), data_(nullptr) {
@@ -429,15 +425,6 @@
     return const_reverse_iterator(cbegin());
   }
 
-  constexpr void swap(span& other) noexcept {
-    // Note: Can't use std::swap here, as it's not constexpr prior to C++20.
-    T* data = data_;
-    data_ = other.data_;
-    other.data_ = data;
-
-    ExtentStorage::swap(other);
-  }
-
  private:
   T* data_;
 };
@@ -462,11 +449,6 @@
   return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
 }
 
-template <typename T, size_t X>
-constexpr void swap(span<T, X>& lhs, span<T, X>& rhs) noexcept {
-  lhs.swap(rhs);
-}
-
 // Type-deducing helpers for constructing a span.
 // Pigweed: Instead of a make_span function, provide the deduction guides
 //     specified in the C++20 standard.
diff --git a/pw_span/span_test.cc b/pw_span/span_test.cc
index bf973fa..f4770f6 100644
--- a/pw_span/span_test.cc
+++ b/pw_span/span_test.cc
@@ -1,4 +1,4 @@
-// Copyright 2019 The Pigweed Authors
+// Copyright 2020 The Pigweed Authors
 //
 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
 // use this file except in compliance with the License. You may obtain a copy of
@@ -16,8 +16,10 @@
 // Modifications are noted with "Pigweed:" comments.
 //
 // Original file:
-//   https://chromium.googlesource.com/chromium/src/+/409610fca8c94015bd216768c6c15cd5a3564826/base/containers/span_unittest.cc
+//   https://chromium.googlesource.com/chromium/src/+/ef71f9c29f0dc6eddae474879c4ca5232ca93a6c/base/containers/span_unittest.cc
 //
+// In order to minimize changes from the original, this file does NOT fully
+// adhere to Pigweed's style guide.
 #include "pw_span/span.h"
 
 #include <algorithm>
@@ -1018,44 +1020,6 @@
                 "span.back() does not refer to the same element as kArray[4]");
 }
 
-TEST(SpanTest, Swap) {
-  {
-    static int kArray1[] = {1, 1};
-    static int kArray2[] = {1, 2};
-    span<const int, 2> static_span1(kArray1);
-    span<const int, 2> static_span2(kArray2);
-
-    EXPECT_EQ(kArray1, static_span1.data());
-    EXPECT_EQ(kArray2, static_span2.data());
-
-    swap(static_span1, static_span2);
-
-    EXPECT_EQ(kArray2, static_span1.data());
-    EXPECT_EQ(kArray1, static_span2.data());
-  }
-
-  {
-    static int kArray1[] = {1};
-    static int kArray2[] = {1, 2};
-    span<const int> dynamic_span1(kArray1);
-    span<const int> dynamic_span2(kArray2);
-
-    EXPECT_EQ(kArray1, dynamic_span1.data());
-    EXPECT_EQ(1u, dynamic_span1.size());
-
-    EXPECT_EQ(kArray2, dynamic_span2.data());
-    EXPECT_EQ(2u, dynamic_span2.size());
-
-    swap(dynamic_span1, dynamic_span2);
-
-    EXPECT_EQ(kArray2, dynamic_span1.data());
-    EXPECT_EQ(2u, dynamic_span1.size());
-
-    EXPECT_EQ(kArray1, dynamic_span2.data());
-    EXPECT_EQ(1u, dynamic_span2.size());
-  }
-}
-
 // Pigweed: This test uses gMock features not yet supported in Pigweed.
 #if 0
 TEST(SpanTest, Iterator) {
@@ -1402,16 +1366,12 @@
 TEST(SpanTest, OutOfBoundsDeath) {
   constexpr span<int, 0> kEmptySpan;
   ASSERT_DEATH_IF_SUPPORTED(kEmptySpan[0], "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.begin()[0], "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.end()[0], "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.first(1), "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.last(1), "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptySpan.subspan(1), "");
 
   constexpr span<int> kEmptyDynamicSpan;
   ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan[0], "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.begin()[0], "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.end()[0], "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.front(), "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.first(1), "");
   ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.last(1), "");
@@ -1422,10 +1382,8 @@
   constexpr span<const int> kNonEmptyDynamicSpan(kArray);
   EXPECT_EQ(3U, kNonEmptyDynamicSpan.size());
   ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan[4], "");
-  ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.begin()[-1], "");
-  ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.begin()[3], "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.subspan(10), "");
-  ASSERT_DEATH_IF_SUPPORTED(kEmptyDynamicSpan.subspan(1, 7), "");
+  ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.subspan(10), "");
+  ASSERT_DEATH_IF_SUPPORTED(kNonEmptyDynamicSpan.subspan(1, 7), "");
 }
 
 // Pigweed: These tests use CheckedContiguousConstIterator, which isn't used in