Skip to content

Commit 44cdca3

Browse files
committed
[libc++] Define namespace views in its own detail header.
Discovered in the comments on D118748: we would like this namespace to exist anytime Ranges exists, regardless of whether concepts syntax is supported. Also, we'd like to fully granularize the <ranges> header, which means not putting any loose declarations at the top level. Differential Revision: https://reviews.llvm.org/D118809
1 parent b35be6f commit 44cdca3

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

libcxx/include/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ set(files
351351
__ranges/take_view.h
352352
__ranges/transform_view.h
353353
__ranges/view_interface.h
354+
__ranges/views.h
354355
__split_buffer
355356
__std_stream
356357
__string

libcxx/include/__ranges/views.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// -*- C++ -*-
2+
//===----------------------------------------------------------------------===//
3+
//
4+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5+
// See https://llvm.org/LICENSE.txt for license information.
6+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7+
//
8+
//===----------------------------------------------------------------------===//
9+
10+
#ifndef _LIBCPP___RANGES_VIEWS
11+
#define _LIBCPP___RANGES_VIEWS
12+
13+
#include <__config>
14+
15+
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
16+
# pragma GCC system_header
17+
#endif
18+
19+
_LIBCPP_BEGIN_NAMESPACE_STD
20+
21+
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
22+
23+
namespace ranges {
24+
25+
namespace views { }
26+
27+
} // namespace ranges
28+
29+
namespace views = ranges::views;
30+
31+
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
32+
33+
_LIBCPP_END_NAMESPACE_STD
34+
35+
#endif // _LIBCPP___RANGES_VIEWS

libcxx/include/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ module std [system] {
817817
export functional.__functional.perfect_forward
818818
}
819819
module view_interface { private header "__ranges/view_interface.h" }
820+
module views { private header "__ranges/views.h" }
820821
}
821822
}
822823
module ratio {

libcxx/include/ranges

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ namespace std {
258258
#include <__ranges/take_view.h>
259259
#include <__ranges/transform_view.h>
260260
#include <__ranges/view_interface.h>
261+
#include <__ranges/views.h>
261262
#include <compare> // Required by the standard.
262263
#include <initializer_list> // Required by the standard.
263264
#include <iterator> // Required by the standard.
@@ -267,16 +268,6 @@ namespace std {
267268
# pragma GCC system_header
268269
#endif
269270

270-
_LIBCPP_BEGIN_NAMESPACE_STD
271-
272-
#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
273-
274-
namespace views = ranges::views;
275-
276-
#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
277-
278-
_LIBCPP_END_NAMESPACE_STD
279-
280271
#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)
281272

282273
#endif // _LIBCPP_RANGES
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: modules-build
10+
11+
// WARNING: This test was generated by 'generate_private_header_tests.py'
12+
// and should not be edited manually.
13+
14+
// expected-error@*:* {{use of private header from outside its module: '__ranges/views.h'}}
15+
#include <__ranges/views.h>

0 commit comments

Comments
 (0)