-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better support for "default" #973
Comments
Hey there, I am running into a similar problem at the moment and just found this. However, I'd like to have this implemented a bit different. Leave Add |
For future reference, until a template <typename T>
bool decodeInto(const YAML::Node& node, T& object)
{
return node && YAML::convert<T>::decode(node, object);
} What was originally: auto object = node.as<Object>(); // <-- internally default-constructed Becomes: Object object;
// initialize object as needed
bool ok = decodeInto(node, object);
Note that this decode into method allows me to de-serialize to objects that exist before Related #993/#1087: This PR tackles the same problem and proposes a solution where the object is constructed inside the Related #1010: A similar PR, tackling the same problem. And like with #1087, I see issues with constructing the object inside the de-serialization logic. The example shown in #1010 seems fine as long as all information necessary to construct the object can be found in the given node (or sub-nodes). But if needed information is not available there, constructing the object becomes more complicated. |
YAML is often used for configuration input, and it's a bit difficult to manage defaults:
Current:
Proposed:
Roadmap:
Node
. Bikeshedding on name is on the table.into
just reads niceas_if
struct with a function, sayupdate
, innode/impl.h
to not create the default variableinto
(newly added templated function) calls theupdate
function.Proposed change in
as_if
:I can create a PR if needed, but I'm confused about the overloads for
S = void
caseThe text was updated successfully, but these errors were encountered: