diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 51bb4461e40db..84ef538437578 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -1309,6 +1309,10 @@ _BANNED_CPP_FUNCTIONS: Sequence[BanRule] = ( # Banned: Views # Banned: Range factories # Banned: Range adaptors + # Incidentally listed on + # https://en.cppreference.com/w/cpp/header/ranges: + 'enable_borrowed_range', + 'enable_view', # From https://en.cppreference.com/w/cpp/algorithm/ranges: # Constrained algorithms: non-modifying sequence operations 'all_of', diff --git a/base/containers/span.h b/base/containers/span.h index 21f9d39b915c6..a599327525a7b 100644 --- a/base/containers/span.h +++ b/base/containers/span.h @@ -37,6 +37,19 @@ template <typename T, typename InternalPtrType = T*> class span; +} // namespace base + +// Mark `span` as satisfying the `view` and `borrowed_range` concepts. This +// should be done before the definition of `span`, so that any inlined calls to +// range functionality use the correct specializations. +template <typename T, size_t N, typename Ptr> +inline constexpr bool std::ranges::enable_view<base::span<T, N, Ptr>> = true; +template <typename T, size_t N, typename Ptr> +inline constexpr bool + std::ranges::enable_borrowed_range<base::span<T, N, Ptr>> = true; + +namespace base { + namespace internal { template <typename From, typename To> @@ -1757,13 +1770,6 @@ constexpr std::ostream& operator<<(std::ostream& l, span<T, N> r) { } // namespace base -template <typename T, size_t N, typename Ptr> -inline constexpr bool - std::ranges::enable_borrowed_range<base::span<T, N, Ptr>> = true; - -template <typename T, size_t N, typename Ptr> -inline constexpr bool std::ranges::enable_view<base::span<T, N, Ptr>> = true; - // EXTENT returns the size of any type that can be converted to a |base::span| // with definite extent, i.e. everything that is a contiguous storage of some // sort with static size. Specifically, this works for std::array in a constexpr