-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement P2538R1 ADL-Proof
projected
(#3822)
Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
- Loading branch information
1 parent
90dcf26
commit cc6533a
Showing
6 changed files
with
90 additions
and
12 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,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\concepts_20_matrix.lst |
54 changes: 54 additions & 0 deletions
54
tests/std/tests/P2538R1_adl_proof_std_projected/test.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,54 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#ifndef _M_CEE // TRANSITION, VSO-1659496 | ||
#include <cassert> | ||
#include <functional> | ||
#include <iterator> | ||
#include <ranges> | ||
#include <utility> | ||
|
||
using namespace std; | ||
|
||
// TRANSITION, GH-1596, should use ranges::count | ||
struct my_count_fn { | ||
template <input_iterator I, sentinel_for<I> S, class T, class Proj = identity> | ||
requires indirect_binary_predicate<ranges::equal_to, projected<I, Proj>, const T*> | ||
constexpr iter_difference_t<I> operator()(I first, S last, const T& value, Proj proj = {}) const { | ||
iter_difference_t<I> counter = 0; | ||
for (; first != last; ++first) { | ||
if (std::invoke(proj, *first) == value) { // intentionally qualified to avoid ADL | ||
++counter; | ||
} | ||
} | ||
return counter; | ||
} | ||
|
||
template <ranges::input_range R, class T, class Proj = identity> | ||
requires indirect_binary_predicate<ranges::equal_to, projected<ranges::iterator_t<R>, Proj>, const T*> | ||
constexpr ranges::range_difference_t<R> operator()(R&& r, const T& value, Proj proj = {}) const { | ||
return (*this)(ranges::begin(r), ranges::end(r), value, ref(proj)); | ||
} | ||
}; | ||
|
||
inline constexpr my_count_fn my_count; | ||
|
||
template <class T> | ||
struct Holder { | ||
T t; | ||
}; | ||
struct Incomplete; | ||
|
||
static_assert(equality_comparable<Holder<Incomplete>*>); | ||
static_assert(indirectly_comparable<Holder<Incomplete>**, Holder<Incomplete>**, equal_to<>>); | ||
static_assert(sortable<Holder<Incomplete>**>); | ||
|
||
constexpr bool test() { | ||
Holder<Incomplete>* a[10] = {}; | ||
assert(my_count(a, a + 10, nullptr) == 10); | ||
assert(my_count(a, nullptr) == 10); | ||
return true; | ||
} | ||
|
||
static_assert(test()); | ||
#endif // _M_CEE |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\concepts_latest_matrix.lst | ||
RUNALL_INCLUDE ..\concepts_20_matrix.lst |