简单地说,下面的断言会触发吗?
template<typename T>
auto destructor()
{
return +[](void* p){
((T*)p)->~T();
};
}
assert(destructor<int>() != destructor<char>());
标准似乎只说 lambda converted function pointer does the same thing as the lambda itself ,然后您会意识到普通的析构类型都具有无操作析构函数,因此是相同的。
最佳答案
The value returned by this conversion function is the address of a function F that, when invoked, has the same effect as invoking the closure type's function call operator.
指向的函数是根据其行为指定的,而不是根据其身份指定的。因此未指定此断言是否会触发。
关于c++ - Lambda 转换函数指针比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48485229/