草庐IT

call_traits

全部标签

C++ : has_trivial_X type traits

boost库,似乎是即将推出的C++0x标准,定义了各种类型特征模板,以区分具有平凡构造函数、复制构造函数、赋值或析构函数的对象与不具有平凡构造函数的对象。其最重要的用途之一是优化某些类型的算法,例如通过使用memcpy。但是,我不明白所有各种has_trivial_X模板之间真正的实际区别。C++标准只定义了我们在这里关注的两大类类型:POD和非POD。如果一个类型具有已定义的构造函数、复制构造函数、赋值运算符或析构函数,则该类型是非POD。换句话说,任何不是内置类型或内置类型的C结构的东西都不是POD。那么区分has_trivial_assign和has_trivial_const

c++ - 为什么无序关联容器在 C++0x 中不使用 allocator_traits<T>

为什么C++0x无序关联容器不使用allocator_traits来定义它们的成员类型pointer和const_pointer?例如,顺序关联容器和有序关联容器使用以下定义:typedeftypenameallocator_traits::pointerpointer;typedeftypenameallocator_traits::const_pointerconst_pointer;而无序关联容器使用这个:typedeftypenameAllocator::pointerpointer;typedeftypenameAllocator::const_pointerconst_po

Solidity—— call、staticcall和delegatecall用法介绍

在一个智能合约中调用另外一个外部智能合约的函数,我们可以通过接口 interface 的方式进行调用。另外,还有一种比较底层的调用方法,就是使用call、staticcall和delegatecall函数。它们是一种低级、底层的调用方式,具有更大的灵活性。我们将分别进行讲解。一、底层调用call1、函数语法(boolsuccess,bytesmemoryresult)=address(contractAddress).call{value:valueToSend}(data);其中的返回值的含义如下:success:指示调用外部函数是否成功。result:调用的外部函数的返回值。其中的参数的含

c++ - "pure virtual method called"实现 boost::thread 包装器接口(interface)时

我有一个小包装器,它集中了与线程相关的内容:classThread{protected:boost::thread*m_thread;virtualvoidwork()=0;voiddo_work(){work();}public:Thread():m_thread(NULL){}virtual~Thread(){catch_up();deletem_thread;}inlinevoidcatch_up(){if(m_thread!=NULL){m_thread->join();}}voidrun(){m_thread=newboost::thread(boost::bind(&Thr

c++ - 从 std::call_once 抛出异常

C++标准对使用抛出异常的函数执行std::call_once(§30.4.4.2/2)作了如下说明:2/Effects:Anexecutionofcall_oncethatdoesnotcallitsfuncisapassiveexecution.Anexecutionofcall_oncethatcallsitsfuncisanactiveexecution.AnactiveexecutionshallcallINVOKE(DECAY_-COPY(std::forward(func)),DECAY_COPY(std::forward(args))...).Ifsuchacallto

c++ - std::string 的 type_traits 段错误

从UsingSFINAEtocheckforglobaloperator收集信息和templates,decltypeandnon-classtypes,我得到了以下代码:http://ideone.com/sEQc87基本上,我将两个问题的代码结合起来,如果它有ostream声明,则调用print函数,否则调用to_string方法。摘自问题1namespacehas_insertion_operator_impl{typedefcharno;typedefcharyes[2];structany_t{templateany_t(Tconst&);};nooperatorstruct

c++ - 如何在 Xcode 中追踪 "libc++abi.dylib: Pure virtual function called!"

我有一个混合使用C++、Objective-C和Swift的多线程OSX应用程序。当我的应用程序关闭时,我在Xcode调试器窗口中看到:libc++abi.dylib:Purevirtualfunctioncalled!我知道这个错误通常是由在C++类构造函数或析构函数中调用虚函数引起的。有没有简单的方法可以找到它的位置?我所说的“简单”是指“不分析每个具有虚函数的类的每个构造函数和析构函数的每一行的调用树”。我没有看到堆栈跟踪。打印此消息时,调试器不会停止程序。从我的应用委托(delegate)的applicationDidTerminate方法记录的消息在此消息之前。我尝试在“所有

c++ - 如何设置 GMock EXPECT_CALL 为模拟函数调用两个不同的函数

如何在“测试套件”中的测试函数中调用模拟函数时调用两个不同的函数?详细信息:模拟函数在测试函数中被调用两次。第一次调用时,它应该调用一个函数(测试套件中的本地函数),第二次调用时,它应该调用另一个函数(测试套件中的另一个本地函数)。那么,如何为上述需求设置EXPECT_Call为“Invoke”呢? 最佳答案 你应该使用WillOnce。像这样的(未经测试):structA{MOCK_METHOD0(foo,void());};classA_Test:public::testing::Test{Aa;voidbar1(){}void

c++ - 使用 float 给出 "call to overloaded function is ambiguous"错误

这个问题在这里已经有了答案:Referencetofunctionisambiguous[duplicate](2个答案)关闭6年前。我正在重载函数add(),但是当我使用float数据类型时它显示错误。但是,当我将其更改为double时,它工作正常。为什么float会导致错误?代码是:#includeusingnamespacestd;classstudents{private:inti;floatf;public:voidadd(intb){i=b;cout错误:Infunction'intmain()':[Error]callofoverloaded'add(double)'is

c++ - 为什么这个 "call"断言看到两个参数而不是一个?

给定thistestprogram:#include#include#includeconststd::string&const_string="bla";std::stringconst&string_const="blabla";static_assert(std::is_same::value,"Uhoh");intmain(){assert(std::is_same::value);}它使用C的断言断言两种类型在编译时和运行时相同。所有Clang、MSVC2015和GCC都报告相同的错误,所以我很确定it'sme:main.cpp:13:49:error:toomanyargu