You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the great library!
We have some strong types which wraps std::string. These provide explicit operator std::string_view(); However if this type is a key in a json dictionary, it will have extra quotes pre/appended to it (Foo{"hello"} -> "\"hello\"").
Due to our class not being implicitly convertible to string_view, we end up in the else block, getting the key quoted.
Would it be possible to use the std::constructible_from<std::string_view, T> instead of the std::convertible_to in the str_t definition, as it would allow structs with explicit conversions to also function as keys without quotes?
Might be related to #1477 but the proposed solution is a bit different.
The text was updated successfully, but these errors were encountered:
anders-wind
changed the title
use std::constructible_from in str_t to support objects with explicit conversion to string_view
Proposal to use std::constructible_from in str_t to support objects with explicit conversion to string_view
Dec 11, 2024
anders-wind
changed the title
Proposal to use std::constructible_from in str_t to support objects with explicit conversion to string_view
Proposal to use std::constructible_from in str_t to support objects with explicit conversion to string_view
Dec 11, 2024
Hi,
Thanks for the great library!
We have some strong types which wraps std::string. These provide
explicit operator std::string_view();
However if this type is a key in a json dictionary, it will have extra quotes pre/appended to it (Foo{"hello"} -> "\"hello\""
).We traced the code to:
and the definition of
str_t
toDue to our class not being implicitly convertible to string_view, we end up in the else block, getting the key quoted.
Would it be possible to use the
std::constructible_from<std::string_view, T>
instead of thestd::convertible_to
in thestr_t
definition, as it would allow structs with explicit conversions to also function as keys without quotes?Godbolt example of the concepts: https://godbolt.org/z/KbKa8nY7c
Might be related to #1477 but the proposed solution is a bit different.
The text was updated successfully, but these errors were encountered: