私はこのコードで動作しているように見えます:
template <typename C>
class class_ {
protected:
std::map<std::string, native_function> methods;
public:
template <typename F, F fn>
class_ &method(const std::string &name) {
methods[name] = method_helper<C, F>::template toNative<fn>();
return *this;
}
};
これにより、次のことが可能になります。
class_<MyClass>()
.method<decltype(&MyClass::numRows), &MyClass::numRows>("numRows");
ただし、エクスポートされたクラスに非メンバー関数をメソッドとして追加できるようにしたいと考えています。method
問題は、通常の関数ポインターを操作するには、別の定義が必要なことです。
template <F, F fn>
class_ &method(const std::string &name) {
methods[name] = function_helper<F>::template toNative<fn>();
return *this;
}
ただし、上記のように、テンプレート パラメーターはまったく同じです。
まったく異なる名前の関数を作成する以外に、関数ポインターとメンバー関数ポインターを区別する便利な方法はありますか? または、実行時にどのコードを実行するかを決定する方法はありますか?