草庐IT

is_function

全部标签

c++ - std::function:参数的严格编译时验证

我想实现一个类,它包含两个带有预定义函数签名的回调。该类具有模板化构造函数,它使用std::bind来创建std::function成员。我预计编译器(g++4.6)会提示如果将签名错误的函数传递给ctor。但是,编译器接受以下内容:callbackc1(i,&test::func_a,&test::func_a);我能理解它为什么这样做。我试图为static_assert构造一个适当的条件,但没有成功。如何通过编译时错误来避免这种情况?#includeusingnamespacestd::placeholders;classcallback{public:typedefstd::fu

读书笔记【头先Python】4. List of Files: Functions, Modules & Files

HowtocreateafunctioninPythonLeaveyour swimclub.py codeopeninVSCode(ifyoulike),thenopenanothernewnotebook,andcallit Files.ipynb.YoualreadyknowhowPython’s import statementworkswiththePSL.Itturnsout import canalsoimportyourcustommodules.And,guesswhat?The swimclub.py fileisaPythonmodule,soyoucanuse impo

C++ 11 绑定(bind) std::function 与存储元组和解包

首先,我对C++11还是比较陌生,所以如果我遗漏了什么,请原谅我的疏忽。所以我想做的基本上是让调用者传入一个函数和该函数的任意参数,将其存储起来,然后稍后异步调用它。似乎有2个主要选项:使用std::bind将std::function绑定(bind)到它的参数(使用可变参数模板获得),然后稍后调用它将参数包转换为一个元组,存储它和std::function,然后再次将元组解压为多个参数并使用它调用函数问题是,一种方法比另一种更好吗?两者之间有优缺点/性能优势吗?谢谢!编辑:根据要求,这里有一个澄清,第一种情况是更早的绑定(bind),我将args绑定(bind)到函数,只要调用者传递

c++ - 错误 : no instance of overloaded function

我正在尝试使用以下代码在我的数据库(SQLServer2008)中插入一些行:CDB.cpp#include"CDB.h"voidCDB::ajouterAlerte(){SqlConnection^mySQLConnection;SqlDataAdapter^myDataAdapter;DataSet^myDataSet;DataRow^myRow;SqlParameter^myParameter;try{mySQLConnection=gcnewSqlConnection("DataSource=NECTARYS-PC;InitialCatalog=MonitoringN;Inte

c++ - CMake "clang++ is not able compile a simple test program"(软呢帽 20)

所以我尝试安装clang+cmake来编译一个简单的C++程序,但出现以下错误:--TheCcompileridentificationisGNU4.8.3--TheCXXcompileridentificationisClang3.5.0--CheckforworkingCcompiler:/usr/bin/cc--CheckforworkingCcompiler:/usr/bin/cc--works--DetectingCcompilerABIinfo--DetectingCcompilerABIinfo-done--CheckforworkingCXXcompiler:/usr/

c++ - 排序 : Is this performance difference for real or am I doing something wrong?

我需要对很多由8个float组成的小数组进行排序。最初我使用的是std::sort但对其性能不满意,我尝试了由此生成的比较交换算法:http://pages.ripco.net/~jgamble/nw.html测试代码如下:templateboolPredDefault(constT&a,constT&b){returna>b;}templateboolPredDefaultReverse(constT&a,constT&b){returnavoidSort8(T*Data,bool(*pred)(constT&a,constT&b)=PredDefault){#defineCmp_S

c++ - 继承的构造函数和 "explicit is better than implicit"

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭7年前。Improvethisquestion良好编程风格的一个众所周知的原则是:“显式优于隐式”。继承的构造函数不是违背了这个原则吗?(包含基类的所有构造函数的单个using语句不是很明确,对吗?)

c++ - 为什么 std::is_constructible 在直接上下文中停止?

源自this话题。也与此有关topic.我的问题是为什么std::is_constructible在直接上下文中停止?我认为std::is_constructible的用户会期望它能够深入工作并给出准确的答案。有了这个直接的上下文,你可能会让std::is_constructible给你一个绿灯,只是在你实际执行它时得到一个硬编译器错误。这是否违背了std::is_constructible的最初目标和目的。现在,它对我来说基本上看起来没用。我想std::looks_constructible_at_first_sight是当前语义的更好名称:( 最佳答案

C++ 概念 : Can I define a concept that is itself a template?

抱歉,如果问题不太清楚。我不确定表达它的最佳方式(随意编辑!)。我认为一个例子是最清楚的:我试图根据Haskelldefinition定义一个Monad概念.绑定(bind)运算符(>>=)要求A类型的Monad可以绑定(bind)到接受A并返回B类型的Monad。我可以根据value_typetypedef定义A,但是如何在我的概念中定义类型B?templateconceptboolMonad(){returnrequires(Mm,Function>f){//(>>=)::ma->(a->mb)->mb{m>>=f}->M}}在上面的例子中,我用什么来代替Function概念中的_

c++ - 错误 "requested alignment is not an integer constant"

我在解决GCC问题时遇到问题。我在GCC4.8下体验过它,但不是5.1。看起来它被报道了here和/或here.问题如下:templatestructS{staticconstintALIGN=16;__attribute__((aligned(ALIGN)))intx;};intmain(intargc,char*argv[]){Ss1;Ss2;return0;}和:$g++test.cxx-otest.exetest.cxx:9:41:error:requestedalignmentisnotanintegerconstant__attribute__((aligned(ALIGN