Put rapidjson under `cereal` namespace
Before the last update of RapidJSON, it was placed under cereal::rapidjson namespace to avoid collisions with other versions of RapidJSON in the same binary, which was very handy. Unfortunately, it's not the case anymore, now Cereal's RapidJSON is defined under its default namespace rapidjson so it conflicts with other RapidJSONs. I propose to put cereal::rapidjson namespace back.
The fix is just to update three lines in include/cereal/external/rapidjson/rapidjson.h. I can send a PR if needed.
You can provide a definition for CEREAL_RAPIDJSON_NAMESPACE_BEGIN in include/cereal/external/rapidjson/rapidjson.h to override the default behavior. That file has additional explanation on this as well.
@AzothAmmo thank you! I did this already for myself but my point is that Cereal should be shipped with rapidjson under cereal namespace by default. The purpose of this is to avoid collision with target project’s rapidjson definitions, which is not a rare case since rapidjson is so widely used.
IMHO it should not be shipped internally at all. This is what we have git-submodules, build systems and package managers for.
Please fix this "I include and mess up library x" issue, it is impossible to use both rapidjson and cereal in vcpkg since cereal has adds a lot of mods in rapidjson.
A library should not bundle/package other libraries, otherwise we can very easily get the diamond problem and ODR violations.
For example, on Ubuntu or Debian, if you install libcereal-dev rapidjson-dev and try to use them both, you will get compilation errors. See this sample code.
#include <cereal/archives/json.hpp>
#include <rapidjson/document.h>
int main() {}
The real solution is to use CMake's find_package(), and rely on cmake to find system's rapidjson.
Other solution is to define CEREAL_RAPIDJSON_NAMESPACE_BEGIN and the other two defines by default to put rapidjson under the namespace of cereal.
If https://github.com/USCiLab/cereal/pull/604 addresses this would really appreciate it getting merged.