[英]How to make variadic template class method take function pointer as argument with type derived from function template?
[英]how can I make variadic template function with a function pointer as non type argument?
我想要實現的是創建一個類似於以下的寺廟:
template<type R, type T, type S, auto F, class ...Fargs>
R create(T input, Fargs... fargs)
{
S a = F(input, fargs ...);
return some_func(a, input.b);
}
然后我想稱之為
int x = create<int, SomeClass, float, SomeFunc_to_apply>(2, someObj, 8.0f, 3, "whatever", "it", "needs");
您可以稍微簡化一下:
template <auto F, typename T, class ...Fargs>
decltype(auto) create(T input, Fargs... fargs)
{
auto a = F(input, fargs ...);
return some_func(a, input.b);
}
並使用它:
SomeClass someObj;
float SomeFunc_to_apply(SomeClass, float, int, const char*, const char*, const char*);
int x = create<SomeFunc_to_apply>(someObj, 8.0f, 3, "whatever", "it", "needs");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.