草庐IT

query_result

全部标签

c++ - 折叠表达式和空参数包 : what's the expected result?

考虑以下最小示例:#includetemplateconstexprautosum(){return(I+...);}templateconstexprautocheck(){return(B&&...);}intmain(){static_assert(6==sum(),"!");//static_assert(0==sum(),"!");static_assert(check(),"!");static_assert(check(),"!");}注释行无法编译。这同样适用于使用*而不是+。涉及bool值的那个可以代替。Here(工作草案)我还没有找到关于空参数包的提及。在另一边,h

c++ - decltype、result_of 还是 typeof?

我有:classA{public:BtoCPD()const;还有:templateclassEv{public:typedefresult_of(T::toCPD())D;实例化后Ev,编译器说:meta.h:12:错误:'T::toCPD'不是类型decltype和typeof都不起作用。 最佳答案 由于你获得的任何结果都取决于模板参数,所以typedeftypename是必要的。decltype是标准C++11功能。它是一个接受表达式并返回类型的“运算符”。typedeftypenamedecltype(T().toCPD()

c++ - 服务器端警告 : Aggregation query used without partition key

在使用Cassandra的C/C++驱动程序时,我有时会在控制台中看到此类消息:1460937092.140[WARN](src/response.cpp:51:char*cass::Response::decode_warnings(char*,size_t)):Server-sidewarning:Aggregationqueryusedwithoutpartitionkey想知道是否有人知道这意味着什么。我应该在我的代码中寻找什么会产生这个错误,或者它只是服务器端我无法控制的东西? 最佳答案 该警告告诉您,您正在使用没有分区键

C++ 等价于 Rust 的 Result<T, E> 类型?

我喜欢在我的C++代码中使用std::experimental::optional,但问题是value_or要求默认值与可选值的类型相同。当我想要一个包含int或包含错误消息的可选项时,这不会很好。我想我可以使用一个带有bool值的union结构来指示该值是否存在或者它是一个错误,但如果C++有一个Result肯定会很好。像Rust这样的类型。有没有这样的类型?为什么Boost没有实现它?Result确实比Option有用得多,而且Boost的人肯定知道它的存在。也许我会去阅读Rust实现,然后将其复制到C++?例如://Functioneitherreturnsafiledescri

c++ - 无法真正理解构造 tcp::resolver::query 的参数是什么

我正在启动Boost.Asio并尝试使官方网站上给出的示例起作用。这是客户端代码:usingboost::asio::ip::tcp;int_tmain(intargc,_TCHAR*argv[]){try{boost::asio::io_serviceio_service;tcp::resolverresolver(io_service);tcp::resolver::queryquery(argv[1],"daytime");tcp::resolver::iteratorendpoint_iterator=resolver.resolve(query);tcp::resolver:

MongoDB:无法规范化查询:BadValue bad geo query

我在2dsphere上索引了字段loc,但无法对Point类型的GeoJson数据运行geowithin查询。这里是查询:db.test.find({loc:{$geoWithin:{$geometry:{type:"Polygon",coordinates:[[[-74.6862705412253,40.42341005],[-75.0846179,39.9009465],[-74.20570119999999,41.0167639]]]}}}}输出:uncaughtexception:error:{"$err":"Can'tcanonicalizequery:BadValuebad

MongoDB:无法规范化查询:BadValue bad geo query

我在2dsphere上索引了字段loc,但无法对Point类型的GeoJson数据运行geowithin查询。这里是查询:db.test.find({loc:{$geoWithin:{$geometry:{type:"Polygon",coordinates:[[[-74.6862705412253,40.42341005],[-75.0846179,39.9009465],[-74.20570119999999,41.0167639]]]}}}}输出:uncaughtexception:error:{"$err":"Can'tcanonicalizequery:BadValuebad

c++ - std::result_of 简单函数

#include#includedoublef(inti){returni+0.1;}structF{public:doubleoperator()(inti){returni+0.1;}};intmain(int,char**){std::result_of::typex;//ok//std::result_of::typex;//error:templateargument1isinvalidx=0.1;std::cerr请解释原因std::result_of::typex;无效...cppreference说“(std::result_of)在编译类型推导出函数调用表达式的返回类

c++ - result_of 用于具有 cv 限定参数的成员对象

鉴于以下声明:structMyClass{};typedefintMyClass::*Mp;在我尝试过的gcc6.2和Clang编译器上,result_of::type产量int&&.我的问题总结:为什么int&&而不是constint&&或者干脆int?更多背景:标准规定result_of是这样定义的:themembertypedeftypeshallnamethetypedecltype(INVOKE(declval(),declval()...));该标准还以这种方式为指向成员对象的指针定义了INVOKE:—t1.*fwhenN==1andfisapointertodatamem

MongoDB : use $ positional operator for querying

我有一个条目看起来像这样的集合:{"userid":1,"contents":[{"tag":"whatever","value":100},{"tag":"whatever2","value":110}]}我希望能够查询该集合并仅返回数组的一部分:与查询匹配的部分。我正在尝试使用$位置运算符来执行此操作,但到目前为止还没有成功。这更准确地说是我想做的:collection.find({'contents.tag':"whatever"},{'contents.$.value':1})因此,我希望只有与匹配查询的数组中的条目相对应的值,在这种情况下为100。你知道有什么问题吗?我在想也