-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Reference tuple from json #5016
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
Draft
EALePain
wants to merge
8
commits into
nlohmann:develop
Choose a base branch
from
EALePain:reference_tuple_from_json
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @EALePain |
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
…tions. Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
255b21c to
f36fd05
Compare
Author
|
ultimately I realized copy elation of the whole tuple is probably the more efficient route than elating moves for string, object, and array types allowed with the const reference returning overload. |
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @EALePain |
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.
The current std::tuple from_json implementations fail to work with std::tie, aka tuples with reference types. The reason for this is that the template types are maintained all the way to the call to
get<Args>()resulting in things likeget<int&>(). The PR modifies this behavior to remove the references from all incoming types if those references are incompatible with the json type being used.Ultimately this change allows for the result of std::tie to be used with get_to and allows the get method to create std::tuples of references to contained values.
The specific set of changes needed to achieve this are:
is_compatible_reference_typemetaprogramming struct that contains ::value = true if the BasicJsonType given has a get_ref instantiation that accepts CompatibleReferenceType (I used get_ptr because SFINAE was not working correctly with get_ref). This allows for overload resolution to decide to use get (and decay the type) or get_ref if a reference type is available for the individual elements of the tuple.||and&&(with not for semantic consistency) in version older than 17. This is needed for the static assert (which I discuss later)from_json_tuple_get_imploverload set. In reverse priority order they:get<T>on the json, returning by valuetuple_typethat figures out the return type of a call tofrom_json_tuple_get_implso that a tuple of exactly the correct types can be constructed from calls to it.from_json_tuple_impl_baseimplementations adding a priority tag value template argument (to circumvent thefrom_json_tuple_get_impl(..., priority_tag<2>)implementation for calls to get references to members) and to returntuple_typeand usefrom_json_tuple_get_impl.from_json_tuple_impl(..., identity_tag<std::tuple<Args...>>, ...)to explicitly disallow reference types that are not compatible with the json type. This is done because this function must return exactly the type in the identity_tag, but the function it calls will return values when dealing with incompatible references. This creates a dangling reference in the return. If desired, this static assert could be moved into an enable_if on the return to preserve SFINAE, but I could not think of a scenario where SFINAE would allow for recovery from this point during instantiation.get_to(std::tie(...))andget<std::tuple<const T&,...>>()and to confirm arithmetic types do not try to pull references even when they are number types.I would also like to potentially discuss modifying
get_toto allow for rvalue references in cases like std::tie and mutable range views such as std::span (if it has not already been discussed).If applicable, an existing issue is referenced.make amalgamate.Read the Contribution Guidelines for detailed information.
(edited to reflect current implementation as of Nov 29)