草庐IT

forward_propgation_results

全部标签

c++ - 为什么要为 std::forward_list 拼接整个列表或线性范围?

将范围从一个列表拼接到另一个列表可以在常数时间内完成,但代价是使size()的复杂度呈线性。C++11改变了std::list的情况,要求size()为常数时间。例如,这破坏了gcc的实现,参见[C++0x]std::list::sizecomplexity.除了splice()范围外,还有什么其他原因size()不能成为常量时间在早期,C++03符合std::listimplementations?为什么拼接整个列表或范围是线性的std::forward_list?参见splice_after(),案例(1)和(3)。另见standarddraftN3485中的23.3.4.6for

c++ - 使用 std::forward 而不是 std::move 来初始化对象有什么好处吗?

我有一个函数模板,它采用某种可调用类型的参数,并使用std::bind为原始可调用对象创建一个具有预定义参数值的新可调用对象。我用转发引用参数和std::forward编写了它,如下所示:templateautomake_example_caller(F&&f){returnstd::bind(std::forward(f),123,456,789);}cppreferencedocumentationforstd::bind表示绑定(bind)对象“包含一个由std::decay::type构造的std::forward(f)类型的成员对象”。由于std::bind将函数转发给它的内

c++ - result_of 没有为 mem_fn 定义类型

我有以下代码:#includestructX{intget()const&{return42;}};templatestd::result_of_tApply(Funcfn){Xx;returnfn(x);}intmain(void){Apply([](Xconst&x){returnx.get();});//Apply(std::mem_fn(&X::get));//doesnotcompile}第一次调用Apply编译正常,但如果我取消注释第二次调用,我会得到以下编译错误:main.cpp:16:5:error:nomatchingfunctionforcallto'Apply'A

c++ - std::forward_list 成员可以实现为静态的吗?

std::forward_list提供了insert_after和erase_after成员,它们可能不需要实际访问std::forward_list对象。因此,它们可以作为static成员函数实现,并且可以在没有列表对象的情况下被调用——对于想要从列表中删除自身的对象很有用,这是一种非常常见的用法。编辑:此优化仅适用于std::allocator或用户定义的无状态分配器的forward_list特化。符合标准的实现可以做到这一点吗?§17.6.5.5/3说AcalltoamemberfunctionsignaturedescribedintheC++standardlibrarybe

c++ - 为什么 `const int ci = 2; std::forward<int>(ci);` 不起作用以及如何修复/解决它?

简单的问题,为什么不thefollowing工作(意味着ci的拷贝)?#includeintmain(){constintci=2;std::forward(ci);}prog.cpp:Infunction'intmain()':prog.cpp:6:23:error:nomatchingfunctionforcallto'forward(constint&)'问题在编写一些模板内容时表现出来,我有一个简单的holder类型,如下所示。为了避免不必要的拷贝,我尽可能使用完美转发,但事实证明这似乎是问题的根源。templatestructholder{Tvalue;holder(T&&v

c++ - g++ 6.1 可能的 std::forward 回归 - 错误或预期行为?

g++6.1最近被引入到ArchLinux的测试库中,我的一些使用g++5.3.0成功编译的代码不再编译。我做了一个最小的例子:gcc.godbolt.orglink//Thiscodecompileswithg++5.3.0//Thisdoesnotcompilewithg++6.1#include#include#include#defineFWD(...)::std::forward(__VA_ARGS__)structsinker{templatevoidsink(T&){}};templatevoidcaller(T&v,TF&&f){sinkers;f(s,v);}temp

C++ Forward方法调用以在没有继承的情况下嵌入对象

我想知道是否有可能自动将方法调用转发给嵌入的对象,没有继承。例如:classembed{public:voidembed_method(){return};};classcontainer{public:voidcontainer_method(){return;}private:embedobj;};intmain(){containerobject;object.container_method();//Localmethodcallobject.embed_method();//'Forward'call,obviouslydoesn'twork}当不可能/不推荐从基类继承时,它

c++ - friend 类概念如何不需要前向声明(forward declaration)?

我最近刚刚了解了C++中的friendclass概念(我用google搜索了一下,但是这个answer让我笑了起来,直到我想起了最重要的部分),并且我正在尝试将它合并到我现在正在进行的项目中。最后挑出了简洁的问题,但总的来说,我对工作代码中完全没有前向声明感到困惑。我所有的类(class)都通过(子)文件夹分开,每个类(class)都分为一个单独的.h和.cpp文件,但这应该足以获得一个对依赖的感觉://FE.h-noimplementations-no.cppfileclassFE{private:virtualvoidsomePrivateFunc()=0;//90%virtual

python - redis redis.client rq Queue job.result # => None

我正在尝试使用Redis找出rq队列。我有一个简单的test_job函数,我想在队列中使用它。deftest_job():return"OK"脚本主要取自rq文档:#!/usr/bin/envpythonimportredis.clientfromrqimportQueueimporttimefromhelpersimporttest_jobdefmain():q=Queue(connection=redis.client.Redis('localhost',6379))job=q.enqueue(test_job)printjob.result#=>Nonewhilenotjob.r