Should YAML::detail::iterator_value really be part of the detail namespace? (Support for C++20 ranges)
还没有人认领这个 Issue。
评估
调研方向
The question is whether YAML::detail::iterator_value, which the reproducer in the issue uses directly, should be promoted to public API so that YAML::Node works with C++20 ranges such as std::ranges::all_of. Start by finding where that type is declared and how YAML::Node's iterator exposes its value type, then compare with the iterator-based loop in the wiki. Done means a maintainer has decided on the public type name and its exposure, and the change is covered by a test that iterates a node with a range algorithm.
由索引模型根据 Issue 内容生成。
描述
A yaml node technically satisfies the the requirements for a range - however, the range value type of a YAML::Node is not technically part of the public interface of yaml-cpp. Consider the following example
#include <cstdlib>
#include <string_view>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <yaml-cpp/yaml.h>
constexpr std::string_view SRC =
"scrambled-eggs:\n"
" ingredient.egg: 2\n"
" ingredient.butter: 1 tbsp\n"
" ingredient.salt: 1 pinch";
bool IsIngredient(const std::string_view Path)
{
return std::strstr(Path.data(), "ingredient.") != nullptr;
}
bool IsValid(const YAML::detail::iterator_value & Value)
{
return IsIngredient(Value.first.Scalar());
}
int main()
{
const YAML::Node Src = YAML::Load(SRC.data());
const YAML::Node RecipeConfig = Src["scrambled-eggs"];
const bool AllValid = std::ranges::all_of(RecipeConfig, IsValid);
std::cout << "All valid ingredients? " << (AllValid? "Yes" : "No") << "\n";
return EXIT_SUCCESS;
}
This is prefectly valid C++20 code - it compiles and outputs All valid ingredients? Yes. However, you might argue that this isn't perfectly valid yaml-cpp code, since it uses an internal data type YAML::detail::iterator_value which I don't think is part of the public API? However, this code is much more concise, and - at the risk of sounding subjective - I would also argue much more legible than the equivalent code using an iterator-based for-loop as suggested in the wiki pages.
So I guess the point of this post is to make a request that the iterator value of a YAML::Node should be part of the public API and not be an internal detail.
- 主要语言
- C++
- 星标
- 6.1k
- 派生
- 2.2k
- 平均合并
- 22 小时 2 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jbeder/yaml-cpp 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 3/5 1-2 天 新手友好度 62/100
-
难度 3/5 半天 新手友好度 55/100
-
难度 3/5 1-2 天 新手友好度 62/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
llvm/offload-test-suite#1703 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
BGI-shenzhen/PopLDdecay#25 ·
-
难度 2/5 1-3 小时 新手友好度 79/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 68/100
eic/TimeframeBuilder#102 ·