c++ template for rapidjson::Value
c++ template for rapidjson::Value
我试图创建一个模板来实现将数据设置到数组的功能。我把它做成这样:
template <class T1>
void SetArray(rapidjson::Document &JsonObj, std::string ArrayName, T1 value)
{
if (!JsonObj.IsObject())
JsonObj.SetObject();
rapidjson::Document::AllocatorType& alloc = JsonObj.GetAllocator();
rapidjson::Value KeyPart;
KeyPart.SetString(ArrayName.c_str(), alloc);
rapidjson::Value ValuePart;
ValuePart.SetString(value.c_str(), alloc);
}
我找不到如何通过T1来改变值类型(std::string,int,bool等(请帮忙,谢谢!
rapidjson::Value
构造函数已经为各种类型加载了重载,所以您应该只执行
rapidjson::Value ValuePart{value};
并让编译器计算出来。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 为什么static_assert错误:即使我传递常量"expression must have a constant value"?
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 为什么我会" void value not ignored as it ought to be"?
- 方法错误"not all control paths return a value"和方法不返回值
- C++ 尝试在不存在的构造函数中引用已删除的函数(使用 rapidJson)
- C++/SDL "initial value of reference to a non-const must be an lvalue"
- 如何在 c++ 中理解这样的代码 [request->headers().Method()->value().getStringView())]
- std::<key-value>不同类型的对向量
- c++ visual studio 64bit | save registers value
- 初始化数组、"memset"或" {//value} "的最佳方法是什么?
- 如何解决类成员函数中的"return a value"错误?
- bsoncxx: document::view vs document::value
- .value( "key" , default) 不适用于空的 json 对象吗?
- 如何在C++中设置演员的"Render Custom Depth Pass"和"Depth Stencil Value"?
- Qt 错误:QSqlQuery::value:尝试从表中检索统计信息时未定位在有效记录上 (QComboBox)
- 为什么 rapidjson 无法获取此整数值
- 马洛克会在 C++17 年返回"invalid pointer value"吗?
- Rapidjson 遍历并获取复杂 JSON 对象成员的值
- c++ rapidjson return value