byte_container_with_subtype__subtype.cpp 712 B

12345678910111213141516171819202122
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. // define a byte container based on std::vector
  4. using byte_container_with_subtype = nlohmann::byte_container_with_subtype<std::vector<std::uint8_t>>;
  5. int main()
  6. {
  7. std::vector<std::uint8_t> bytes = {{0xca, 0xfe, 0xba, 0xbe}};
  8. // create container
  9. auto c1 = byte_container_with_subtype(bytes);
  10. // create container with subtype
  11. auto c2 = byte_container_with_subtype(bytes, 42);
  12. std::cout << "c1.subtype() = " << c1.subtype()
  13. << "\nc2.subtype() = " << c2.subtype() << std::endl;
  14. // in case no subtype is set, return special value
  15. assert(c1.subtype() == static_cast<byte_container_with_subtype::subtype_type>(-1));
  16. }