特点

初始化方式

🔹1. 默认构造

std::forward_list<int> fl;  // 空链表

🔹2. 指定大小

std::forward_list<int> fl(5);  // 5 个默认元素(int 为 0)

🔹3. 指定大小与初始值

std::forward_list<int> fl(3, 99);  // {99, 99, 99}

🔹4. 初始化列表(C++11)

std::forward_list<int> fl = {1, 2, 3, 4};

🔹5. 区间构造

std::vector<int> v = {1, 2, 3};
std::forward_list<int> fl(v.begin(), v.end());

🔹6. 拷贝 / 移动构造

std::forward_list<int> a = {1, 2, 3};
std::forward_list<int> b(a);             // 拷贝
std::forward_list<int> c(std::move(a));  // 移动