-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Using custom string. #2398
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I can reproduce your findings, but not yet understood the error. |
I could create a minimal wrapper around class my_string {
public:
using value_type = std::string::value_type;
using size_type = std::string::size_type;
my_string() {}
my_string(const value_type* s) : _s(s) {}
my_string(std::initializer_list<value_type> ilist) : _s(ilist) {}
~my_string() {}
const value_type* data() const noexcept {
return _s.data();
}
size_type size() const noexcept {
return _s.size();
}
void clear() noexcept {
_s.clear();
}
void push_back(size_type ch) {
_s.push_back(ch);
}
friend bool operator<(const my_string& lhs, const my_string& rhs)
{
return lhs._s < rhs._s;
}
private:
std::string _s;
}; I am not sure whether it is complete, but it helped me find a problem in your code. After removing the constructor my_string(char){} your code compiles. |
Sorry for not updating the issue sooner. Yes, thanks, removing that constructor does help. Additional gripe was with Looks like int_to_string was reported also in #2059 and commit aeef507 linked as a fix, but not sure how that is supposed to work: https://godbolt.org/z/aEWbM6joo |
@armatti you're right that the referenced commit does not do what it was intended to do. ADL is for the "arguments" of the function, not the return type. However, looks like you can use ADL to replace this function instead, which is what it sounds like you did.
FYI @dota17 |
As problems could be solved without modifying nlohmann::json, I'm happy to close this issue. |
I've tried using custom containers with nlohmann::json.
ObjectType
andArrayType
can be swapped, but changingStringType
breaks creating json from most types.Here's a minimal, non-functional string implementation, that builds as long as you don't try to create a json from other types than string literals: https://godbolt.org/z/GTvn8T
If I read correctly
nlohmann::detail::detector
fails to find a matchingto_json
function, but I don't understand how changingStringType
has anything to do with it. ShouldStringType
be replaceable? Does it then need a custom serializer or what's the trick?The text was updated successfully, but these errors were encountered: