草庐IT

load-store-functions

全部标签

c++ - 确定 std::function 的返回类型

我正在编写一个模板函数,它接收一个std::function对象(通过使用适当的参数调用std::bind生成)。在这个函数中,我想确定这个函数对象的返回类型。有可能吗?事实上,我希望模板函数返回相同的类型。您能想出一种优雅的、基于标准的方法来实现这一目标吗?类似于:templateT::return_typefunctionObjWrapper(TfunctionObject){//...returnfunctionObject();}谢谢 最佳答案 您可以使用decltype和尾随返回类型来完成:templateautofunc

c++ - 将双变量 std::function 转换为单变量

我有一个获取两个值x和y并返回结果的函数:std::functionmult=[](doublex,doubley){returnx*y;};现在我想得到一个常量y的单变量函数。我写了下面的代码,但它不起作用。std::function(std::function,double)>funcYgivenX=[](std::functionfunc2d,doubleinX){return[&func2d,&inX](doubleinY){returnfunc2d(inX,inY);};};我在这里做错了什么?最好(最有效)的方法是什么? 最佳答案

c++ - std::atomic_store 和 std::atomic_exchange 不交换

根据en.cppreference.com,std::atomic_exchange和std::atomic_store等价于线程安全的std::swap。但这不是我使用g++或clang++得到的行为。Problemliveoncoliru.(见下文)它虽然打印了这个:std::atomic_storea:0x1ed2c300b:0x1ed2c501a:0x1ed2c501b:0x1ed2c501std::atomic_exchangea:0x1ed2c500b:0x1ed2c301a:0x1ed2c301b:0x1ed2c301这是为什么?难道我做错了什么?我是否误读了文档?代码l

c++ - "error: no matching function for call to"

我当时在键盘上,我正在尝试使用C++来提高我的技能。我以前从未使用过模板,所以我尝试研究如何使用它们。下面的代码是结果,不幸的是,它不起作用。我确实尝试寻找问题的解决方案,但由于我没有太多使用模板的经验,所以我无法在我的问题和其他问题之间建立任何联系。所以,我决定寻求帮助。templateclassVector2{public:Ax,y;Vector2(Axp,Ayp){this->x=xp;this->y=yp;}};templateclassrayToCast{public:rayToCast(Bangle,Vector2origin,Vector2point1,Vector2po

c++ - C2556 : overloaded function differs only by return type

我正在阅读EffectiveC++,它告诉我“可以重载仅因常量不同而不同的成员函数”。书中的例子是:classTextBlock{public:constchar&operator[](std::size_tposition)const;char&operator[](std::size_tposition);private:std::stringtext;}我下面的示例使用了一个存储指针。classA{public:A(int*val):val_(val){}int*get_message(){returnval_;}constint*get_message(){returnval_

c++ - 继续获取 "error: use of undeclared identifier ' cout' 和错误 : reference to overloaded function could not be resolved

我正在编写一个使用许多不同函数的排序程序,你们都可以从我的声明。但是,当我尝试编译和运行我的程序时,我不断遇到这些相同的错误它们如下:error:useofundeclaredidentifier'cout';didyoumean'count'?couterror:referencetooverloadedfunctioncouldnotberesolved;didyoumeantocallit?couterror:useofundeclaredidentifier'endl';didyoumean'end'?cout我不太确定为什么会出现这些错误....我想我已经包含了我需要的一切为

c++ - 未命中断点 - "the module did not load at the default load address"

我正在尝试调试CPPUnitTests,断点设置在作为待测试DLL(C++非托管dll)一部分的文件中。我将CPPunit测试程序进程附加到打开项目的visualstudioIDE,处于native模式(也尝试过托管+native),然后运行测试,但断点根本没有命中。断点似乎没问题(全红点)。我在DebugBuild中构建了所有必要的DLL。我去Debug->Windows->Modules检查测试程序进程是否加载了我正在调试的DLL,它确实加载了,并且SYmbol文件也被加载了,但是DLL的名称中有一个感叹号和当我将鼠标悬停在它上面时,它说“模块没有在默认加载地址加载”。我该如何解决

c++ - 为什么 clang++ 报告与 "value stored to ' .. .' during its initialization is never read"的结构化绑定(bind)?

我有以下测试用例:testcase("[room]exits"){auto[center,east,north,south,west]=make_test_rooms();check_eq(center->east(),east);check_eq(center->north(),north);check_eq(center->south(),south);check_eq(center->west(),west+1);}当我编译它时,clang++(clangversion5.0.1(tags/RELEASE_501/final))报告:room.cpp:52:7:note:Valu

c++ - 为什么宏 __STL_FUNCTION_TMPL_PARTIAL_ORDER 应该将模板函数包含在 std_pair.h 中

今天在STL_pair.h中看到如下代码:#ifdef__STL_FUNCTION_TMPL_PARTIAL_ORDERtemplateinlinebooloperator!=(constpair&__x,constpair&__y){return!(__x==__y);}templateinlinebooloperator>(constpair&__x,constpair&__y){return__y我不认为模板函数与偏特化有任何关联的功能模板。我错了吗? 最佳答案 编译器如何处理函数调用在C++中调用函数模板经历了名称查找(标准

C++ 设计 : Overloading/Overriding many many functions, 的清理方式?

我在这里尝试实现的案例是一个基类,它有一个函数(我们称之为modify_command),它实际上可以接受许多不同的类型,因此派生类可以实现它们认为合适的modify_command函数。现在我在基类中有一些类似的东西:classBase{templatevoidmodify_command(Commandcmd){std::cout(cmd);//Callsthetemplatedfunction}virtualvoidmodify_command(SpecificCommandBcmd){modify_command(cmd);//Callsthetemplatedfunction