跳转至

ev-abseil-range-for-literals-003

字段 值
项目 abseil/abseil-cpp
固定 commit 2065f4ded055
路径 absl/time/format.cc
行段 L111-L117
特性 范围 for 循环
许可证 Apache-2.0
代码来源 项目源码
级别 manual
审核 zyuhao7 @ 2026-10-27
测试代码 否
发现方式 manual

用法

用 const auto& 的 range-for 遍历静态数组并匹配前缀

为什么典型

只读遍历固定字面量表,const auto& 避免复制且表明不修改元素。

摘录

  for (const auto& lit : kLiterals) {
    if (absl::StartsWith(input, lit.name)) {
      absl::string_view tail = input.substr(lit.name.size());
      // The trailing portion must be empty or whitespace.
      if (StripLeadingAsciiWhitespace(tail).empty()) {
        *time = lit.value;
        return true;

备注

生产路径;时间解析先检查无穷远、无穷过去等特殊字面量。

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