草庐IT

Function_Score

全部标签

c++ - std::function 中的 const 和 & 被忽略了吗?

为什么这段代码会编译?std::functionf=[](inta){};int和constint&不是不同的类型吗? 最佳答案 它们是不同的,但没关系,因为constint&参数可以传递给int参数,这就是所需要的。 关于c++-std::function中的const和&被忽略了吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/45387506/

c++ - std::function 中的 const 和 & 被忽略了吗?

为什么这段代码会编译?std::functionf=[](inta){};int和constint&不是不同的类型吗? 最佳答案 它们是不同的,但没关系,因为constint&参数可以传递给int参数,这就是所需要的。 关于c++-std::function中的const和&被忽略了吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/45387506/

c++ - 为什么使用 constexpr、__PRETTY_FUNCTION__ 和 char * 的这两段代码会有不同的结果?

我有这段代码,如果你注释掉注释“但这不起作用?!”的行,它编译得很好,但如果你不这样做,编译器会产生错误。至少,gcc8.2generatesanerror.但是,他们看起来和我一模一样。有什么问题?这是法律法规吗?templatestructtest_template{staticintsize(){returnx;}};constexprintce_strlen(charconst*s){inti=0;while(s[i])++i;returni;}intjoe(){constexprintplen=ce_strlen(__PRETTY_FUNCTION__);//Thiswork

c++ - 为什么使用 constexpr、__PRETTY_FUNCTION__ 和 char * 的这两段代码会有不同的结果?

我有这段代码,如果你注释掉注释“但这不起作用?!”的行,它编译得很好,但如果你不这样做,编译器会产生错误。至少,gcc8.2generatesanerror.但是,他们看起来和我一模一样。有什么问题?这是法律法规吗?templatestructtest_template{staticintsize(){returnx;}};constexprintce_strlen(charconst*s){inti=0;while(s[i])++i;returni;}intjoe(){constexprintplen=ce_strlen(__PRETTY_FUNCTION__);//Thiswork

c++ - std::function 构造函数和 nullptr

为什么下面的代码输出“0”?#include#includeintmain(){typedefvoid(*fp_t)();fp_tfp=nullptr;std::functionf=fp;std::cout我已经使用gcc4.7.2和MSVC-11.0对其进行了测试。我认为它应该打印“1”,因为标准中的以下引用:ISO/IEC14882:201120.8.11.2.1函数构造/复制/销毁[func.wrap.func.con]templatefunction(Ff);templatefunction(allocator_arg_t,constA&a,Ff);...8Postcondit

c++ - std::function 构造函数和 nullptr

为什么下面的代码输出“0”?#include#includeintmain(){typedefvoid(*fp_t)();fp_tfp=nullptr;std::functionf=fp;std::cout我已经使用gcc4.7.2和MSVC-11.0对其进行了测试。我认为它应该打印“1”,因为标准中的以下引用:ISO/IEC14882:201120.8.11.2.1函数构造/复制/销毁[func.wrap.func.con]templatefunction(Ff);templatefunction(allocator_arg_t,constA&a,Ff);...8Postcondit

c++ - 为什么 C++11 不能将不可复制的仿函数移动到 std::function?

//------------------------------------------------------------------------------structA{A(){}A(A&&){}A&operator=(A&&){return*this;}voidoperator()(){}private:A(constA&);A&operator=(constA&);intx;};//------------------------------------------------------------------------------intmain(){Aa;std::fu

c++ - 为什么 C++11 不能将不可复制的仿函数移动到 std::function?

//------------------------------------------------------------------------------structA{A(){}A(A&&){}A&operator=(A&&){return*this;}voidoperator()(){}private:A(constA&);A&operator=(constA&);intx;};//------------------------------------------------------------------------------intmain(){Aa;std::fu

c++ - 将不可复制的闭包对象传递给 std::function 参数

这个问题在这里已经有了答案:Howtocreateanstd::functionfromamove-capturinglambdaexpression?(3个回答)关闭2年前。在C++14中,lambda表达式可以通过使用捕获初始化程序从变量中move来捕获变量。但是,这使得生成的闭包对象不可复制。如果我有一个采用std::function参数(我无法更改)的现有函数,我无法传递闭包对象,因为std::function的构造函数要求给定的仿函数是CopyConstructible。#include#includevoiddoit(std::functionf){f();}intmain

c++ - 将不可复制的闭包对象传递给 std::function 参数

这个问题在这里已经有了答案:Howtocreateanstd::functionfromamove-capturinglambdaexpression?(3个回答)关闭2年前。在C++14中,lambda表达式可以通过使用捕获初始化程序从变量中move来捕获变量。但是,这使得生成的闭包对象不可复制。如果我有一个采用std::function参数(我无法更改)的现有函数,我无法传递闭包对象,因为std::function的构造函数要求给定的仿函数是CopyConstructible。#include#includevoiddoit(std::functionf){f();}intmain