[libcxx-commits] [libcxx] [libcxx] cbegin should always return a constant iterator (PR #99915)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 9 07:27:32 PDT 2024


================
@@ -0,0 +1,205 @@
+// -*- C++ -*-
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBCPP___RANGES_AS_CONST_VIEW_H
+#define _LIBCPP___RANGES_AS_CONST_VIEW_H
+
+#include <__concepts/constructible.h>
+#include <__iterator/concepts.h>
+#include <__ranges/all.h>
+#include <__ranges/concepts.h>
+#include <__ranges/const_access.h>
+#include <__ranges/empty_view.h>
+#include <__ranges/range_adaptor.h>
+#include <__ranges/ref_view.h>
+#include <__ranges/size.h>
+#include <__ranges/view_interface.h>
+#include <__type_traits/is_specialization.h>
+#include <__utility/auto_cast.h>
+#include <__utility/move.h>
+#include <__utility/pair.h>
+#include <cstddef>
+#include <span>
+
+#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+#  pragma GCC system_header
+#endif
+
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+#if _LIBCPP_STD_VER >= 23
+
+namespace ranges {
+template <input_range _View>
+  requires view<_View>
+class as_const_view : public view_interface<as_const_view<_View>> {
+  _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View();
+
+public:
+  _LIBCPP_HIDE_FROM_ABI as_const_view()
+    requires default_initializable<_View>
+  = default;
+  _LIBCPP_HIDE_FROM_ABI constexpr explicit as_const_view(_View __base) : __base_(std::move(__base)) {}
----------------
ldionne wrote:

Similar comment for `explicit`. Here you can have a test like `static_assert(is_constructible && !is_convertible)`.

https://github.com/llvm/llvm-project/pull/99915


More information about the libcxx-commits mailing list