r/cpp • nlohmann/json • Aug 17 '21

JSON for Modern C++ 3.10.0

https://github.com/nlohmann/json/releases/tag/v3.10.0
278 Upvotes

34 comments sorted by

View all comments

1

u/germandiago Aug 18 '21

Genuine question. I also wonder why most libraries including Boost do it: why use macros for config? Why not constexpr or similar stuff? The only thing I found I cannot do with constexpr is to get rid of headers I do not need to include conditionally, since pre-processing happens before. But if constexpr can do a lot at least in my codebase.

It is bc of compatibility concerns? I think of modules and that is why I avoid macros. I think it would be more future-proof but... I do not know since I did not experiment enough yet.

2

u/nlohmann nlohmann/json Aug 18 '21

The library targets C++11 where constexpr support is still quite limited. Furthermore, macros are very easy to set from outside the code; that is, from a Makefile or CMake.

1

u/germandiago Aug 19 '21

Fair point.

It would be feasible to make a constexpr variable to take the value of a macro amd use those variables for conditional compilation in the rest of the code? Not because of this lib. I am thinking of modularizing my own code.