首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::is_partitioned

Defined in header <algorithm>

?

?

template< class InputIt, class UnaryPredicate > bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );

(1)

(since C++11)

template< class ExecutionPolicy, class ForwardIt, class UnaryPredicate > bool is_partitioned( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryPredicate p );

(2)

(since C++17)

1%29true如果范围内的所有元素[first, last)满足谓词的p出现在所有不使用%27T的元素之前。还回来了true如果[first, last)是空的。

2%29与%281%29相同,但根据policy。此重载只参与以下情况下的过载解决方案:std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的

参数

first, last

-

the range of elements to check

policy

-

the execution policy to use. See execution policy for details.

p

-

unary predicate which returns ?true for the elements expected to be found in the beginning of the range. The signature of the predicate function should be equivalent to the following: bool pred(const Type &a); The signature does not need to have const &, but the function must not modify the objects passed to it. The type Type must be such that an object of type InputIt can be dereferenced and then implicitly converted to Type. ?

类型要求

-输入必须符合输入器的要求。

---。它的值类型必须转换为单数预测%27s参数类型。

-单数预测必须满足谓词的要求。

返回值

true如果范围[first, last)为空或由p...false否则。

复杂性

顶多std::distance(first, last)的应用p...

例外

带有名为ExecutionPolicy报告错误如下:

  • 如果执行作为算法一部分调用的函数,则引发异常ExecutionPolicy是其中之一标准政策,,,std::terminate叫做。对于任何其他人ExecutionPolicy,行为是由实现定义的。
  • 如果算法不能分配内存,std::bad_alloc被扔了。

可能的实施

模板<类Inputit,类UnaryPredicate>bool是[医]分区%28 InputIt First,Inputit Lest,UnaryPredicate p%29{表示%28;First%21=Lest;++First%29 if%28%21 p%28%2A第一%29%29中断;对于%28;第一%21=最后;++第一%29如果%28p%28%2A首先%29%29返回false;返回true;}

*。

二次

代码语言:javascript
复制
#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);
}

二次

产出:

二次

代码语言:javascript
复制
false true false

二次

另见

partition

divides a range of elements into two groups (function template)

partition_point (C++11)

locates the partition point of a partitioned range (function template)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com