C++ 参考手册
- C++11
 - C++14
 - C++17
 - C++20
 - C++ 编译器支持情况表
 - 独立与宿主实现
 - C++ 语言
 - C++ 关键词
 - 预处理器
 - C++ 标准库头文件
 - 具名要求
 - 功能特性测试 (C++20)
 - 工具库
 - 类型支持(基本类型、RTTI、类型特性)
 - 概念库 (C++20)
 - 错误处理
 - 动态内存管理
 - 日期和时间工具
 - 字符串库
 - 容器库
 - std::array
 - std::vector
 - std::map
 - std::unordered_map
 - std::priority_queue
 - std::span
 - std::forward_list
 - std::forward_list<T,Allocator>::forward_list
 - std::forward_list<T,Allocator>::~forward_list
 - std::forward_list<T,Allocator>::operator=
 - std::forward_list<T,Allocator>::unique
 - std::forward_list<T,Allocator>::reverse
 - std::forward_list<T,Allocator>::sort
 - std::forward_list 的推导指引
 - std::forward_list<T,Allocator>::merge
 - std::forward_list<T,Allocator>::splice_after
 - std::forward_list<T,Allocator>::remove, remove_if
 - operator==,!=,<,<=,>,>=,<=>(std::forward_list)
 - std::swap(std::forward_list)
 - std::erase, std::erase_if (std::forward_list)
 - std::forward_list<T,Allocator>::swap
 - std::forward_list<T,Allocator>::erase_after
 - std::forward_list<T,Allocator>::push_front
 - std::forward_list<T,Allocator>::emplace_front
 - std::forward_list<T,Allocator>::pop_front
 - std::forward_list<T,Allocator>::resize
 - std::forward_list<T,Allocator>::empty
 - std::forward_list<T,Allocator>::max_size
 - std::forward_list<T,Allocator>::clear
 - std::forward_list<T,Allocator>::insert_after
 - std::forward_list<T,Allocator>::emplace_after
 - std::forward_list<T,Allocator>::begin, std::forward_list<T,Allocator>::cbegin
 - std::forward_list<T,Allocator>::end, std::forward_list<T,Allocator>::cend
 - std::forward_list<T,Allocator>::assign
 - std::forward_list<T,Allocator>::get_allocator
 - std::forward_list<T,Allocator>::front
 - std::forward_list<T,Allocator>::before_begin, cbefore_begin
 - std::deque
 - std::list
 - std::set
 - std::multiset
 - std::multimap
 - std::unordered_set
 - std::unordered_multiset
 - std::unordered_multimap
 - std::stack
 - std::queue
 - std::vector<bool>
 - 结点把柄 (C++17)
 - 注释
 - 迭代器库
 - 范围库 (C++20)
 - 算法库
 - 数值库
 - 输入/输出库
 - 文件系统库
 - 本地化库
 - 正则表达式库
 - 原子操作库
 - 线程支持库
 - 实验性 C++ 特性
 - 有用的资源
 - 索引
 - std 符号索引
 - 协程支持 (C++20)
 - C++ 关键词
 
位置:首页 > C++ 参考手册 >容器库 >std::forward_list > std::forward_list 的推导指引
std::forward_list 的推导指引
|   定义于头文件  <forward_list>
  | 
||
|   template< class InputIt,           class Alloc = std::allocator<typename std::iterator_traits<InputIt>::value_type>>  | 
(C++17 起) | |
为 forward_list 提供此推导指引,以允许从迭代器范围推导。此重载仅若InputIt 满足遗留输入迭代器 (LegacyInputIterator) 且 Alloc 满足分配器 (Allocator) 才参与重载决议
注意:库确定类型是否满足遗留输入迭代器 (LegacyInputIterator) 的程度是未指定的,除了最低要求是整数类型不具备输入迭代器的条件。类似地,确定类型是否满足分配器 (Allocator) 是未指定的,除了最低要求是成员类型 Alloc::value_type 必须存在,且表达式 std::declval<Alloc&>().allocate(std::size_t{}) 在作为不求值操作数时必须为良构。
示例
运行此代码
#include <forward_list> #include <vector> int main() { std::vector<int> v = {1, 2, 3, 4}; // 使用显式推导指引推导 std::forward_list<int> std::forward_list x(v.begin(), v.end()); // 推导 std::forward_list<std::vector<int>::iterator> // 列表初始化的重载决议第一阶段选择从 initializer_list 构造函数合成的候选 // 不进行第二阶段且推导指引无效果 std::forward_list y{v.begin(), v.end()}; }