-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[libc++] Implements ranges::enable_borrowed_range
This is the initial patch to implement ranges in libc++. Implements parts of: - P0896R4 One Ranges Proposal - P1870 forwarding-range is too subtle - LWG3379 in several library names is misleading Reviewed By: ldionne, #libc, cjdb, zoecarver, Quuxplusone Differential Revision: https://reviews.llvm.org/D90999
- Loading branch information
Showing
18 changed files
with
379 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// -*- C++ -*- | ||
//===------------------ __ranges/enable_borrowed_range.h ------------------===// | ||
// | ||
// 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_ENABLE_BORROWED_RANGE_H | ||
#define _LIBCPP___RANGES_ENABLE_BORROWED_RANGE_H | ||
|
||
// These customization variables are used in <span> and <string_view>. The | ||
// separate header is used to avoid including the entire <ranges> header in | ||
// <span> and <string_view>. | ||
|
||
#include <__config> | ||
|
||
#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 > 17 && !defined(_LIBCPP_HAS_NO_RANGES) | ||
|
||
namespace ranges | ||
{ | ||
|
||
// [range.range], ranges | ||
|
||
template <class> | ||
inline constexpr bool enable_borrowed_range = false; | ||
|
||
} // namespace ranges | ||
|
||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP___RANGES_ENABLE_BORROWED_RANGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// -*- C++ -*- | ||
//===--------------------------- ranges -----------------------------------===// | ||
// | ||
// 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 | ||
#define _LIBCPP_RANGES | ||
|
||
/* | ||
#include <compare> // see [compare.syn] | ||
#include <initializer_list> // see [initializer.list.syn] | ||
#include <iterator> // see [iterator.synopsis] | ||
namespace std::ranges { | ||
// [range.range], ranges | ||
template<class T> | ||
inline constexpr bool enable_borrowed_range = false; | ||
} | ||
*/ | ||
|
||
#include <__config> | ||
#include <__ranges/enable_borrowed_range.h> | ||
#include <compare> // Required by the standard. | ||
#include <initializer_list> // Required by the standard. | ||
#include <iterator> // Required by the standard. | ||
#include <type_traits> | ||
#include <version> | ||
|
||
#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 > 17 && !defined(_LIBCPP_HAS_NO_RANGES) | ||
|
||
#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES) | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
_LIBCPP_POP_MACROS | ||
|
||
#endif // _LIBCPP_RANGES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
libcxx/test/libcxx/inclusions/ranges.inclusions.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// WARNING: This test was generated by generate_header_inclusion_tests.py | ||
// and should not be edited manually. | ||
// | ||
// clang-format off | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
|
||
// <ranges> | ||
|
||
// Test that <ranges> includes all the other headers it's supposed to. | ||
|
||
#include <ranges> | ||
#include "test_macros.h" | ||
|
||
#if !defined(_LIBCPP_RANGES) | ||
# error "<ranges> was expected to define _LIBCPP_RANGES" | ||
#endif | ||
#if TEST_STD_VER > 17 && !defined(_LIBCPP_COMPARE) | ||
# error "<ranges> should include <compare> in C++20 and later" | ||
#endif | ||
#if TEST_STD_VER > 03 && !defined(_LIBCPP_INITIALIZER_LIST) | ||
# error "<ranges> should include <initializer_list> in C++20 and later" | ||
#endif | ||
#if !defined(_LIBCPP_ITERATOR) | ||
# error "<ranges> should include <iterator> in C++20 and later" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// <ranges> | ||
|
||
#include <ranges> | ||
|
||
#include "test_macros.h" | ||
|
||
#ifndef _LIBCPP_VERSION | ||
#error _LIBCPP_VERSION not defined | ||
#endif | ||
|
||
// Required for MSVC internal test runner compatibility. | ||
int main(int, char**) { return 0; } |
28 changes: 28 additions & 0 deletions
28
libcxx/test/std/containers/views/enable_borrowed_range.compile.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// UNSUPPORTED: c++03, c++11, c++14, c++17 | ||
// UNSUPPORTED: libcpp-no-concepts | ||
|
||
// <span> | ||
|
||
// template<class ElementType, size_t Extent> | ||
// inline constexpr bool ranges::enable_borrowed_range< | ||
// span<ElementType, Extent>> = true; | ||
|
||
#include <span> | ||
|
||
#include "test_macros.h" | ||
|
||
void test() { | ||
static_assert(std::ranges::enable_borrowed_range<std::span<int, 0> >); | ||
static_assert(std::ranges::enable_borrowed_range<std::span<int, 42> >); | ||
static_assert(std::ranges::enable_borrowed_range<std::span<int, std::dynamic_extent> >); | ||
static_assert(!std::ranges::enable_borrowed_range<std::span<int, 42>&>); | ||
static_assert(!std::ranges::enable_borrowed_range<std::span<int, 42> const>); | ||
} |
75 changes: 75 additions & 0 deletions
75
...x/test/std/language.support/support.limits/support.limits.general/ranges.version.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// WARNING: This test was generated by generate_feature_test_macro_components.py | ||
// and should not be edited manually. | ||
// | ||
// clang-format off | ||
|
||
// <ranges> | ||
|
||
// Test the feature test macros defined by <ranges> | ||
|
||
/* Constant Value | ||
__cpp_lib_ranges 201811L [C++20] | ||
*/ | ||
|
||
#include <ranges> | ||
#include "test_macros.h" | ||
|
||
#if TEST_STD_VER < 14 | ||
|
||
# ifdef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should not be defined before c++20" | ||
# endif | ||
|
||
#elif TEST_STD_VER == 14 | ||
|
||
# ifdef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should not be defined before c++20" | ||
# endif | ||
|
||
#elif TEST_STD_VER == 17 | ||
|
||
# ifdef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should not be defined before c++20" | ||
# endif | ||
|
||
#elif TEST_STD_VER == 20 | ||
|
||
# if !defined(_LIBCPP_VERSION) | ||
# ifndef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should be defined in c++20" | ||
# endif | ||
# if __cpp_lib_ranges != 201811L | ||
# error "__cpp_lib_ranges should have the value 201811L in c++20" | ||
# endif | ||
# else // _LIBCPP_VERSION | ||
# ifdef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should not be defined because it is unimplemented in libc++!" | ||
# endif | ||
# endif | ||
|
||
#elif TEST_STD_VER > 20 | ||
|
||
# if !defined(_LIBCPP_VERSION) | ||
# ifndef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should be defined in c++2b" | ||
# endif | ||
# if __cpp_lib_ranges != 201811L | ||
# error "__cpp_lib_ranges should have the value 201811L in c++2b" | ||
# endif | ||
# else // _LIBCPP_VERSION | ||
# ifdef __cpp_lib_ranges | ||
# error "__cpp_lib_ranges should not be defined because it is unimplemented in libc++!" | ||
# endif | ||
# endif | ||
|
||
#endif // TEST_STD_VER > 20 | ||
|
||
int main(int, char**) { return 0; } |
Oops, something went wrong.