deductiongu...rstd::queue(3)
π NAME π
deductionguidesforstd::queue β like, literally the deduction guides for std::queue, no cap, that's the whole name π«Ά
This page lives in the C++ Standard Libary manual, and it's deductiongu...rstd::queue(3) if you're the kind of icon who needs the exact lookup string β¨
πΈ Synopsis πΈ
Okay bestie, first things first β this whole situation is Defined in header <queue> π
template< class Container >
queue( Container )
(1) (since C++17)
-> queue<typename Container::value_type, Container>;
template< class Container, class Alloc >
queue( Container, Alloc )
(2) (since C++17)
-> queue<typename Container::value_type, Container>;
template< class InputIt >
queue( InputIt, InputIt )
(3) (since C++23)
-> queue<typename std::iterator_traits<InputIt>::value_type>;
template< class InputIt, class Alloc >
queue( InputIt, InputIt, Alloc )
(4) (since C++23)
-> queue<typename std::iterator_traits<InputIt>::value_type,
std::deque<typename std::iterator_traits<InputIt>::value_type, Alloc>>;
template< ranges::input_range R >
queue( std::from_range_t, R&& )
(5) (since C++23)
-> queue<ranges::range_value_t<R>>;
template< ranges::input_range R, class Allocator >
queue( std::from_range_t, R&&, Allocator )
(6) (since C++23)
-> queue<ranges::range_value_t<R>,
std::deque<ranges::range_value_t<R>, Allocator>>;
So here's the tea β β these deduction guides are provided for queue to allow deduction from the underlying container type. That's the whole point, and honestly? Iconic behaviour.
- Deduces the underlying container type from the argument. Simple. Clean. Slay. π
- Same as (1), except that the allocator is provided. She brought a friend π«Ά
- Deduces the element type from the iterator, using
std::deque<typename std::iterator_traits<InputIt>::value_type>as the underlying container type. - Same as (3), except that the allocator is provided.
- Deduces the element type from a
std::from_range_ttag and aninput_range. - Same as (5), except that the allocator is provided. Allocator girlies stay winning π
β¨ When do these even show up tho β¨
These overloads participate in overload resolution only if β¬οΈ
InputIt(if it exists) satisfiesLegacyInputIterator,Container(if it exists) does not satisfyAllocator,- for (3) (until C++23) (4) (since C++23),
AllocsatisfiesAllocator, and std::uses_allocator_v<Container, Alloc>istrueif bothContainerandAllocexist.
π¨ Note, and pls actually read this one: the extent to which the library determines that a type does not satisfyLegacyInputIteratoris 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 satisfyAllocatoris unspecified, except that as a minimum the member typeAlloc::value_typemust exist and the expressionstd::declval<Alloc&>().allocate(std::size_t{})must be well-formed when treated as an unevaluated operand. Big words, huge meaning, don't skip her π
π¦ Notes π¦
Feature-test macro moment, bestie β this is the β¨ receipts β¨ section π
__cpp_lib_adaptor_iterator_pair_constructorβ value202106L, std(C++23), feature: Iterator pair constructors forstd::queueandstd::stack; overloads (2) and (4)__cpp_lib_containers_rangesβ value202202L, std(C++23), feature: Ranges-aware construction and insertion; overloads (5) and (6)
Like, the way these macros are literally just sitting there documenting which overloads ate ππ₯
π Example π
// Run this code
#include <queue>
#include <vector>
int main()
{
std::vector<int> v = {1, 2, 3, 4};
std::queue s{v}; // guide #1 deduces std::queue<int, vector<int>>
}
Look at her go π guide #1 doing all the work, deducing std::queue<int, vector<int>> from a single brace-init. Main character energy fr fr π
Okay that's the whole page, bestie β go forth and let the compiler do the deducing for you, you absolute genius π§ββοΈπ
Pssst, this one's from cppreference athttp://cppreference.com, dated2024.06.10, and it's thedeductiongu...rstd::queue(3)page β cite her correctly or she'll haunt your build logs π₯π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms