Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 提供方法指针和派生类型的对象时std::bind的一致性_C++_C++11_Language Lawyer_Stdbind - Fatal编程技术网

C++ 提供方法指针和派生类型的对象时std::bind的一致性

C++ 提供方法指针和派生类型的对象时std::bind的一致性,c++,c++11,language-lawyer,stdbind,C++,C++11,Language Lawyer,Stdbind,这个问题基本上是我回答的结果。我刚刚意识到标准中的措辞似乎忽略了一些情况。考虑这段代码: #include <iostream> #include <functional> struct foo { void f(int v) { std::cout << v << std::endl; } }; struct bar : foo {}; int main() { bar obj; std::bind(&foo::f, o

这个问题基本上是我回答的结果。我刚刚意识到标准中的措辞似乎忽略了一些情况。考虑这段代码:

#include <iostream>
#include <functional>

struct foo
{
  void f(int v) { std::cout << v << std::endl; }
};

struct bar : foo {};

int main()
{
  bar obj;
  std::bind(&foo::f, obj, 1)();
}
#包括
#包括
结构foo
{

void f(int v){std::coutC++11标准的第20.8.9.1.3段定义了调用
std::bind()
伪函数的效果,如下所示:

返回:具有弱结果类型(20.8.2)的转发呼叫包装器
g
g(u1,u2,…,uM)
的效果应为
INVOKE(fd,std::forward(v1),std::forward(v2),…,std::forward(vN),
结果(类型)

请注意,调用
std::forward
将始终返回引用类型,无论是左值引用还是右值引用。根据第20.2.3/1-2段,实际上:

template constepr T&&forward(typename remove\u reference::type&T)无异常;

template constepr T&&forward(typename remove\u reference::type&&T)noexcept;

返回:
static\u cast(t)

因此,
INVOKE
伪函数(注意:不是
bind()

我相信标准本身从来没有将
INVOKE()
伪函数(这只是一些内部形式主义)用于从
T
派生的类型的对象(而不是对对象的引用)


但是,这并不意味着您不能使用对象调用
std::bind()
或其他函数,这些函数的定义依次是
invoke()
(不是对对象的引用)从
T

派生的类型,这似乎是正确的,谢谢。必须通读20.8.9.1.3/10才能弄清楚V1/V1…VN/VN实际上是什么。这当然不是标准中最简单的部分:)我不确定“T类型的对象”何时案例是需要的,为什么参考案例没有涵盖它。但是,在这个措辞中有一个缺陷,请参见。我应该找出何时/为什么需要它,以及是否需要它作为参考包装