跳转至

ev-mold-abbrev-template-append-001

字段 值
项目 rui314/mold
固定 commit 27162691b71a
路径 lib/common.h
行段 L412-L415
特性 缩写函数模板(abbreviated function templates)
许可证 MIT
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-26
测试代码 否
发现方式 manual

用法

在部分模板参数已写出的函数中,用 const auto& 接收未具名类型的容器

为什么典型

只需要元素类型 T 时,拼接参数的具体容器类型无关紧要;auto 参数让一个函数接受任意可遍历容器。

摘录

template <typename T>
inline void append(std::vector<T> &x, const auto &y) {
  x.insert(x.end(), y.begin(), y.end());
}

备注

生产路径;显式模板参数与缩写参数混用,展示只约束必要类型时的写法。

查看固定 commit 源码 · 返回证据索引