-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
node/convert: relax the check for string_view #1222
Conversation
in 35b4498, the conversion for `std::string_view` was added, but it enables it only if C++17 is used. but the availability of `std::string_view` does not depends on C++17. in this change, we use the more specific language feature macro to check the availability of `std::string_view` instead of checking for the C++ standard. Refs jbeder#1148 Signed-off-by: Kefu Chai <tchaikov@gmail.com>
80c227a
to
bad22f4
Compare
@jbeder hi Jesse, i was trying to address the comment of #1148 (comment) . but yeah, i was wrong following @0xFireWolf 's comment, as |
This reverts commit 6262201. in 6262201, we wanted address the needs to use the `string_view` converter in C++98, but that requirement was based on wrong preconditions. `std::string_view` was introduced in C++17, and popular standard libraries like libstdc++ and libc++ both provide `std::string_view` when the source is built with C++17. furthermore 6262201 is buggy. because it uses `<version>` to tell the feature set provided by the standard library. but `<version>` is a part of C++20. so this defeats the purpose of the change of 6262201.
This reverts commit 6262201. in 6262201, we wanted address the needs to use the `string_view` converter in C++98, but that requirement was based on wrong preconditions. `std::string_view` was introduced in C++17, and popular standard libraries like libstdc++ and libc++ both provide `std::string_view` when the source is built with C++17. furthermore 6262201 is buggy. because it uses `<version>` to tell the feature set provided by the standard library. but `<version>` is a part of C++20. so this defeats the purpose of the change of 6262201. Fixes jbeder#1223
Oops, I completely forgot that feature-test macros are only available as of C++20. I apologize for my previous comment. Now I see two possible options here:
I personally prefer the first option, because compilers that are still actively maintained all support C++17. However, if you care a lot about backward compatibility, then the second option seems to be a better solution. |
Link to the description of |
@0xFireWolf i'd prefer using the platform neutral and standard compliant way. could you help me understand the advantage of checking |
@tchaikov I made two suggestions in your latest PR. Simply reverting your commit won't fix the issue I mentioned in #1148 (comment) on Windows. |
i don't claim that reverting the commit address your concern. i am trying to address the regression. i think, that is more important to the existing users of this library.
i am confused, if they don't pass |
Let me clarify the issue from the beginning, and I hope it could clarify your confusion. You first PR (#1148) added conversion support for Now, there are multiple possible solutions to this issue.
Each solution has different tradeoffs. In my humble opinion, the first solution is not wise, because the library author must explicitly state this requirement in the documentation, while developers must manually add that compiler option if they haven't done so. The second solution, while I love it, does not care about backward compatibility and thus abandons all pre-C++17 developers. The third solution, which I suggested in your latest PR (#1225), seems to be the best one, because it fixes the issue on Windows without affecting *nix and Mac developers. Now back to myself. The C++20 project I am working on needs a YAML parser and supports Linux, macOS and Windows. I recently upgraded @jbeder Please feel free to chime in and make the final decision. |
For your convenience, I copied the description of
The description of
So if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L)
//...
#endif |
thank you @0xFireWolf . now i get your point better. i was under the impression that
so, to be more specific, the status is that the projects compiled using MSVC but not with
i don't get this part though. probably the error is not specific enough for me to understand. because before you upgraded to yaml-cpp 0.8.0, you should already be using your own converter, right? so, IIUC, you updated your code to use the new convertor. and all of a sudden, the CI fails on MSVC. but it passes on platforms where the compiler defines the discrepancy caused by the missing actually there is one more option: to pass well, personally i consider the check for #if __cplusplus >= 201703L
#define YAML_DEFINE_HAS_STRING_VIEW 1
#elif defined(_MSVC_LANG) && _MSVC_LANG >= 201703L
#define YAML_DEFINE_HAS_STRING_VIEW 1
#else
#define YAML_DEFINE_HAS_STRING_VIEW 0
#endif in |
MSVC always defines the macro
Correct.
Yes, I manually specialized the template for
This is wrong.
I don't think this is a good idea.
This seems better, especially if the library uses |
okay. sorry for the confusion, i should have replaced "define" with "define the right". |
This reverts commit 6262201. in 6262201, we wanted address the needs to use the `string_view` converter in C++98, but that requirement was based on wrong preconditions. `std::string_view` was introduced in C++17, and popular standard libraries like libstdc++ and libc++ both provide `std::string_view` when the source is built with C++17. furthermore 6262201 is buggy. because it uses `<version>` to tell the feature set provided by the standard library. but `<version>` is a part of C++20. so this defeats the purpose of the change of 6262201. Fixes #1223
in 35b4498, the conversion for
std::string_view
was added, but it enables it only if C++17 is used. but the availability ofstd::string_view
does not depends on C++17. in this change, we use the more specific language feature macro to check the availability ofstd::string_view
instead of checking for the C++ standard.Refs #1148
Signed-off-by: Kefu Chai tchaikov@gmail.com