[libcxx-commits] [libcxx] [libc++][ranges] implement `ranges::elements_of` (PR #91414)

Xiaoyang Liu via libcxx-commits libcxx-commits at lists.llvm.org
Wed Oct 16 21:30:01 PDT 2024


================
@@ -0,0 +1,62 @@
+// -*- 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_ELEMENTS_OF_H
+#define _LIBCPP___RANGES_ELEMENTS_OF_H
+
+#include <__config>
+#include <__memory/allocator.h>
+#include <__ranges/concepts.h>
+#include <__utility/forward.h>
+#include <cstddef>
+
+#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 <range _Range, class _Allocator = allocator<byte>>
+struct elements_of {
+  _LIBCPP_NO_UNIQUE_ADDRESS _Range range;
+  _LIBCPP_NO_UNIQUE_ADDRESS _Allocator allocator = _Allocator();
+
+#  if !defined(__cpp_aggregate_paren_init)
+  // This explicit constructor is required because AppleClang 15 hasn't
+  // implemented P0960R3.
+  template <std::ranges::range _Range2, class _Allocator2 = std::allocator<byte>>
----------------
xiaoyang-sde wrote:

Apple clang 15 is unable to find these types unless they are fully qualified:

```
/Users/xiaoyang/Developer/llvm-project/build-apple/libcxx/test-suite-install/include/c++/v1/__ranges/elements_of.h:40:13: error: unknown type name 'range'
  template <range _Range2, class _Allocator2 = allocator<byte>>

/Users/xiaoyang/Developer/llvm-project/build-apple/libcxx/test-suite-install/include/c++/v1/__ranges/elements_of.h:40:48: error: no template named 'allocator'; did you mean '::std::allocator'?
  template <range _Range2, class _Allocator2 = allocator<byte>>
```

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


More information about the libcxx-commits mailing list