Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
deductiongu...iority_queue(3) C++ Standard Libarydeductiongu...iority_queue(3)

NAME
       deductionguidesforstd::priority_queue  -	 deductionguidesforstd::prior-
       ity_queue

Synopsis
	  Defined in header <queue>
	  template< class Comp,	class Container	>

	  priority_queue(	     Comp,	       Container	     )
       (1) (since C++17)

	      -> priority_queue<typename Container::value_type,	Container,
	  Comp>;
	  template< class InputIt,

		    class Comp = std::less</*iter-value-type*/<InputIt>>,
		    class Container =
	  std::vector</*iter-value-type*/<InputIt>			     >
       (2) (since C++17)
	  priority_queue( InputIt, InputIt, Comp = Comp(), Container =
	  Container() )

	      -> priority_queue</*iter-value-type*/<InputIt>, Container,
	  Comp>;
	  template< class Comp,	class Container, class Alloc >

	  priority_queue(	 Comp,	      Container,	Alloc	     )
       (3) (since C++17)

	      -> priority_queue<typename Container::value_type,	Container,
	  Comp>;
	  template< class InputIt, class Alloc >

	  priority_queue( InputIt, InputIt, Alloc )
	      ->		  priority_queue</*iter-value-type*/<InputIt>,
       (4) (since C++17)
				std::vector</*iter-value-type*/<InputIt>,
	  Alloc>,

				std::less</*iter-value-type*/<InputIt>>>;
	  template< class InputIt, class Comp, class Alloc >

	  priority_queue( InputIt, InputIt, Comp, Alloc	)
	      ->		  priority_queue</*iter-value-type*/<InputIt>,
       (5) (since C++17)

				std::vector</*iter-value-type*/<InputIt>,
	  Alloc>, Comp>;
	  template< class InputIt, class Comp, class Container,	class Alloc
	  >

	  priority_queue(   InputIt,   InputIt,	  Comp,	  Container,  Alloc  )
       (6) (since C++17)

	      -> priority_queue<typename Container::value_type,	Container,
	  Comp>;
	  template< ranges::input_range	R,

		    class Comp = std::less<ranges::range_value_t<R>> >
	  priority_queue(   std::from_range_t,	 R&&,	Comp   =   Comp()    )
       (7) (since C++23)
	      -> priority_queue<ranges::range_value_t<R>,

				std::vector<ranges::range_value_t<R>>,
	  Comp>;
	  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>,
       (8) (since C++23)

				std::vector<ranges::range_value_t<R>,
	  Alloc>, Comp>;
	  template< ranges::input_range	R, class Alloc >

	  priority_queue( std::from_range_t, R&&, Alloc	)
	      ->		      priority_queue<ranges::range_value_t<R>,
       (9) (since C++23)

				std::vector<ranges::range_value_t<R>,
	  Alloc>>;

	  The following	deduction guides are provided for std::priority_queue:

	  1-6)	Allow deduction	from underlying	container type and from	an it-
       erator range.
	  /*iter-value-type*/<It>      denotes	    typename	   std::itera-
       tor_traits<It>::value_type for
	  any type It.
	  7-9)	Allow  deduction  from	a  std::from_range_t  tag  and	an in-
       put_range.

	  These	overloads participate in overload resolution only if

	    * InputIt satisfies	LegacyInputIterator,
	    * Comp does	not satisfy Allocator,
	    * Container	does not satisfy Allocator,
	    * for overloads (4,5),
	      (since C++23) Alloc satisfies Allocator, and
	    * for overloads (3,6), std::uses_allocator_v<Container, Alloc>  is
       true.

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

Notes
	      Feature-test macro       Value	Std		      Feature
	  __cpp_lib_containers_ranges 202202L (C++23)  Ranges-aware  construc-
       tion and	insertion;
						      overloads	(7-9)

Example
       // Run this code

	#include <functional>
	#include <iostream>
	#include <queue>
	#include <vector>

	int main()
	{
	    const std::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::pri-
       ority_queue<int>

	    for	(; !pq2.empty(); pq2.pop())
		std::cout << pq2.top() << ' ';
	    std::cout << '\n';
	}

Output:
	1 2 3 4
	4 3 2 1

	  Defect reports

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

	     DR	     Applied	to		   Behavior    as    published
       Correct behavior
	  LWG  3506  C++17	 deduction  guides from	iterator and allocator
       added
			      were missing

http://cppreference.com		  2024.06.10	 deductiongu...iority_queue(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=deductionguidesforstd::priority_queue&sektion=3&manpath=FreeBSD+Ports+15.1.quarterly>

home | help