[ Web Proxy ]
URL:
Viewing: http://ja.cppreference.com/cpp/algorithm/is_partitioned [Back]  [Original]

std::is_partitioned - cppreference.com
cppreference.com

std::is_partitioned

: cppreference.com
 
C++
(C++20)
(C++20)
(C++17)
(C++11)
(C++11)
(C++11)
 
(C++20)
: std::sortable, std::projected, ...
: std::ranges::copy, std::ranges::sort, ...
(C++17)
(C++11)(C++11)(C++11)
(C++17)
(C++11)
()
(C++11)
/
(C++11)
(C++17)

C
 
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
(1)
template< class InputIt, class UnaryPredicate > bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );
(C++11)
(C++20)
template< class InputIt, class UnaryPredicate > constexpr bool is_partitioned( InputIt first, InputIt last, UnaryPredicate p );
(C++20)
template< class ExecutionPolicy, class ForwardIt, class UnaryPredicate > bool is_partitioned( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last, UnaryPredicate p );
(2) (C++17)
1) [first, last) p true [first, last) true
2) (1) policy std::is_execution_policy_v<std::decay_t<ExecutionPolicy>> true

first, last -
policy -
p - true

p(v) VT ( const ) v bool VT InputIt v VT& VT VT (C++11)

-
InputIt LegacyInputIterator
-
ForwardIt LegacyForwardIterator UnaryPredicate's
-
UnaryPredicate Predicate

[first, last) p true false

std::distance(first, last) p

ExecutionPolicy

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);
}

:

false true false

2
() [edit]

() [edit]

Web Proxy Viewer  |  New URL  |  Original Page