c++提取函数指针的模板参数
有没有办法提取/内省模板函数指针以获取其模板参数类型和大小?
更一般地说,C++ 中什么样的 Callables/Invocables 能够通过内省来获取模板参数的类型信息以及技术是什么?
编辑: 我想做的是将可调用对象作为模板参数传递给其他类,并携带该可调用对象所具有的有关其采用的模板参数的所有信息。然后我以一种更编译时和功能友好的方式调用这个可调用函数。
https://godbolt.org/z/q3f98177Y
template<typename T>
T SomeFunc() {return T{};}
constexpr auto some_func_fp = &SomeFunc<int>;
// can we do some introspection to get the types
// and size of the template arguments of some templated function pointers?
Is there a way to extract/introspect on templated function pointer to get its template argument types and size?
More generally speaking, what kind of Callables/Invocables in C++ are able to be introspected to get the type info of template args and what are the techiniques?
Edit:
What I'm trying to do is to pass a callable object to some other class as a template parameter and carrying all the info this callable has regarding what template parameters it takes. Then I invoke this callable in a more compile-time and functional friendly way.
https://godbolt.org/z/q3f98177Y
template<typename T>
T SomeFunc() {return T{};}
constexpr auto some_func_fp = &SomeFunc<int>;
// can we do some introspection to get the types
// and size of the template arguments of some templated function pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般来说,函数的类型(和指针类型)不能与模板参数无关。 (在你的情况下,你可以检测返回类型)
You can't, in general, the function's type (and the pointer type) has nothing to do with the template parameter. (in your case you can detect the return type though)