nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
41.33k stars 6.58k forks source link

Conditional Compilation for C++17 Compatibility #4166

Closed iconnor closed 9 months ago

iconnor commented 9 months ago

This pull request wraps two specific files in a conditional compilation block to allow builds using the C++17 standard. The goal is to enhance compatibility without affecting existing functionality.

Motivation: I am utilizing this library in a PlatformIO project that uses C++17 for both native CI/CD and testing purposes. While I understand that the library aims to use the latest C++ standards, there are scenarios where projects may need to use older but still widely-used standards like C++17.

Changes: Wrapped the offending code in #if __cplusplus >= 202002L ... #endif blocks to allow compilation under C++17. Benefits: Increases the library's compatibility with projects that are not yet able to migrate to C++20. Allows for more diverse usage in larger codebases that may be using multiple C++ standards. No impact on existing functionality when used in a C++20 environment. Alternative Considered: An alternative could be to completely exclude these files during the build process, but conditional compilation offers a less invasive approach.


Pull request checklist

Read the Contribution Guidelines for detailed information.

Please don't

gregmarr commented 9 months ago

This library is actually 100% C++11 compatible. It can take advantage of later standards if you compile with them, but it doesn't require anything later than that.

The files you modified are examples used in the documentation, not part of the library itself.

nlohmann commented 9 months ago

What your code is proposing is already done in the library: any feature that is not pure C++11 is guarded by macros. The MR like this makes no sense, because the example files are just documentation.