xref: /third_party/json/docs/examples/std_swap.cpp
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/json/docs/examples/
1c5f01b2fSopenharmony_ci#include <iostream>
2c5f01b2fSopenharmony_ci#include <iomanip>
3c5f01b2fSopenharmony_ci#include <nlohmann/json.hpp>
4c5f01b2fSopenharmony_ci
5c5f01b2fSopenharmony_ciusing json = nlohmann::json;
6c5f01b2fSopenharmony_ci
7c5f01b2fSopenharmony_ciint main()
8c5f01b2fSopenharmony_ci{
9c5f01b2fSopenharmony_ci    // create JSON values
10c5f01b2fSopenharmony_ci    json j1 = {{"one", 1}, {"two", 2}};
11c5f01b2fSopenharmony_ci    json j2 = {1, 2, 4, 8, 16};
12c5f01b2fSopenharmony_ci
13c5f01b2fSopenharmony_ci    std::cout << "j1 = " << j1 << " | j2 = " << j2 << '\n';
14c5f01b2fSopenharmony_ci
15c5f01b2fSopenharmony_ci    // swap values
16c5f01b2fSopenharmony_ci    std::swap(j1, j2);
17c5f01b2fSopenharmony_ci
18c5f01b2fSopenharmony_ci    std::cout << "j1 = " << j1 << " | j2 = " << j2 << std::endl;
19c5f01b2fSopenharmony_ci}
20

Indexes created Thu Nov 07 10:32:03 CST 2024