在json/parse.hpp中实现对json格式的字符串解析为一个json对象
#include <json/parse.hpp>
using namespace ayr;
int main()
{
Atring json_str = R"({"array": [1, 2, "3", 4, 5.6, ["a", "b", "c"], {"d": 1, "e": 2, "f": 3}]})";
json::Json json_obj = ayr::json::parse(json_str);
for (auto& item : json_obj["array"as].transform<json::JsonType::JsonArray>())
print(item);
return 0;
}
对于拷贝昂贵的类型,DynArray远快于vector
#include <vector>
#include <string>
#include <law/Array.hpp>
#include <law/DynArray.hpp>
#include <law/timer.hpp>
ayr::DynArray<std::string> das;
std::vector<std::string> vs;
constexpr int N = 100000;
void test_das()
{
for (int i = 0; i < N; ++i)
{
das.append("hello");
}
}
void test_vs()
{
for (int i = 0; i < N; ++i)
{
vs.push_back("hello");
}
}
int main()
{
auto tm = ayr::Timer();
tm(test_das);
tm(test_vs);
return 0;
}
/*
输出:
Time elapsed: 63251 microseconds
Time elapsed: 169696 microseconds
*/