mirror of
https://github.com/nlohmann/json.git
synced 2024-08-21 20:42:29 +02:00
* 👥 update contributor and sponsor list * 🚧 document BJData format * 🚧 document BJData format * 📝 clarified documentation of [json.exception.parse_error.112] * ✏️ adjust titles * 📝 add more examples * 🚨 adjust warnings for index.md files * 📝 add more examples * 🔥 remove example for deprecated code * 📝 add missing enum entry * 📝 overwork table for binary formats * ✅ add test to create table for binary formats * 📝 fix wording in example * 📝 add more examples * Update iterators.md (#3481) * ✨ add check for overloads to linter #3455 * 👥 update contributor list * 📝 add more examples * 📝 fix documentation * 📝 add more examples * 🎨 fix indentation * 🔥 remove example for destructor * 📝 overwork documentation * Updated BJData documentation, #3464 (#3493) * update bjdata.md for #3464 * Minor edit * Fix URL typo * Add info on demoting ND array to a 1-D optimized array when singleton dimension Co-authored-by: Chaoqi Zhang <prncoprs@163.com> Co-authored-by: Qianqian Fang <fangqq@gmail.com>
23 lines
712 B
C++
23 lines
712 B
C++
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
// define a byte container based on std::vector
|
|
using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
|
|
|
|
int main()
|
|
{
|
|
std::vector<std::uint8_t> bytes = {{0xca, 0xfe, 0xba, 0xbe}};
|
|
|
|
// create container
|
|
auto c1 = byte_container_with_subtype(bytes);
|
|
|
|
// create container with subtype
|
|
auto c2 = byte_container_with_subtype(bytes, 42);
|
|
|
|
std::cout << "c1.subtype() = " << c1.subtype()
|
|
<< "\nc2.subtype() = " << c2.subtype() << std::endl;
|
|
|
|
// in case no subtype is set, return special value
|
|
assert(c1.subtype() == static_cast<byte_container_with_subtype::subtype_type>(-1));
|
|
}
|