C++ 参考手册
- C++11
 - C++14
 - C++17
 - C++20
 - C++ 编译器支持情况表
 - 独立与宿主实现
 - C++ 语言
 - C++ 关键词
 - 预处理器
 - C++ 标准库头文件
 - 具名要求
 - 功能特性测试 (C++20)
 - 工具库
 - 类型支持(基本类型、RTTI、类型特性)
 - 概念库 (C++20)
 - 错误处理
 - 动态内存管理
 - 日期和时间工具
 - 字符串库
 - 容器库
 - 迭代器库
 - 范围库 (C++20)
 - 算法库
 - std::execution::sequenced_policy, std::execution::parallel_policy, std::execution::parallel_unsequenced_policy, std::execution::unsequenced_policy
 - 有制约算法 (C++20 起)
 - std::is_execution_policy
 - std::execution::seq, std::execution::par, std::execution::par_unseq, std::execution::unseq
 - std::all_of, std::any_of, std::none_of
 - std::for_each_n
 - std::sort
 - std::reduce
 - std::inclusive_scan
 - std::exclusive_scan
 - std::random_shuffle, std::shuffle
 - std::clamp
 - std::equal
 - std::is_permutation
 - std::mismatch
 - std::swap
 - std::search
 - std::transform
 - std::for_each
 - std::make_heap
 - std::count, std::count_if
 - std::adjacent_find
 - std::find, std::find_if, std::find_if_not
 - std::find_end
 - std::find_first_of
 - std::search_n
 - std::lexicographical_compare
 - std::lexicographical_compare_three_way
 - std::copy, std::copy_if
 - std::copy_n
 - std::copy_backward
 - std::move
 - std::move_backward
 - std::shift_left, std::shift_right
 - std::fill
 - std::fill_n
 - std::generate
 - std::generate_n
 - std::iter_swap
 - std::swap_ranges
 - std::sample
 - std::remove, std::remove_if
 - std::replace, std::replace_if
 - std::reverse
 - std::rotate
 - std::unique
 - std::remove_copy, std::remove_copy_if
 - std::replace_copy, std::replace_copy_if
 - std::reverse_copy
 - std::rotate_copy
 - std::unique_copy
 - std::is_partitioned
 - std::partition_point
 - std::partition
 - std::partition_copy
 - std::stable_partition
 - std::is_sorted
 - std::is_sorted_until
 - std::stable_sort
 - std::partial_sort
 - std::partial_sort_copy
 - std::nth_element
 - std::lower_bound
 - std::upper_bound
 - std::binary_search
 - std::equal_range
 - std::merge
 - std::inplace_merge
 - std::set_difference
 - std::set_intersection
 - std::set_symmetric_difference
 - std::set_union
 - std::includes
 - std::is_heap
 - std::is_heap_until
 - std::sort_heap
 - std::push_heap
 - std::pop_heap
 - std::max
 - std::max_element
 - std::min
 - std::min_element
 - std::minmax
 - std::minmax_element
 - std::next_permutation
 - std::prev_permutation
 - std::iota
 - std::inner_product
 - std::adjacent_difference
 - std::accumulate
 - std::transform_reduce
 - std::partial_sum
 - std::transform_inclusive_scan
 - std::transform_exclusive_scan
 - std::qsort
 - std::bsearch
 - 注释
 - 数值库
 - 输入/输出库
 - 文件系统库
 - 本地化库
 - 正则表达式库
 - 原子操作库
 - 线程支持库
 - 实验性 C++ 特性
 - 有用的资源
 - 索引
 - std 符号索引
 - 协程支持 (C++20)
 - C++ 关键词
 
std::partial_sort_copy
|   定义于头文件  <algorithm>
  | 
||
| (1) | ||
|   template< class InputIt, class RandomIt > RandomIt partial_sort_copy( InputIt first, InputIt last,  | 
(C++20 前) | |
|   template< class InputIt, class RandomIt > constexpr RandomIt partial_sort_copy( InputIt first, InputIt last,  | 
(C++20 起) | |
|   template< class ExecutionPolicy, class ForwardIt, class RandomIt > RandomIt partial_sort_copy( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last,  | 
(2) | (C++17 起) | 
| (3) | ||
|   template< class InputIt, class RandomIt, class Compare > RandomIt partial_sort_copy( InputIt first, InputIt last,  | 
(C++20 前) | |
|   template< class InputIt, class RandomIt, class Compare > constexpr RandomIt partial_sort_copy( InputIt first, InputIt last,  | 
(C++20 起) | |
|   template< class ExecutionPolicy, class ForwardIt, class RandomIt, class Compare > RandomIt partial_sort_copy( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last,  | 
(4) | (C++17 起) | 
以升序排序范围 [first, last) 中的某些元素,存储结果于范围 [d_first, d_last) 。
至多将 d_last - d_first 个元素放置并排序到范围 [d_first, d_first + n) 中。其中 n 是要排序的元素数( n = min(last - first, d_last - d_first) )。不保证保持相等元素的顺序。
operator< 比较元素。comp 比较元素。policy 执行。这些重载仅若 std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> 为 true 才参与重载决议。参数
| first, last | - | 要排序的元素范围 | 
| d_first, d_last | - | 定义目标范围的随机访问迭代器 | 
| policy | - | 所用的执行策略。细节见执行策略。 | 
| comp | - |  比较函数对象(即满足比较 (Compare) 概念的对象),若第一参数小于(即先序于)第二参数则返回 true 。 比较函数的签名应等价于如下: bool cmp(const Type1 &a, const Type2 &b); 虽然签名不必有 const & ,函数也不能修改传递给它的对象,而且必须接受(可为 const 的)类型   | 
| 类型要求 | ||
 -InputIt 必须满足遗留输入迭代器 (LegacyInputIterator)  的要求。
 | ||
 -ForwardIt 必须满足遗留向前迭代器 (LegacyForwardIterator)  的要求。
 | ||
 -RandomIt 必须满足值可交换 (ValueSwappable)  和 遗留随机访问迭代器 (LegacyRandomAccessIterator)  的要求。
 | ||
 -解引用 RandomIt 结果的类型必须满足可移动赋值 (MoveAssignable) 和可移动构造 (MoveConstructible) 的要求。
 | ||
返回值
指向定义已排序范围上界的元素的迭代器,即 d_first + min(last - first, d_last - d_first) 。
复杂度
O(N·log(min(D,N)) 次应用 cmp ,其中 N = std::distance(first, last) , D = std::distance(d_first, d_last) 。
异常
拥有名为 ExecutionPolicy 的模板形参的重载按下列方式报告错误:
-  若作为算法一部分调用的函数的执行抛出异常,且 
ExecutionPolicy为标准策略之一,则调用 std::terminate 。对于任何其他ExecutionPolicy,行为是实现定义的。 - 若算法无法分配内存,则抛出 std::bad_alloc 。
 
示例
下列代码排序 int 的 vector 并将它们复制到较小和较大的 vector 中。
#include <algorithm> #include <vector> #include <functional> #include <iostream> int main() { std::vector<int> v0{4, 2, 5, 1, 3}; std::vector<int> v1{10, 11, 12}; std::vector<int> v2{10, 11, 12, 13, 14, 15, 16}; std::vector<int>::iterator it; it = std::partial_sort_copy(v0.begin(), v0.end(), v1.begin(), v1.end()); std::cout << "Writing to the smaller vector in ascending order gives: "; for (int a : v1) { std::cout << a << " "; } std::cout << '\n'; if(it == v1.end()) std::cout << "The return value is the end iterator\n"; it = std::partial_sort_copy(v0.begin(), v0.end(), v2.begin(), v2.end(), std::greater<int>()); std::cout << "Writing to the larger vector in descending order gives: "; for (int a : v2) { std::cout << a << " "; } std::cout << '\n' << "The return value is the iterator to " << *it << '\n'; }
输出:
Writing to the smaller vector in ascending order gives: 1 2 3 The return value is the end iterator Writing to the larger vector in descending order gives: 5 4 3 2 1 15 16 The return value is the iterator to 15
参阅
|    排序一个范围的前 N 个元素   (函数模板)  | |
|    将范围按升序排序   (函数模板)  | |
|    将范围内的元素排序,同时保持相等的元素之间的顺序   (函数模板)  |