接受boost :: hana :: partial :: operator()的地址

时间:2018-08-11 14:01:01

标签: c++ c++14 function-pointers boost-hana

假设我有一个做某事的lambda:

auto thing = [](int x){ /* Stuff */ };

我要保存“ x”值,以后再调用它,所以我这样做:

auto other = boost::hana::partial(thing, 42);

现在,因为我想对此进行某种类型的擦除,所以我想使用operator() .....的地址,所以我尝试这样做:

using type = decltype(other);
void (type::*ptr)(void) = &type::operator();

Clang抱怨other对象的功能不足,无法满足要求:godbolt

看来partial类型正在返回引用(到void?)……为什么这不起作用?

1 个答案:

答案 0 :(得分:3)

它(operator())具有& const& &&等重载;您的成员函数指针不能通过const或r / l value-ness限定*this。因此不匹配。

在无法编译的行的&之前添加const&&&const&&=,它将编译。

这是[MCVE]:

struct foo {
    void bar()&{}
};

int main(){
    auto p = &foo::bar;
    void(foo::*p2)() = p; // lacks &
}