feat: Allow decoding for types without default constructor - #1479
Open
SGSSGene wants to merge 1 commit into
Open
feat: Allow decoding for types without default constructor#1479SGSSGene wants to merge 1 commit into
SGSSGene wants to merge 1 commit into
Conversation
SGSSGene
force-pushed
the
feat/not-default-decoder
branch
from
August 10, 2026 09:27
2897332 to
41be05a
Compare
SGSSGene
force-pushed
the
feat/not-default-decoder
branch
4 times, most recently
from
August 10, 2026 10:46
9522ee9 to
d1f8ebc
Compare
Collaborator
Author
|
Maybe it also enough to consider it as a fix for #506 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is inspired by #1010, but instead of creating a new customization point via
decode_dispatcherit reusesconvertby usingconvert<std::optional<T>>specialization for non-default constructible classes.If cmake variable
YAML_CPP_USE_OPTIONALis set (automatically set if target is c++17 or above) this new feature is activated. It can be deactivated by settingYAML_CPP_USE_OPTIONALto false to force old behavior if desired.When decoding a type
T, it will useconvert<std::optional<T>>and forward toconvert<T>if not available.The signature requirements are as before but by using the additional
std::optionalit allows us to delay the construction of our type T.Assume we have some type without default constructor:
you could write
To implement encoding for Vec3 one must still implement
convert<Vec3>with theencodemethod.Notes:
fixes #973 #993
alternative for PR #1010 and #1087
PR #1087 breaks API and relies on exception paths which I don't like, since this seems like normal control flow to me.