From 3af3684cd64ce885a4345de479936f91afa79ad9 Mon Sep 17 00:00:00 2001 From: Akira Takahashi Date: Fri, 2 Aug 2024 13:41:43 +0900 Subject: [PATCH] =?UTF-8?q?stable=20sort=E9=96=A2=E4=BF=82=20:=20C++26?= =?UTF-8?q?=E3=81=A7=E3=81=AEconstexpr=E5=AF=BE=E5=BF=9C=20(close=20#1182)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- reference/algorithm/inplace_merge.md | 17 ++++++++++-- reference/algorithm/ranges_inplace_merge.md | 26 ++++++++++++++++--- .../algorithm/ranges_stable_partition.md | 20 ++++++++++++++ reference/algorithm/ranges_stable_sort.md | 20 ++++++++++++++ reference/algorithm/stable_partition.md | 7 +++++ reference/algorithm/stable_sort.md | 15 ++++++++++- 6 files changed, 99 insertions(+), 6 deletions(-) diff --git a/reference/algorithm/inplace_merge.md b/reference/algorithm/inplace_merge.md index 72932b0df1..2af32581f8 100644 --- a/reference/algorithm/inplace_merge.md +++ b/reference/algorithm/inplace_merge.md @@ -9,12 +9,23 @@ namespace std { void inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); // (1) C++03 + template + constexpr + void inplace_merge(BidirectionalIterator first, + BidirectionalIterator middle, + BidirectionalIterator last); // (1) C++26 template void inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); // (2) C++03 + template + constexpr + void inplace_merge(BidirectionalIterator first, + BidirectionalIterator middle, + BidirectionalIterator last, + Compare comp); // (2) C++26 template void inplace_merge(ExecutionPolicy&& exec, @@ -94,7 +105,9 @@ int main() ``` ## 実装例 -- [inplace_merge を読んでみた](http://www.kmonos.net/wlog/115.html#_2300101215) - +- [`inplace_merge` を読んでみた](http://www.kmonos.net/wlog/115.html#_2300101215) +## 参照 +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した diff --git a/reference/algorithm/ranges_inplace_merge.md b/reference/algorithm/ranges_inplace_merge.md index 3b5b73f0cc..062a0e0a0f 100644 --- a/reference/algorithm/ranges_inplace_merge.md +++ b/reference/algorithm/ranges_inplace_merge.md @@ -17,6 +17,17 @@ namespace std::ranges { S last, Comp comp = {}, Proj proj = {}); // (1) C++20 + template S, + class Comp = ranges::less, + class Proj = identity> + requires sortable + constexpr I + inplace_merge(I first, + I middle, + S last, + Comp comp = {}, + Proj proj = {}); // (1) C++26 template middle, Comp comp = {}, Proj proj = {}); // (2) C++20 + template + requires sortable, Comp, Proj> + constexpr borrowed_iterator_t + inplace_merge(R&& r, + iterator_t middle, + Comp comp = {}, + Proj proj = {}); // (2) C++26 } ``` * bidirectional_iterator[link /reference/iterator/bidirectional_iterator.md] @@ -98,7 +118,7 @@ int main() ``` ## 実装例 -- [inplace_merge を読んでみた](http://www.kmonos.net/wlog/115.html#_2300101215) +- [`inplace_merge` を読んでみた](http://www.kmonos.net/wlog/115.html#_2300101215) ## バージョン ### 言語 @@ -112,5 +132,5 @@ int main() ## 参照 - [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms) - - +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した diff --git a/reference/algorithm/ranges_stable_partition.md b/reference/algorithm/ranges_stable_partition.md index a2324e8770..5fd20f2956 100644 --- a/reference/algorithm/ranges_stable_partition.md +++ b/reference/algorithm/ranges_stable_partition.md @@ -16,6 +16,16 @@ namespace std::ranges { S last, Pred pred, Proj proj = {}); // (1) C++20 + template S, + class Proj = identity, + indirect_unary_predicate> Pred> + requires permutable + constexpr subrange + stable_partition(I first, + S last, + Pred pred, + Proj proj = {}); // (1) C++26 template , Proj>> Pred> + requires permutable> + constexpr borrowed_subrange_t + stable_partition(R&& r, + Pred pred, + Proj proj = {}); // (2) C++26 } ``` * bidirectional_iterator[link /reference/iterator/bidirectional_iterator.md] @@ -106,3 +124,5 @@ int main() ## 参照 - [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms) +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した diff --git a/reference/algorithm/ranges_stable_sort.md b/reference/algorithm/ranges_stable_sort.md index e0c93a7f7e..bde206d5cd 100644 --- a/reference/algorithm/ranges_stable_sort.md +++ b/reference/algorithm/ranges_stable_sort.md @@ -16,6 +16,16 @@ namespace std::ranges { S last, Comp comp = {}, Proj proj = {}); // (1) C++20 + template S, + class Comp = ranges::less, + class Proj = identity> + requires sortable + constexpr I + stable_sort(I first, + S last, + Comp comp = {}, + Proj proj = {}); // (1) C++26 template + requires sortable, Comp, Proj> + constexpr borrowed_iterator_t + stable_sort(R&& r, + Comp comp = {}, + Proj proj = {}); // (2) C++26 } ``` * random_access_iterator[link /reference/iterator/random_access_iterator.md] @@ -96,3 +114,5 @@ int main() ## 参照 - [N4861 25 Algorithms library](https://timsong-cpp.github.io/cppwp/n4861/algorithms) +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した diff --git a/reference/algorithm/stable_partition.md b/reference/algorithm/stable_partition.md index 38d2af6d84..1ab0fc7da5 100644 --- a/reference/algorithm/stable_partition.md +++ b/reference/algorithm/stable_partition.md @@ -10,6 +10,11 @@ namespace std { stable_partition(BidirectionalIterator first, BidirectionalIterator last, Predicate pred); // (1) C++03 + template + constexpr BidirectionalIterator + stable_partition(BidirectionalIterator first, + BidirectionalIterator last, + Predicate pred); // (1) C++26 template BidirectionalIterator @@ -81,3 +86,5 @@ int main() ## 参照 - [LWG Issue 2150. Unclear specification of `find_end`](http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2150) - [P0574R1 Algorithm Complexity Constraints and Parallel Overloads](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0574r1.html) +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した diff --git a/reference/algorithm/stable_sort.md b/reference/algorithm/stable_sort.md index 0f77c873be..f66fe2166b 100644 --- a/reference/algorithm/stable_sort.md +++ b/reference/algorithm/stable_sort.md @@ -7,12 +7,21 @@ namespace std { template void stable_sort(RandomAccessIterator first, - RandomAccessIterator last); // (1) C++03 + RandomAccessIterator last); // (1) C++03 + template + constexpr + void stable_sort(RandomAccessIterator first, + RandomAccessIterator last); // (1) C++26 template void stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); // (2) C++03 + template + constexpr + void stable_sort(RandomAccessIterator first, + RandomAccessIterator last, + Compare comp); // (2) C++26 template void stable_sort(ExecutionPolicy&& exec, @@ -82,3 +91,7 @@ int main() 5 ``` + +## 参照 +- [P2562R1 `constexpr` Stable Sorting](https://open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2562r1.pdf) + - C++26から`constexpr`に対応した