deductiongu...forward_list(3)
π deduction guides for std::forward_list π
okay bestie, this is the manual page deductiongu...forward_list(3) from the C++ Standard Libary (yes, that spelling is straight from the header, not me π), and we're about to make deduction guides for std::forward_list make sense. no cap, it's giving tiny page with big C++17/C++23 energy β¨
πΈ NAME πΈ
deductionguidesforstd::forward_list - deductionguidesforstd::forward_list
like, yes, the name is literally that twice with a hyphen in the middle. iconic manpage behavior π
π Synopsis π
Defined in header <forward_list>
template< class InputIt,
class Alloc = std::allocator<
typename std::iterator_traits<InputIt>::value_type>
>
(1) (since C++17)
forward_list( InputIt, InputIt, Alloc = Alloc() )
-> forward_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)
forward_list( std::from_range_t, R&&, Alloc = Alloc() )
-> forward_list<ranges::range_value_t<R>, Alloc>;
(1)β this deduction guide is provided forforward_listto allow deduction from an iterator range π§. This overload participates in overload resolution only ifInputItsatisfiesLegacyInputIteratorandAllocsatisfiesAllocator.(2)β this deduction guide is provided forforward_listto allow deduction from astd::from_range_ttag and aninput_rangeπ¦.
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 π
the feature-test macro situation is:
__cpp_lib_containers_rangesβ value:202202L; std:(C++23); feature: "Ranges-aware construction and insertion; overload (2)" π
π Example π
// Run this code
#include <forward_list>
#include <vector>
int main()
{
std::vector<int> v = {1, 2, 3, 4};
// uses explicit deduction guide to deduce std::forward_list<int>
std::forward_list x(v.begin(), v.end());
// deduces std::forward_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::forward_list y{v.begin(), v.end()};
}
lowkey obsessed with how x gets std::forward_list<int> and y gets std::forward_list<std::vector<int>::iterator> because of that two-phase overload resolution thing β the deduction guide has no effect there, periodt π
and that's the page, bestie! footer vibe check: http://cppreference.com Β· 2024.06.10 Β· deductiongu...forward_list(3) π«Άβ¨
π¦ 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