[英]c++ use tuple as parameter pack in template
我正在使用boost::callable_traits::args_t
從方法中獲取參數類型的std :: tuple。 可以使用該元組作為參數包嗎?
void doJob(int i) {
std::cout << i << std::endl;
}
template<auto F>
void magic(boost::callable_traits::args_t<F> ...args) { // here is the magic
F(args...)
}
magic<doJob>(1);
這是我要實現的東西。 我想在不使用可變參數模板的情況下做到這一點。
如果可以使用C ++ 17,則可以使用std::apply
調用該函數。 std::apply
接受一個callable和一個tuple,並以未打包的tuple作為函數參數調用callable。 那會讓magic
看起來像
template<auto F>
void magic(boost::callable_traits::args_t<F> args) { // here is the magic
std::apply(F, args);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.