Should YAML::detail::iterator_value really be part of the detail namespace? (Support for C++20 ranges)
まだ誰も着手していません。
評価
調査の方向性
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分
- マージ済み PR(30日)
- 1
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
jbeder/yaml-cpp の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
eclipse-score/lifecycle#929 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
colbymchenry/codegraph#3223 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
firefox-devtools/profiler#6436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信