is it possible to have a partial fallback on struct custom types?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start by reading the linked conversion tutorial and the Node::as and convert<T> APIs. The issue asks whether structured custom types can support per-field fallback values, including an override passed to as; it does not identify files or tests. Done means deciding whether this API belongs in yaml-cpp and, if so, specifying and testing how partial fallbacks work.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
for e.g. given
https://github.com/jbeder/yaml-cpp/wiki/Tutorial#converting-tofrom-native-data-types
namespace YAML {
template<>
struct convert<Vec3> {
static Node encode(const Vec3& rhs) {
Node node;
node.push_back(rhs.x);
node.push_back(rhs.y);
node.push_back(rhs.z);
return node;
}
static bool decode(const Node& node, Vec3& rhs) {
//if(node.size() != 3) {
// return false;
// }
rhs.x = node["x"].as<double>();
rhs.y = node["y"].as<double>();
rhs.z = node["z"].as<double>();
return true;
}
};
}
would it be possible to have z as optional so the last decode line would be something like:
rhs.x = node["x"].as<double>();
rhs.y = node["y"].as<double>();
rhs.z = node["z"].as<double>(0.0); // note the fallback here
in this case instead of hard-coding a 0.0 would it be possible to pass a value as a fallback?
rhs.x = node["x"].as<double>();
rhs.y = node["y"].as<double>();
rhs.z = node["z"].as<double>(z_fallback);
and when using it to decode a YAML document that for e.g. has only x and y. is it possible to specify the Z fallback, kind of:
{
// without any fallback as x,y,z are present
YAML::Node node = YAML::Load("start: {x:1, y:3, z:0}");
Vec3 v = node["start"].as<Vec3>();
}
{
// z fallback
YAML::Node node = YAML::Load("start: {x:1, y:3}");
Vec3 v = node["start"].as<Vec3>({.z=z_fallback}); // here there is no way to pass a "partial fall back" as i am aware of.
}
a workaround for this partial fallback could be:
when decoding, use a special value to indicate fallback has happened, so after conversion with .as, check that special value and replace with the right fallback. But this requires a value to not be used and be reserved. not always possible.
another one is to use a global value for the fallback to change as needed before the .as call.
Is there any undocumented way to achieve such a partial fallback "elegantly"?
Would it make any sense from a yaml-cpp perspective to allow decoding having partial fall-back on a structured type?
Would it be possible to add in the convert template such kind of partial fallbacks functionalities?
like storing one T to be used as fallback, that can be overridden when calling the higher level .as with fallback that is passing it to template struct convert so it will use those as fallbacks? or something like that?
- Ngôn ngữ chính
- C++
- Star
- 6.1k
- Fork
- 2.2k
- Merge trung bình
- 22 giờ 2 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của jbeder/yaml-cpp
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Explicit `!!null` tag with empty content loads as a Scalar node instead of NullCó thể đã có người làm @ppc64el đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 62/100
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 55/100
Tất cả issue của jbeder/yaml-cpp
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Niko1221/Strata#5560 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
NVIDIA windows
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[辞書] C/C++のプリプロセッサ指令名を英字のままにするĐang mở要トリアージ 辞書
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
yksr-melt/Meltype#1625 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[yugabyted] xcluster set_up and add_to_replication fail for database names containing - . or (Đang mởkind/bug priority/medium qa_automation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
yugabyte/yugabyte-db#37324 ·
Maintainer thường phản hồi trong vòng 1 ngày