Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::priority_queue<T,Container,Compare>::push_range

      From cppreference.com
      <cpp‎ |container‎ |priority queue

      [edit template]
       
       
       
       
      template<container-compatible-range<value_type> R>
      void push_range( R&& rg);
      (since C++23)

      Inserts a copy of each element ofrg inpriority_queue, as if by:

      Then restores the heap property as if byranges::make_heap(c, comp). After the insertionranges::is_heap(c, comp) istrue.

      Each iterator in the rangerg is dereferenced exactly once.

      Contents

      [edit]Parameters

      rg - acontainer compatible range, that is, aninput_range whose elements are convertible toT

      [edit]Complexity

      The complexity ofc.append_range plus the complexity ofranges::make_heap(c, comp).

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_containers_ranges202202L(C++23)Ranges-aware construction and insertion

      [edit]Example

      Run this code
      #include <initializer_list>#include <queue>#include <version>#ifdef __cpp_lib_format_ranges#include <print>usingstd::println;#else#define FMT_HEADER_ONLY#include <fmt/ranges.h>using fmt::println;#endif int main(){std::priority_queue<int> adaptor;constauto rg={1,3,2,4}; #ifdef __cpp_lib_containers_ranges    adaptor.push_range(rg);#elsefor(int e: rg)        adaptor.push(e);#endif     println("{}", adaptor);}

      Output:

      [4, 3, 2, 1]

      [edit]See also

      inserts element and sorts the underlying container
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/priority_queue/push_range&oldid=156414"

      [8]ページ先頭

      ©2009-2025 Movatter.jp