继承模板化转换运算符

Vin*_*ent 10 c++ inheritance conversion-operator template-meta-programming c++20

考虑以下代码:

template <class R, class... Args>
using function_type = R(*)(Args...);

struct base {
    template <class R, class... Args>
    constexpr operator function_type<R, Args...>() const noexcept {
        return nullptr;
    }
};

struct derived: private base {
    template <class R, class... Args>
    using base::operator function_type<R, Args...>; // ERROR
};
Run Code Online (Sandbox Code Playgroud)

C++20 中是否有替代方法来继承和公开模板化转换函数?

Oli*_*liv 3

GCC support this: [demo]

template <class R, class... Args>
using function_type = R(*)(Args...);

struct base {
    template <class R, class... Args>
    constexpr operator function_type<R, Args...>() const noexcept {
        return nullptr;
    }
};

struct derived: private base {
  
    using base::operator function_type<auto, auto...>; // No error!
};


int main (){
  derived d;
  static_cast <int(*)(int)>(d);
}
Run Code Online (Sandbox Code Playgroud)

But I think this is an extension to the language that may come from the concept-TS.