草庐IT

function_char-length

全部标签

c++ - 为什么 g++ 声明某些 valarray<double> o 有 "no matching function for call cbegin(o)"?

请考虑以下代码:usingcustom_t=std::valarray;custom_to;unsignedacc=std::accumulate(std::cbegin(o),std::cend(o),0);g++-5说Nomatchingfunctionforcalltocbegin(custom_t&)如果我改用std::begin(o)和std::end(o),一切正常。这是编译器错误吗?代码使用VisualStudio2015编译。 最佳答案 这是一个libstdc++错误,我刚刚创建了https://gcc.gnu.or

c++ - 为什么 UuidFromString 函数请求非常量指针指向 unsigned char?

我不知道为什么UuidFromString函数需要非常量指向无符号字符的指针。为什么不用constchar*代替呢?我的想法是不需要修改第一个参数所指出的数据。 最佳答案 UuidFromString专为COM/DCOM而设计。unsignedchar是为了防止需要检查负数char值(默认char是signed,这意味着值的范围是[-128,127]-因为这个字符串应该是ANSI字符,这是避免条件检查的一种廉价方法)。它的姊妹函数(UuidToString)确实需要一个const输入参数。我在文档中看不到关于为什么UuidFromS

c++ - std::function 参数列表和 typedef

我有一个类似这样的typedef:typedefstd::functionMyFunction;在我的代码中某处是这样使用的:MyFunctionfunc=[](intarg1,floatarg2){/*dosometing*/};问题是,每次我更改函数的参数数量(例如,我添加第三个参数chararg3)时,我都被迫在我使用MyFunction的所有代码中更新它(即使这些根本不使用参数。而且我懒得那样做。有没有办法从它的类型中获取std::function的参数列表?(我的意思是)这样函数创建看起来像那样?:MyFunctionfunc=[](MyFunction::args){/*d

c++ - 调用时为 std::function 分配新值

inti=9;struct_variable.f=[i](Tstruct_variable&){do_something_with_capture_variable(i);...struct_variable.f=another_compatible_std_function;//dosomethingelse,butneverusecapturedvariableafterhere...};struct_variable.f(struct_variable);lambda函数被保存为成员struct_variable.f(也是类型std::function),在回调中,struct_

c++ - 为什么可以将 std::bind 分配给参数不匹配的 std::function?

我有如下代码:#include#includeusingnamespacestd;voidF(intx){coutf1=std::bind(F,std::placeholders::_1);f1(100);//Thisworks,willprint100.intx=0;std::functionf2=std::bind(F,x);f2();//Thisworks,willprint0.std::functionf3=std::bind(F,x);f3(200);//BUTWHYTHISWORKS??????Itprints0.return0;}我的编译器信息是:AppleLLVM版本6

c++ - 错误 C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...) noexcept(<expr>)'

下面是一个给出编译时错误的程序。这主要与D类中的Boo函数有关。我最终尝试使用多个线程来调用solve方法,但目前这对我来说似乎不太有效,无法做到这一点。错误是:1>d:\dummy\project1\trash.cpp(37):warningC4101:'d':unreferencedlocalvariable1>c:\programfiles(x86)\microsoftvisualstudio\2017\community1\vc\tools\msvc\14.11.25503\include\thr\xthread(240):errorC2672:'std::invoke':no

c++ - const char[] 默认函数参数

我定义了这样一个类型:typedefcharsType[256];和一个带有默认参数的函数:voidfoo(constsTypeparam=NULL);MinGW(g++4.8.0)编译它没有错误。相反,VisualStudio2015(Tools14.0)给出了以下错误:errorC2040:'sType':'int'differsinlevelsofindirectionfrom'char[256]'我试图将NULL转换为constchar[],但这会导致:errorC2440:'typecast':cannotconvertfrom'int'to'constchar[]'有什么提

c++ - 如何从移动捕获 lambda 表达式创建 std::function?

我正在尝试创建一个std::function来自移动捕获lambda表达式。请注意,我可以毫无问题地创建移动捕获lambda表达式;仅当我尝试将其包装在std::function中时我得到一个错误。例如:autopi=std::make_unique(0);//noproblemshere!autofoo=[q=std::move(pi)]{*q=5;std::coutbar=foo;std::functionbar{foo};std::functionbar{std::move(foo)};std::functionbar=std::move(foo);std::functionba

c++ - 将 python 列表包装为 unsigned char*

编辑:大家好!!我目前正在尝试从Python访问C++函数,当我尝试将Python列表作为参数传递给函数时遇到了问题。这是我试图访问的C++函数定义(用于向PC/SC阅读器发送命令):SRpdu*SendAPDU(unsignedintuiAPDU,//CommandunsignedintucLE,//DataexpectedforresponseunsignedintucLC,//Sizeofdatabufferunsignedchar*pucDataBuf=0);//databuffer我的目标是像下面的示例一样从python调用此函数。目标是将列表[1,2,3]转换为unsign

c++ - 使用 char 参数从 <cctype> 调用函数是否安全?

C编程语言表示来自的函数遵循一个共同的要求:ISOC99,7.4p1:Inallcasestheargumentisanint,thevalueofwhichshallberepresentableasanunsignedcharorshallequalthevalueofthemacroEOF.Iftheargumenthasanyothervalue,thebehaviorisundefined.这意味着下面的代码是不安全的:intupper(constchar*s,size_tindex){returntoupper(s[index]);}如果此代码在char的实现上执行与sig