diff --git a/chromium_src/base/types/zip.h b/chromium_src/base/types/zip.h deleted file mode 100644 index 6cce72b8597..00000000000 --- a/chromium_src/base/types/zip.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) 2024 The Brave Authors. All rights reserved. -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at https://mozilla.org/MPL/2.0/. - -// Copyright 2024 The Chromium Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef BRAVE_CHROMIUM_SRC_BASE_TYPES_ZIP_H_ -#define BRAVE_CHROMIUM_SRC_BASE_TYPES_ZIP_H_ - -#include -#include -#include -#include - -#include "base/check.h" -#include "base/compiler_specific.h" - -namespace base { - -namespace internal { - -template -class Zipper { - public: - constexpr explicit Zipper(Ranges&... ranges LIFETIME_BOUND) noexcept - : ranges_(ranges...) {} - - // A sentinel used by the iterator to constrain the comparison to make sure it - // has the proper end of each range. - struct ZipEnd {}; - - class iterator { - public: - using value_type = std::tuple< - std::remove_cv_t()))>...>; - using reference = value_type; - using element_type = value_type; - using difference_type = std::ptrdiff_t; - using pointer = void; - // TODO(https://crbug.com/377940847): This could be improved going forward - // to select a better iterator category, based on the common denominator of - // the union of iterators, for instance output iterators, etc. - using iterator_category = std::input_iterator_tag; - using iterator_concept = std::input_iterator_tag; - - constexpr iterator& operator++() noexcept LIFETIME_BOUND { - advance(std::index_sequence_for{}); - return *this; - } - - constexpr auto operator*() const noexcept LIFETIME_BOUND { - return deref(std::index_sequence_for{}); - } - - // Determines if the iterator has reached the end, so a for-range loop bails - // out. - constexpr bool operator!=(ZipEnd) const noexcept LIFETIME_BOUND { - return has_more(std::index_sequence_for{}); - } - - private: - friend class Zipper; - - constexpr explicit iterator( - std::tuple()))...> begin - LIFETIME_BOUND, - std::tuple()))...> end - LIFETIME_BOUND) noexcept - : begin_(begin), end_(end) {} - - // Checks if any range has reached the end. - template - constexpr bool has_more(std::index_sequence) const { - return (... && (std::get(begin_) != std::get(end_))); - } - - template - constexpr void advance(std::index_sequence) LIFETIME_BOUND { - CHECK(operator!=(ZipEnd())); - // SAFETY: The increment is safe as it has been just CHECKed so it is - // guaranteed to be inside [begin_, end_). - UNSAFE_BUFFERS((++std::get(begin_), ...)); - } - - template - constexpr value_type deref(std::index_sequence) const - LIFETIME_BOUND { - return {*std::get(begin_)...}; - } - - std::tuple()))...> begin_; - std::tuple()))...> end_; - }; - - constexpr iterator begin() noexcept LIFETIME_BOUND { - return begin_impl(std::index_sequence_for{}); - } - - constexpr ZipEnd end() noexcept { return ZipEnd(); } - - private: - template - constexpr iterator begin_impl(std::index_sequence) LIFETIME_BOUND { - return iterator(std::make_tuple(std::begin(std::get(ranges_))...), - std::make_tuple(std::end(std::get(ranges_))...)); - } - - std::tuple ranges_; -}; - -} // namespace internal - -// Zipping utility that allows iterating over multiple ranges in lockstep. -// -// Example: -// -// std::vector a = {1, 2, 3}; -// std::vector b = {4.5, 5.5, 6.5}; -// std::vector c = {"x", "y", "z"}; -// for (auto [x, y, z] : zip(a, b, c)) { -// LOG(INFO) << x << " " << y << " " << z; -// } -// -// Zipping will carry on until one of the ranges run out, at which the loop will -// bail. -template -constexpr internal::Zipper zip(Ranges&... ranges LIFETIME_BOUND) { - return internal::Zipper(ranges...); -} - -} // namespace base - -#endif // BRAVE_CHROMIUM_SRC_BASE_TYPES_ZIP_H_ diff --git a/chromium_src/check_chromium_src_config.json5 b/chromium_src/check_chromium_src_config.json5 index 80c78e7c809..a968ea998a3 100644 --- a/chromium_src/check_chromium_src_config.json5 +++ b/chromium_src/check_chromium_src_config.json5 @@ -17,7 +17,6 @@ // Please, keep in alphabetical order. "path_excludes": [ "base/feature_override.h", - "base/types/zip.h", "check_chromium_src_config.json5", "chrome/browser/devtools/url_constants_unittest.cc", "chrome/browser/history/history_utils_unittest.cc",