-
-
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
base: develop
Are you sure you want to change the base?
Conversation
🔴 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
|
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 |
0e4d300 to
0bb6948
Compare
🔴 Amalgamation check failed! 🔴The source code has not been amalgamated. @EALePain |
5e9c010 to
33c9f2b
Compare
…15 doesn't like it Signed-off-by: Evelyn LePain <ava.lepain@gmail.com>
33c9f2b to
a583225
Compare
|
🥳 Green CI! I will try to review this in the next week. |
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)