The following code:
json::value params;
params[U("version")] = json::value("1.0");
results in the following JSON: `{"version":true}` under Windows, as `"1.0"` literal is implicitly converted to `bool` as it's a pointer. This is rather unfortunate and it would be nice to avoid it.
I think the simplest way to solve it would be to add a deleted ctor from narrow strings, i.e.
class value {
#ifdef _UTF16_STRINGS
value(const char*) = delete;
#endif
};
to prevent this code from compiling.
Although personally I'd be even happier if the code accept narrow strings everywhere, even under Windows, and assumed them to be in UTF-8 and did the necessary conversions transparently, this comes at a tiny performance cost but is much more user-friendly.
Comments: The explicit constructor doesn't prevent implicit conversions. ``` struct Foo { explicit Foo(bool b) {} }; int main() { Foo f("Hello, world!"); } ``` Compiles clean: ``` PS C:\test> cl /nologo main.cpp main.cpp ``` The fix will have to be something like ``` struct Foo { explicit Foo(bool b) {} explicit Foo(const char*) = delete; }; ```
json::value params;
params[U("version")] = json::value("1.0");
results in the following JSON: `{"version":true}` under Windows, as `"1.0"` literal is implicitly converted to `bool` as it's a pointer. This is rather unfortunate and it would be nice to avoid it.
I think the simplest way to solve it would be to add a deleted ctor from narrow strings, i.e.
class value {
#ifdef _UTF16_STRINGS
value(const char*) = delete;
#endif
};
to prevent this code from compiling.
Although personally I'd be even happier if the code accept narrow strings everywhere, even under Windows, and assumed them to be in UTF-8 and did the necessary conversions transparently, this comes at a tiny performance cost but is much more user-friendly.
Comments: The explicit constructor doesn't prevent implicit conversions. ``` struct Foo { explicit Foo(bool b) {} }; int main() { Foo f("Hello, world!"); } ``` Compiles clean: ``` PS C:\test> cl /nologo main.cpp main.cpp ``` The fix will have to be something like ``` struct Foo { explicit Foo(bool b) {} explicit Foo(const char*) = delete; }; ```