Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      deduction guides forstd::priority_queue

      From cppreference.com
      <cpp‎ |container‎ |priority queue
       
       
       
       
      Defined in header<queue>
      template<class Comp,class Container>

      priority_queue( Comp, Container)

         -> priority_queue<typename Container::value_type, Container, Comp>;
      (1)(since C++17)
      template<class InputIt,

               class Comp=std::less</*iter-val-t*/<InputIt>>,
               class Container=std::vector</*iter-val-t*/<InputIt>>
      priority_queue( InputIt, InputIt, Comp= Comp(), Container= Container())

         -> priority_queue</*iter-val-t*/<InputIt>, Container, Comp>;
      (2)(since C++17)
      template<class Comp,class Container,class Alloc>

      priority_queue( Comp, Container, Alloc)

         -> priority_queue<typename Container::value_type, Container, Comp>;
      (3)(since C++17)
      template<class InputIt,class Alloc>

      priority_queue( InputIt, InputIt, Alloc)
         -> priority_queue</*iter-val-t*/<InputIt>,
                           std::vector</*iter-val-t*/<InputIt>, Alloc>,

                           std::less</*iter-val-t*/<InputIt>>>;
      (4)(since C++17)
      template<class InputIt,class Comp,class Alloc>

      priority_queue( InputIt, InputIt, Comp, Alloc)
         -> priority_queue</*iter-val-t*/<InputIt>,

                           std::vector</*iter-val-t*/<InputIt>, Alloc>, Comp>;
      (5)(since C++17)
      template<class InputIt,class Comp,class Container,class Alloc>

      priority_queue( InputIt, InputIt, Comp, Container, Alloc)

         -> priority_queue<typename Container::value_type, Container, Comp>;
      (6)(since C++17)
      template<ranges::input_range R,

               class Comp=std::less<ranges::range_value_t<R>>>
      priority_queue(std::from_range_t, R&&, Comp= Comp())
         -> priority_queue<ranges::range_value_t<R>,

                           std::vector<ranges::range_value_t<R>>, Comp>;
      (7)(since C++23)
      template<ranges::input_range R,class Comp,class Alloc>

      priority_queue(std::from_range_t, R&&, Comp, Alloc)
         -> priority_queue<ranges::range_value_t<R>,

                           std::vector<ranges::range_value_t<R>, Alloc>, Comp>;
      (8)(since C++23)
      template<ranges::input_range R,class Alloc>

      priority_queue(std::from_range_t, R&&, Alloc)
         -> priority_queue<ranges::range_value_t<R>,

                           std::vector<ranges::range_value_t<R>, Alloc>>;
      (9)(since C++23)
      Exposition-only helper type aliases
      template<class InputIt>

      using/*iter-val-t*/=

         typenamestd::iterator_traits<InputIt>::value_type;
      (exposition only*)

      The followingdeduction guides are provided forstd::priority_queue:

      1-6) Allow deduction from underlying container type and from an iterator range.
      7-9) Allow deduction from astd::from_range_t tag and aninput_range.

      These overloads participate in overload resolution only if

      Note: the extent to which the library determines that a type does not satisfyLegacyInputIterator is unspecified, except that as a minimum integral types do not qualify as input iterators. Likewise, the extent to which it determines that a type does not satisfyAllocator is unspecified, except that as a minimum the member typeAlloc::value_type must exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{}) must be well-formed when treated as an unevaluated operand.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_containers_ranges202202L(C++23)Ranges-aware construction and insertion; overloads(7-9)

      [edit]Example

      Run this code
      #include <functional>#include <iostream>#include <queue>#include <vector> int main(){conststd::vector<int> v={1,2,3,4};std::priority_queue pq1{std::greater<int>{}, v};// deduces std::priority_queue<//     int, std::vector<int>,//     std::greater<int>>for(;!pq1.empty(); pq1.pop())std::cout<< pq1.top()<<' ';std::cout<<'\n'; std::priority_queue pq2{v.begin(), v.end()};// deduces std::priority_queue<int> for(;!pq2.empty(); pq2.pop())std::cout<< pq2.top()<<' ';std::cout<<'\n';}

      Output:

      1 2 3 44 3 2 1

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3506C++17deduction guides from iterator and allocator were missingadded,(4-6)
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/priority_queue/deduction_guides&oldid=182257"

      [8]ページ先頭

      ©2009-2025 Movatter.jp