代码之家  ›  专栏  ›  技术社区  ›  DarthRubik

获取boost::hana::partial::operator()的地址

  •  2
  • DarthRubik  · 技术社区  · 6 年前

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

    我想省去“x”值,稍后再调用它,所以我要:

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

    现在,因为我想对这个做一些类型擦除,我想取 operator()

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

    克朗抱怨说 other 对象的函数不足以满足以下要求: godbolt

    看来 partial void ?)……为什么这不起作用?

    1 回复  |  直到 6 年前
        1
  •  3
  •   Yakk - Adam Nevraumont    6 年前

    它(运算符())具有 & const& && etc重载;成员函数指针不符合 *this 按常量或r/l值。所以不匹配。

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

    这里有一个[MCVE]:

    struct foo {
        void bar()&{}
    };
    
    int main(){
        auto p = &foo::bar;
        void(foo::*p2)() = p; // lacks &
    }
    
    推荐文章