迭代表示为 std::basic_string_view 的正则表达式子匹配

Iterating regex submatches represented as std::basic_string_view

是否有使用 std (C++17) 转换 std::sub_match to std::basic_string_view (without constructing an intermediate std::basic_string and without intermediate heap allocation)? Or one abstraction level further, is there an alternative to std::regex_token_iterator for iterating regex submatches represented as std::basic_string_view instead of std::sub_match 的直接有效方法?

我比较喜欢用std::basic_string_view over std::sub_match的原因是:

没有通用的方法来检测迭代器是否连续。我们仍然可以处理已知的连续迭代器——例如 std::string:

std::string_view as_sv(std::ssub_match m) {
    if(!m.matched) return {};
    return { &*m.first, m.second - m.first };
}

处理 sub_match 的其余命名特化留作 reader 的练习。