deductiongu...forstd::list(3)
okay bestie, this is the deductiongu...forstd::list(3) page from the C++ Standard Libary manual. Title and manual name folded in right at the top β weβre not copying the whole header line, weβre being cute about it. π
πΈ NAME πΈ
Itβs literally deductionguidesforstd::list β and the description is the same exact thing: deductionguidesforstd::list - deductionguidesforstd::list. iconic behavior, honestly. π
β¨ Synopsis β¨
Defined in header <list> β hereβs the whole declaration situation, bestie:
template< class InputIt,
class Alloc = std::allocator<
typename std::iterator_traits<InputIt>::value_type>
>
(1) (since C++17)
list( InputIt, InputIt, Alloc = Alloc() )
-> list<typename std::iterator_traits<InputIt>::value_type,
Alloc>;
template< ranges::input_range R,
class Alloc = std::allocator<ranges::range_value_t<R>> >
(2) (since C++23)
list( std::from_range_t, R&&, Alloc = Alloc() )
-> list<ranges::range_value_t<R>, Alloc>;
- This deduction guide is provided for
listto allow deduction from an iterator range. This overload participates in overload resolution only ifInputItsatisfiesLegacyInputIteratorandAllocsatisfiesAllocator. - This deduction guide is provided for
listto allow deduction from astd::from_range_ttag and aninput_range.
Note, and this part is important: 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. thatβs the whole caveat, fr fr. π«Ά
π§ Notes π§
- Feature-test macro:
__cpp_lib_containers_ranges - Value:
202202L - Std:
(C++23) - Feature:
Ranges-aware construction and insertion; overload (2)
π Example π
Run this code, bestie β comments are part of the code and weβre keeping them exactly:
// Run this code
#include <list>
#include <vector>
int main()
{
std::vector<int> v = {1, 2, 3, 4};
// uses explicit deduction guide to deduce std::list<int>
std::list x(v.begin(), v.end());
// deduces std::list<std::vector<int>::iterator>
// first phase of overload resolution for list-initialization
selects the candidate
// synthesized from the initializer-list constructor; second phase
is not performed
// and deduction guide has no effect
std::list y{v.begin(), v.end()};
}
and thatβs the page, bestie. footer vibes: source/version http://cppreference.com, date 2024.06.10, for deductiongu...forstd::list(3) β mwah πβ¨
π¦ 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