Skip to content

Commit

Permalink
[libc++] Define namespace views in its own detail header.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Arthur O'Dwyer committed Feb 4, 2022
1 parent b35be6f commit 44cdca3
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
1 change: 1 addition & 0 deletions libcxx/include/CMakeLists.txt
Expand Up @@ -351,6 +351,7 @@ set(files
__ranges/take_view.h
__ranges/transform_view.h
__ranges/view_interface.h
__ranges/views.h
__split_buffer
__std_stream
__string
Expand Down
35 changes: 35 additions & 0 deletions libcxx/include/__ranges/views.h
@@ -0,0 +1,35 @@
// -*- 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_VIEWS
#define _LIBCPP___RANGES_VIEWS

#include <__config>

#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)

namespace ranges {

namespace views { }

} // namespace ranges

namespace views = ranges::views;

#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)

_LIBCPP_END_NAMESPACE_STD

#endif // _LIBCPP___RANGES_VIEWS
1 change: 1 addition & 0 deletions libcxx/include/module.modulemap
Expand Up @@ -817,6 +817,7 @@ module std [system] {
export functional.__functional.perfect_forward
}
module view_interface { private header "__ranges/view_interface.h" }
module views { private header "__ranges/views.h" }
}
}
module ratio {
Expand Down
11 changes: 1 addition & 10 deletions libcxx/include/ranges
Expand Up @@ -258,6 +258,7 @@ namespace std {
#include <__ranges/take_view.h>
#include <__ranges/transform_view.h>
#include <__ranges/view_interface.h>
#include <__ranges/views.h>
#include <compare> // Required by the standard.
#include <initializer_list> // Required by the standard.
#include <iterator> // Required by the standard.
Expand All @@ -267,16 +268,6 @@ namespace std {
# pragma GCC system_header
#endif

_LIBCPP_BEGIN_NAMESPACE_STD

#if !defined(_LIBCPP_HAS_NO_CONCEPTS)

namespace views = ranges::views;

#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)

_LIBCPP_END_NAMESPACE_STD

#endif // !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)

#endif // _LIBCPP_RANGES
@@ -0,0 +1,15 @@
//===----------------------------------------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

// REQUIRES: modules-build

// WARNING: This test was generated by 'generate_private_header_tests.py'
// and should not be edited manually.

// expected-error@*:* {{use of private header from outside its module: '__ranges/views.h'}}
#include <__ranges/views.h>

0 comments on commit 44cdca3

Please sign in to comment.