-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Implement ranges::contains #65148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
02e9afd
[libc++] Implement ranges::contains
ZijunZhaoCCK 55a6817
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 80c08f6
[libc++] Implement ranges::contains
ZijunZhaoCCK 34d8e29
[libc++] Implement ranges::contains
ZijunZhaoCCK 9db49dd
[libc++] Implement ranges::contains
ZijunZhaoCCK e0ea68c
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 54bccdd
[libc++] Implement ranges::contains
ZijunZhaoCCK 826bd98
[libc++] Implement ranges::contains
ZijunZhaoCCK 32cf818
[libc++] Implement ranges::contains
ZijunZhaoCCK 0174984
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 9fd0ede
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK a19c951
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 56e0a7c
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 4420189
update the tests and make it more elegant
ZijunZhaoCCK e00ebb2
[NFC] test commit
Keenuts 7481a66
update test types
ZijunZhaoCCK 90a64b6
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK f37aa1d
simplify code
ZijunZhaoCCK 441a2cb
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK e21911a
nits fixed
ZijunZhaoCCK de8820d
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 7f452e3
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK fdff1a4
1. remove Comparable and TriviallyComparable
ZijunZhaoCCK 89153ef
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK c49ea46
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 1a2b342
[NFC] test commit
Keenuts 51672ee
reformat
ZijunZhaoCCK c7a85d7
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 302b936
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK adc8c39
1. add robust tests
ZijunZhaoCCK 717fdde
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 4700079
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 321a010
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 3e16dde
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 3ae6559
Merge branch 'main' into libcxx-ranges-contains
ZijunZhaoCCK f8113e7
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 7406611
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 2df36fe
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK e88ff21
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK eabbd2c
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK decac9b
Add benchmark tests
ZijunZhaoCCK 295757b
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 1dc09ff
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 061b132
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 19ce63f
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK d779a80
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 3555d17
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK ff58d89
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 81aab9c
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK eb4ca79
Improve benchmark tests.
ZijunZhaoCCK 5354f00
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 16a3c3d
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 221cd0a
Update benchmark tests and identity.h
ZijunZhaoCCK 898a8c7
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 8530245
reformat
ZijunZhaoCCK 5299856
reformat test
ZijunZhaoCCK bea58e6
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 2262fca
reformat
ZijunZhaoCCK 68d5519
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 1ebcc0c
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 2f8b619
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 23a9e61
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 9658671
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK bc510f8
fix build failure
ZijunZhaoCCK 04cfbed
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK bf1c492
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 42d7a3c
reformat
ZijunZhaoCCK 6f0a529
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 64ed92f
reformat
ZijunZhaoCCK d68f8c7
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK f6a7b11
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 1ef7586
reformat
ZijunZhaoCCK a8d2fd5
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK ab88ae1
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 01e3830
Update files
ZijunZhaoCCK 3d26bac
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK a3ac4bc
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 3e207a4
1. remove move() for end sentinel 2. add more tests
ZijunZhaoCCK 11ead5f
reformat
ZijunZhaoCCK 215cfef
reformat
ZijunZhaoCCK c5aacec
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 1c06faf
fix CI build error
ZijunZhaoCCK 7bc83d3
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 9019dbf
update tests
ZijunZhaoCCK 76e9682
reformat
ZijunZhaoCCK 89a2f6e
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK f724c88
Update header files and tests
ZijunZhaoCCK 7fff049
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 65cec29
Update header files and tests
ZijunZhaoCCK 65e5d8a
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 7b24f0d
Merge branch 'llvm:main' into libcxx-ranges-contains
ZijunZhaoCCK 256ab44
Update header files and tests
ZijunZhaoCCK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,49 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <algorithm> | ||
#include <benchmark/benchmark.h> | ||
#include <iterator> | ||
#include <vector> | ||
|
||
#include "test_iterators.h" | ||
ZijunZhaoCCK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static void bm_contains_char(benchmark::State& state) { | ||
std::vector<char> a(state.range(), 'a'); | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(a); | ||
|
||
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 'B')); | ||
} | ||
} | ||
BENCHMARK(bm_contains_char)->RangeMultiplier(16)->Range(16, 16 << 20); | ||
|
||
static void bm_contains_int(benchmark::State& state) { | ||
std::vector<int> a(state.range(), 1); | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(a); | ||
|
||
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), 2)); | ||
} | ||
} | ||
BENCHMARK(bm_contains_int)->RangeMultiplier(16)->Range(16, 16 << 20); | ||
|
||
static void bm_contains_bool(benchmark::State& state) { | ||
std::vector<bool> a(state.range(), true); | ||
|
||
for (auto _ : state) { | ||
benchmark::DoNotOptimize(a); | ||
|
||
benchmark::DoNotOptimize(std::ranges::contains(a.begin(), a.end(), false)); | ||
} | ||
} | ||
BENCHMARK(bm_contains_bool)->RangeMultiplier(16)->Range(16, 16 << 20); | ||
|
||
BENCHMARK_MAIN(); |
This file contains hidden or 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 hidden or 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,61 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// 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___ALGORITHM_RANGES_CONTAINS_H | ||
#define _LIBCPP___ALGORITHM_RANGES_CONTAINS_H | ||
|
||
#include <__algorithm/ranges_find.h> | ||
#include <__config> | ||
#include <__functional/identity.h> | ||
#include <__functional/ranges_operations.h> | ||
#include <__functional/reference_wrapper.h> | ||
#include <__iterator/concepts.h> | ||
#include <__iterator/indirectly_comparable.h> | ||
#include <__iterator/projected.h> | ||
#include <__ranges/access.h> | ||
#include <__ranges/concepts.h> | ||
#include <__utility/move.h> | ||
|
||
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) | ||
# pragma GCC system_header | ||
#endif | ||
|
||
#if _LIBCPP_STD_VER >= 23 | ||
|
||
_LIBCPP_BEGIN_NAMESPACE_STD | ||
|
||
namespace ranges { | ||
namespace __contains { | ||
struct __fn { | ||
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity> | ||
ZijunZhaoCCK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*> | ||
ZijunZhaoCCK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool static | ||
operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) { | ||
return ranges::find(std::move(__first), __last, __value, std::ref(__proj)) != __last; | ||
} | ||
|
||
template <input_range _Range, class _Type, class _Proj = identity> | ||
ZijunZhaoCCK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
requires indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*> | ||
_LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr bool static | ||
operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) { | ||
return ranges::find(ranges::begin(__range), ranges::end(__range), __value, std::ref(__proj)) != | ||
ranges::end(__range); | ||
} | ||
}; | ||
} // namespace __contains | ||
ZijunZhaoCCK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
inline namespace __cpo { | ||
inline constexpr auto contains = __contains::__fn{}; | ||
} // namespace __cpo | ||
} // namespace ranges | ||
|
||
_LIBCPP_END_NAMESPACE_STD | ||
|
||
#endif // _LIBCPP_STD_VER >= 23 | ||
|
||
#endif // _LIBCPP___ALGORITHM_RANGES_CONTAINS_H |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.