deductiongu...rstd::stack(3)
π NAME π
okay so bestie, welcome to deductiongu...rstd::stack(3) β straight outta the C++ Standard Libary (yes, that's how the header spells it π). This page is literally the deduction-guide glow-up for std::stack.
The name is a mouthful: deductionguidesforstd::stack β and the official one-liner is deductionguidesforstd::stack - deductionguidesforstd::stack. no cap, that's the whole NAME vibe. β¨
β¨ SYNOPSIS β¨
Defined in header <stack>:
template< class Container >
stack( Container )
(1) (since C++17)
-> stack<typename Container::value_type, Container>;
template< class Container, class Alloc >
stack( Container, Alloc )
(2) (since C++17)
-> stack<typename Container::value_type, Container>;
template< class InputIt >
stack( InputIt, InputIt )
(3) (since C++23)
-> stack<typename std::iterator_traits<InputIt>::value_type>;
template< class InputIt, class Alloc >
stack( InputIt, InputIt, Alloc )
(4) (since C++23)
-> stack<typename std::iterator_traits<InputIt>::value_type,
std::deque<typename std::iterator_traits<InputIt>::value_type, Alloc>>;
template< ranges::input_range R >
stack( std::from_range_t, R&& )
(5) (since C++23)
-> stack<ranges::range_value_t<R>>;
template< ranges::input_range R, class Allocator >
stack( std::from_range_t, R&&, Allocator )
(6) (since C++23)
-> stack<ranges::range_value_t<R>,
std::deque<ranges::range_value_t<R>, Allocator>>;
These deduction guides are provided for stack to allow deduction from underlying container type. π
- Deduces underlying container type from the argument.
- Same as (1), except that the allocator is provided.
- 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.
These overloads participate in overload resolution only if:
InputIt(if exists) satisfiesLegacyInputIterator,Container(if exists) does not satisfyAllocator,- for (3) (until C++23) (4) (since C++23),
AllocsatisfiesAllocator, and std::uses_allocator_v<Container, Alloc>is true if bothContainerandAllocexist.
Note: 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. π«Ά
π§ NOTES π§
Feature-test macro tea, bestie β β here's the whole table vibe:
__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).
π EXAMPLE π
// Run this code
#include <stack>
#include <vector>
int main()
{
std::vector<int> v = {1, 2, 3, 4};
std::stack s{v}; // guide #1 deduces std::stack<int, vector<int>>
}
and that's the whole flex β guide #1 literally deduces std::stack<int, vector<int>> from std::stack s{v};. iconic. π
mwah π β source: http://cppreference.com, version/date: 2024.06.10, page: deductiongu...rstd::stack(3). bye bestie, go deduce something cute π
π¦ 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