std::is_partitioned
来自cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Defined in header <algorithm>
|
||
| template< class InputIt, class UnaryPredicate > bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p ); |
(C++11 起) | |
返回true所有元素是否满足谓词的范围内
[first, last)p之前的所有元素不出现。返回true如果[first, last)是空的.Original:
Returns true if all elements in the range
[first, last) that satisfy the predicate p appear before all elements that don't. Also returns true if [first, last) is empty.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
| first, last | - | 检查元素的范围
Original: the range of elements to check The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | |||||||||
| p | - | unary predicate which returns true 预期的元素将被发现在该范围的开头 . Original: for the elements expected to be found in the beginning of the range The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. The signature of the predicate function should be equivalent to the following:
The signature does not need to have const &, but the function must not modify the objects passed to it. | |||||||||
| Type requirements | |||||||||||
-InputIt must meet the requirements of InputIterator.
| |||||||||||
[编辑] 返回值
true如果
[first, last)为空或p进行分区。 false否则.....Original:
true if the range
[first, last) is empty or is partitioned by p. false otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 复杂性
在大多数
std::distance(first, last)应用p.Original:
At most
std::distance(first, last) applications of p.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 可能的实现
template< class InputIt, class UnaryPredicate > bool is_partitioned(InputIt first, InputIt last, UnaryPredicate p) { for (; first != last; ++first) if (!p(*first)) break; for (; first != last; ++first) if (p(*first)) return false; return true; } |
[编辑] 为例
#include <algorithm> #include <array> #include <iostream> int main() { std::array<int, 9> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; auto is_even = [](int i){ return i % 2 == 0; }; std::cout.setf(std::ios_base::boolalpha); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::partition(v.begin(), v.end(), is_even); std::cout << std::is_partitioned(v.begin(), v.end(), is_even) << ' '; std::reverse(v.begin(), v.end()); std::cout << std::is_partitioned(v.begin(), v.end(), is_even); }
Output:
false true false
[编辑] 另请参阅
| 把一个范围的元素分为两组 Original: divides a range of elements into two groups The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (函数模板) | |
| (C++11) |
locates the partition point of a partitioned range (函数模板) |