-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Test LWG-4105 ranges::ends_with
's Returns misses difference casting
#4897
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
7 commits
Select commit
Hold shift + click to select a range
0cc5499
Test for LWG-4105
frederick-vs-ja 23b78ba
Switch to use strict_latest_matrix.lst
frederick-vs-ja 3dc1d77
Include `<memory>` for `to_address`.
StephanTLavavej d483c0b
All shall love `[[nodiscard]]` and despair.
StephanTLavavej c5f40da
`std::ranges` => `ranges`
StephanTLavavej db4713c
Use `_Signed_integer_like`, `input_iterator`, and `TEST_EVERYTHING`
frederick-vs-ja 3bed4bf
Enable /analyze and EDG test coverage.
StephanTLavavej 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
4 changes: 4 additions & 0 deletions
4
tests/std/tests/LWG4105_ranges_ends_with_and_integer_class/env.lst
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,4 @@ | ||
# Copyright (c) Microsoft Corporation. | ||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
RUNALL_INCLUDE ..\strict_latest_matrix.lst |
120 changes: 120 additions & 0 deletions
120
tests/std/tests/LWG4105_ranges_ends_with_and_integer_class/test.cpp
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,120 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <functional> | ||
#include <ranges> | ||
#include <span> | ||
#include <utility> | ||
|
||
#include <range_algorithm_support.hpp> | ||
|
||
using namespace std; | ||
|
||
template <class T> | ||
concept testable_range = ranges::input_range<T> && (ranges::forward_range<T> || ranges::sized_range<T>); | ||
|
||
template <class T> | ||
concept testable_sentinel = | ||
ranges::input_range<T> | ||
&& (ranges::forward_range<T> || sized_sentinel_for<ranges::sentinel_t<T>, ranges::iterator_t<T>>); | ||
|
||
struct instantiator { | ||
static constexpr pair<int, int> haystack[] = {{0, 42}, {1, 42}, {2, 42}, {4, 42}}; | ||
static constexpr pair<int, int> short_haystack[] = {{4, 42}}; | ||
static constexpr pair<long, long> long_needle[] = {{13, 1}, {13, 2}, {13, 4}}; | ||
static constexpr pair<long, long> short_needle[] = {{13, 2}, {13, 4}}; | ||
static constexpr pair<long, long> wrong_needle[] = {{13, 2}, {13, 3}}; | ||
|
||
template <std::_Signed_integer_like Diff1, testable_range In1, std::_Signed_integer_like Diff2, testable_range In2> | ||
static constexpr void test_range_rediff() { | ||
using ranges::ends_with, ranges::equal_to; | ||
|
||
{ | ||
In1 r1{haystack}; | ||
In2 r2{long_needle}; | ||
const same_as<bool> auto match = ends_with(test::make_redifference_subrange<Diff1>(r1), | ||
test::make_redifference_subrange<Diff2>(r2), equal_to{}, get_first, get_second); | ||
assert(match); | ||
} | ||
{ | ||
In1 r1{haystack}; | ||
In2 r2{short_needle}; | ||
const same_as<bool> auto match = ends_with(test::make_redifference_subrange<Diff1>(r1), | ||
test::make_redifference_subrange<Diff2>(r2), equal_to{}, get_first, get_second); | ||
assert(match); | ||
} | ||
{ | ||
In1 r1{haystack}; | ||
In2 r2{wrong_needle}; | ||
const same_as<bool> auto match = ends_with(test::make_redifference_subrange<Diff1>(r1), | ||
test::make_redifference_subrange<Diff2>(r2), equal_to{}, get_first, get_second); | ||
assert(!match); | ||
} | ||
{ | ||
In1 r1{short_haystack}; | ||
In2 r2{short_needle}; | ||
const same_as<bool> auto match = ends_with(test::make_redifference_subrange<Diff1>(r1), | ||
test::make_redifference_subrange<Diff2>(r2), equal_to{}, get_first, get_second); | ||
assert(!match); | ||
} | ||
{ | ||
In1 r1{haystack}; | ||
In2 r2{span<pair<long, long>, 0>{}}; | ||
const same_as<bool> auto match = ends_with(test::make_redifference_subrange<Diff1>(r1), | ||
test::make_redifference_subrange<Diff2>(r2), equal_to{}, get_first, get_second); | ||
assert(match); | ||
} | ||
} | ||
|
||
template <ranges::input_range In1, ranges::input_range In2> | ||
static void call() { | ||
if constexpr (testable_range<In1> && testable_range<In2>) { | ||
using int_class = ranges::range_difference_t<ranges::iota_view<long long>>; | ||
|
||
test_range_rediff<int_class, In1, short, In2>(); | ||
static_assert((test_range_rediff<int_class, In1, short, In2>(), true)); | ||
|
||
test_range_rediff<short, In1, int_class, In2>(); | ||
static_assert((test_range_rediff<short, In1, int_class, In2>(), true)); | ||
} | ||
} | ||
}; | ||
|
||
#ifdef TEST_EVERYTHING | ||
int main() { | ||
#if !defined(_PREFAST_) && !defined(__EDG__) // TRANSITION, GH-1030 and GH-3567 | ||
test_in_in<instantiator, const pair<int, int>, const pair<long, long>>(); | ||
#endif // ^^^ no workaround ^^^ | ||
frederick-vs-ja marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
#else // ^^^ test all permutations of range properties / test only interesting permutations vvv | ||
template <class R> | ||
void run_tests_inner() { | ||
instantiator::call<R, test::range<test::input, const pair<long, long>, test::Sized::yes>>(); | ||
instantiator::call<R, test::range<test::fwd, const pair<long, long>, test::Sized::no>>(); | ||
instantiator::call<R, test::range<test::fwd, const pair<long, long>, test::Sized::yes>>(); | ||
instantiator::call<R, test::range<test::bidi, const pair<long, long>, test::Sized::no>>(); | ||
instantiator::call<R, test::range<test::bidi, const pair<long, long>, test::Sized::yes>>(); | ||
instantiator::call<R, test::range<test::random, const pair<long, long>, test::Sized::no>>(); | ||
instantiator::call<R, test::range<test::random, const pair<long, long>, test::Sized::yes>>(); | ||
instantiator::call<R, test::range<test::contiguous, const pair<long, long>, test::Sized::no>>(); | ||
instantiator::call<R, test::range<test::contiguous, const pair<long, long>, test::Sized::yes>>(); | ||
} | ||
|
||
void run_tests() { | ||
run_tests_inner<test::range<test::input, const pair<int, int>, test::Sized::yes>>(); | ||
run_tests_inner<test::range<test::fwd, const pair<int, int>, test::Sized::no>>(); | ||
run_tests_inner<test::range<test::fwd, const pair<int, int>, test::Sized::yes>>(); | ||
run_tests_inner<test::range<test::bidi, const pair<int, int>, test::Sized::no>>(); | ||
run_tests_inner<test::range<test::bidi, const pair<int, int>, test::Sized::yes>>(); | ||
run_tests_inner<test::range<test::random, const pair<int, int>, test::Sized::no>>(); | ||
run_tests_inner<test::range<test::random, const pair<int, int>, test::Sized::yes>>(); | ||
run_tests_inner<test::range<test::contiguous, const pair<int, int>, test::Sized::no>>(); | ||
run_tests_inner<test::range<test::contiguous, const pair<int, int>, test::Sized::yes>>(); | ||
} | ||
|
||
int main() { | ||
run_tests(); | ||
} | ||
#endif // TEST_EVERYTHING |
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.