swap__binary_t.cpp 432 B

1234567891011121314151617181920
  1. #include <iostream>
  2. #include <nlohmann/json.hpp>
  3. using json = nlohmann::json;
  4. int main()
  5. {
  6. // create a binary value
  7. json value = json::binary({1, 2, 3});
  8. // create a binary_t
  9. json::binary_t binary = {{4, 5, 6}};
  10. // swap the object stored in the JSON value
  11. value.swap(binary);
  12. // output the values
  13. std::cout << "value = " << value << '\n';
  14. std::cout << "binary = " << json(binary) << '\n';
  15. }