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

std::is_heap_until cppreference.com
cppreference.com

std::is_heap_until

cppreference.com

<metanoindex/>

 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++20)
, ranges::copy, ranges::sort, ...
(C++17)
(C++11)(C++11)(C++11)
(C++17)
(C++11)
( )
(C++11)
/
(C++11)
(C++17)

(C++17)
(C++17)
(C++17)
C
 
<tbody> </tbody>
template< class RandomIt > RandomIt is_heap_until( RandomIt first, RandomIt last );
(1) ( C++11)
template< class RandomIt, class Compare > RandomIt is_heap_until( RandomIt first, RandomIt last, Compare comp );
(2) ( C++11)
[first, last) first ' . operator< , comp.
:
Examines the range [first, last) and finds the largest range beginning at first which is heap. The first version of the function uses operator< to compare the elements, the second uses the given comparison function comp.
Google.
. .

first, last
:
the range of elements to examine
Google.
. .
comp (.. , Compare), true, "", .

:

bool cmp(const Type1 &a, const Type2 &b);

noexcept ( C++11) . const&, . ( const) Type1 Type2 ( , Type1& , Type1, Type1 ( C++11)). Type1 Type2 , RandomIt .

-
RandomIt RandomAccessIterator.

first ' . , it , [first, it) ' .
:
The upper bound of the largest range beginning at first which is heap. That is, the last iterator it for which range [first, it) is heap.
Google.
. .

first last
:
Linear in the distance between first and last
Google.
. .

' [f,l), :
:
A heap is a range of elements [f,l) that has the following properties:
Google.
. .
  • *f
    :
    *f is the largest element in the range
    Google.
    . .
  • std::push_heap()
    :
    a new element can be added using std::push_heap()
    Google.
    . .
  • std::pop_heap()
    :
    the first element can be removed using std::pop_heap()
    Google.
    . .
, .
:
The actual arrangement of the elements is implementation defined.
Google.
. .

#include <iostream>
#include <algorithm>

int main()
{
    std::vector<int> v { 3, 1, 4, 1, 5, 9 };

    std::make_heap(v.begin(), v.end());

    // probably mess up the heap
    v.push_back(2);
    v.push_back(6);

    auto heap_end = std::is_heap_until(v.begin(), v.end());

    std::cout << "all of v: ";
    for (auto i : v) std::cout << i << ' ';
    std::cout << '\n';

    std::cout << "only heap: ";
    for (auto i = v.begin(); i != heap_end; ++i) std::cout << *i << ' ';
    std::cout << '\n';
}

:

all of v:  9 5 4 1 1 3 2 6
only heap: 9 5 4 1 1 3 2

.

,
( ) []

Web Proxy Viewer  |  New URL  |  Original Page