forked from microsoft/STL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<algorithm>
: Fix bogus pointer arithmetic with integer-class (micro…
…soft#5091) Co-authored-by: Casey Carter <cacarter@microsoft.com>
- Loading branch information
1 parent
1711bc3
commit fec1c8b
Showing
5 changed files
with
133 additions
and
24 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
4 changes: 4 additions & 0 deletions
4
tests/std/tests/GH_002885_stable_sort_difference_type/env.lst
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 ..\usual_20_matrix.lst |
99 changes: 99 additions & 0 deletions
99
tests/std/tests/GH_002885_stable_sort_difference_type/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,99 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include <algorithm> | ||
#include <cassert> | ||
#include <cstddef> | ||
#include <cstdint> | ||
#include <ranges> | ||
|
||
#include "range_algorithm_support.hpp" | ||
|
||
using namespace std; | ||
|
||
constexpr auto pred = [](int i) { return i <= 42; }; | ||
|
||
template <class I> | ||
void test_iota_transform() { | ||
constexpr int orig[]{42, 1729}; | ||
int a[]{42, 1729}; | ||
auto vw = views::iota(I{}, static_cast<I>(ranges::size(a))) | ||
| views::transform([&a](I i) -> auto& { return a[static_cast<size_t>(i)]; }); | ||
|
||
static_assert(three_way_comparable<ranges::iterator_t<ranges::iota_view<I>>>); // TRANSITION, /permissive | ||
|
||
ranges::stable_sort(vw); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::stable_sort(vw.begin(), vw.end()); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::inplace_merge(vw, ranges::next(vw.begin())); | ||
assert(ranges::equal(a, orig)); | ||
ranges::inplace_merge(vw.begin(), ranges::next(vw.begin()), vw.end()); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::stable_partition(vw, pred); | ||
assert(ranges::equal(a, orig)); | ||
ranges::stable_partition(vw.begin(), vw.end(), pred); | ||
assert(ranges::equal(a, orig)); | ||
} | ||
|
||
void test_iota_transform_all() { | ||
test_iota_transform<signed char>(); | ||
test_iota_transform<short>(); | ||
test_iota_transform<int>(); | ||
test_iota_transform<long>(); | ||
test_iota_transform<long long>(); | ||
|
||
test_iota_transform<unsigned char>(); | ||
test_iota_transform<unsigned short>(); | ||
test_iota_transform<unsigned int>(); | ||
test_iota_transform<unsigned long>(); | ||
test_iota_transform<unsigned long long>(); | ||
|
||
test_iota_transform<char>(); | ||
#ifdef __cpp_char8_t | ||
test_iota_transform<char8_t>(); | ||
#endif // defined(__cpp_char8_t) | ||
test_iota_transform<char16_t>(); | ||
test_iota_transform<char32_t>(); | ||
test_iota_transform<wchar_t>(); | ||
} | ||
|
||
template <class I> | ||
void test_redifference() { | ||
constexpr int orig[]{42, 1729}; | ||
int a[]{42, 1729}; | ||
auto vw = test::make_redifference_subrange<I>(a); | ||
|
||
ranges::stable_sort(vw); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::stable_sort(vw.begin(), vw.end()); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::inplace_merge(vw, ranges::next(vw.begin())); | ||
assert(ranges::equal(a, orig)); | ||
ranges::inplace_merge(vw.begin(), ranges::next(vw.begin()), vw.end()); | ||
assert(ranges::equal(a, orig)); | ||
|
||
ranges::stable_partition(vw, pred); | ||
assert(ranges::equal(a, orig)); | ||
ranges::stable_partition(vw.begin(), vw.end(), pred); | ||
assert(ranges::equal(a, orig)); | ||
} | ||
|
||
void test_redifference_all() { | ||
test_redifference<signed char>(); | ||
test_redifference<short>(); | ||
test_redifference<int>(); | ||
test_redifference<long>(); | ||
test_redifference<long long>(); | ||
test_redifference<_Signed128>(); | ||
} | ||
|
||
int main() { | ||
test_iota_transform_all(); | ||
test_redifference_all(); | ||
} |