从成员指针中提取它指向​​的 class 的类型

Extract from a member pointer the type of class it points to

如何用C++20正确编译,a.k.a计算extract<mem_fun>::type?可能吗?

像传递非成员函数或私有函数这样的错误场景extract<>对我来说不是那么重要。

#include <concepts>

struct x
{
    void f()
    {

    }
};

template<auto mem_fun>
struct extract
{
    // using type= ???
};

int main()
{
    using namespace std;
    static_assert(same_as<typename extract<&x::f>::type, x>);
    return 0;
}

指向成员的指针都具有类型 T C::*,其中 T 可以是某种类型或某种函数类型,甚至是某种“可恶的”函数类型。

所以你只需要专注于那个特定的形状:

template<auto mem_fun>
struct extract;

template <typename T, typename C, T C::* v>
struct extract<v> {
    using type = C;
};