草庐IT

automatic-ref-counting

全部标签

c++ - 如果 count() 是 constexpr 函数,为什么 std::array<int, count()> 不能编译?

这个问题在这里已经有了答案:constexprnotworkingifthefunctionisdeclaredinsideclassscope(3个回答)3年前关闭。为什么下面的C++代码不能用VC2017编译?structFixedMatchResults{staticconstexprstd::size_tcount(){return20;};std::arrayresults;};错误是:errorC2975:'_Size':invalidtemplateargumentfor'std::array',expectedcompile-timeconstantexpression

c++ - std::bind std::shared_ptr 参数不会增加 use_count

以下代码:#include#include#includestructFoo{Foo():m_p(std::make_shared()){}Foo(constFoo&foo){printf("copy\n");}std::shared_ptrm_p;};voidfunc(Foofoo){}intmain(){Foofoo;std::functionf=std::bind(func,foo);printf("usecount:%ld\n",foo.m_p.use_count());f();}得到结果:copycopyusecount:1copy由于复制了Foo,所以我认为m_p的use_

解决error: failed to push some refs to ‘https://github.com...‘问题

问题描述本地修改代码后正准备push到远程仓库,但是遇到了如下问题:error:failedtopushsomerefsto'https://github.com...'hint:Updateswererejectedbecausetheremotecontainsworkthatyoudohint:nothavelocally.Thisisusuallycausedbyanotherrepositorypushinghint:tothesameref.Youmaywanttofirstintegratetheremotechangeshint:(e.g.,'gitpull...')befor

c++ - 带有 C++ 模板的虚假 "use of local variable with automatic storage from containing function"?

以下代码无法在g++7.2.0中编译templateclassRequest{intcontent=0;public:friendvoidsetContent(inti,void*voidptr){Request*ptr=(Request*)voidptr;ptr->content=i;}intgetContent(){returncontent;}};intmain(){Requestreq;setContent(4,&req);returnreq.getContent();}有错误test.cpp:Ininstantiationof‘voidsetContent(int,void*

c++ - std::thread constructor 传递指针和传递ref有区别吗?

创建调用成员函数的线程时,传递当前类的指针和传递引用有区别吗?从下面的示例中,方法1的行为是否与方法2相同?有什么区别吗?classMyClass{public:MyClass(){};~MyClass(){};voidmemberFunction1(){//method1std::threadtheThread(&MyClass::memberFunction2,this,argumentToMemberFunction2)//method2std::threadtheThread(&MyClass::memberFunction2,std::ref(*this),argumentT

C ++功能签名接受LVALUE,RVALUE和RVALUE REF

假设我具有以下功能:print_sutff(conststd::stringstuff){std::cout我可以接受:std::stringstd::string&std::string&&对功能代码的外观没有任何影响。但是,可以通过多种方式调用该功能,我想通过这些方式实现以下行为(或尽可能接近它):autopass="astring";print_sutff(pass);在这里,用户不能使用&amp;&amp;我更喜欢&amp;优先考虑lvaue或者:print_sutff("astring");这里是&amp;amp;应调用构造函数。所以我的问题是:有什么方法可以接受lvalue,&am

ActiverEcord Collection Count Count COMINED FIELD订购时给出mysql2 ::错误:“顺序子句”中的未知列

试图拨打ActivereCord::关系集合的算法正常,除非您将其加入如下:users=User.joins(:foos).select(['users.idasid','users.nameasname','sum(b.blah)asblah','max(foos.baz)asbazness']).joins('leftjointabley_thingsbonusers.id=b.user_id').group('users.id')users.count#noproblemusers.order('nameDESC').count#noproblemusers.order('bazness

c++ - STL bitset::count() 方法的性能如何?

我四处搜索,找不到bitset::count()的性能时间规范。有人知道它是什么(O(n)或更好)以及在哪里可以找到它吗?编辑由STL我仅指标准模板库。 最佳答案 我在我的电脑上读取了这个文件(C:\cygwin\lib\gcc\i686-pc-cygwin\3.4.4\include\c++\bitset)。看这些///Returnsthenumberofbitswhichareset.size_tcount()const{returnthis->_M_do_count();}size_t_M_do_count()const{si

c++ - 如果没有 if,std::count_if 会更快吗?

这是gccstd::count_if代码templatetypenameiterator_traits::difference_typecount_if(_InputIterator__first,_InputIterator__last,_Predicate__pred){[snip]typenameiterator_traits::difference_type__n=0;for(;__first!=__last;++__first)if(__pred(*__first))++__n;return__n;}我的问题:使用它会更好(即更快)吗__n+=__pred(*__first)

c++ - 隐式生成的赋值运算符应该是 & ref 限定的吗?

以下代码在gcc4.8.1上编译没有问题:#includestructfoo{};intmain(){foobar;foo()=bar;foo()=std::move(bar);}似乎为foo隐式生成的赋值运算符不是&引用限定的,因此可以在右值上调用。根据标准,这是正确的吗?如果是这样,有什么理由不要求隐式生成的赋值运算符是&ref-qualified?为什么标准不要求生成以下内容?structfoo{foo&operator=(fooconst&)&;foo&operator=(foo&&)&;}; 最佳答案 好吧,有一些合法的用