September 2017
Beginner to intermediate
384 pages
9h 18m
English
The variant data type is good at representing simple alternatives, but as of C++17, it is not particularly suitable for representing recursive data types such as JSON lists. That is, the following C++17 code will fail to compile:
using JSONValue = std::variant< std::nullptr_t, bool, double, std::string, std::vector<JSONValue>, std::map<std::string, JSONValue> >;
There are several possible workarounds. The most robust and correct is to continue using the C++11 Boost library boost::variant, which specifically supports recursive variant types via the marker type boost::recursive_variant_:
using JSONValue = boost::variant< std::nullptr_t, bool, double, std::string, std::vector<boost::recursive_variant_>, std::map<std::string, ...
Read now
Unlock full access