-
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.
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 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
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_matrix.lst |
59 changes: 59 additions & 0 deletions
59
tests/std/tests/P0896R4_ranges_alg_replace_copy_if/test.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,59 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <concepts> | ||
#include <ranges> | ||
#include <utility> | ||
|
||
#include <range_algorithm_support.hpp> | ||
using namespace std; | ||
using P = pair<int, int>; | ||
|
||
constexpr auto matches = [](int const val) { return val == 47; }; | ||
|
||
// Validate that replace_copy_if_result aliases in_out_result | ||
STATIC_ASSERT(same_as<ranges::replace_copy_if_result<int, double>, ranges::in_out_result<int, double>>); | ||
|
||
// Validate dangling story | ||
STATIC_ASSERT(same_as<decltype(ranges::replace_copy(borrowed<false>{}, static_cast<int*>(nullptr), matches, 5)), | ||
ranges::replace_copy_if_result<ranges::dangling, int*>>); | ||
STATIC_ASSERT(same_as<decltype(ranges::replace_copy(borrowed<true>{}, static_cast<int*>(nullptr), matches, 5)), | ||
ranges::replace_copy_if_result<int*, int*>>); | ||
|
||
struct instantiator { | ||
static constexpr P input[5] = {{0, 99}, {1, 47}, {2, 99}, {3, 47}, {4, 99}}; | ||
static constexpr P expected[5] = {{0, 99}, {47, 1}, {2, 99}, {47, 1}, {4, 99}}; | ||
|
||
template <ranges::input_range Read, ranges::indirectly_writable<ranges::range_reference_t<Read>> Write> | ||
static constexpr void call() { | ||
using ranges::replace_copy_if, ranges::replace_copy_if_result, ranges::iterator_t; | ||
{ // Validate iterator + sentinel overload | ||
Read wrapped_input{input}; | ||
P input[5] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}}; | ||
|
||
auto result = replace_copy_if( | ||
wrapped_input.begin(), wrapped_input.end(), Write{output}, matches, P{47, 1}, get_second); | ||
STATIC_ASSERT(same_as<decltype(result), replace_copy_if_result<iterator_t<Read>, Write>>); | ||
assert(result.in == wrapped_input.end()); | ||
assert(result.out.peek() == output + 5); | ||
assert(ranges::equal(output, expected)); | ||
} | ||
{ // Validate range overload | ||
Read wrapped_input{input}; | ||
P input[5] = {{-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}, {-1, -1}}; | ||
|
||
auto result = replace_copy_if(wrapped_input, Write{output}, matches, P{47, 1}, get_second); | ||
STATIC_ASSERT(same_as<decltype(result), replace_copy_if_result<iterator_t<Read>, Write>>); | ||
assert(result.in == wrapped_input.end()); | ||
assert(result.out.peek() == output + 5); | ||
assert(ranges::equal(output, expected)); | ||
} | ||
} | ||
}; | ||
|
||
int main() { | ||
STATIC_ASSERT((test_in_write<instantiator, P const, P>(), true)); | ||
test_in_write<instantiator, P const, P>(); | ||
} |