在C ++ 11模板中,是否有一種方法可以將元組用作(可能是模板)函數的各個參數?示例:假設我具有此功能:void foo(int a, int b) { }而且我有元組auto bar = std::make_tuple(1, 2)。我可以用它以foo(1, 2)模板方式調用嗎?我的意思不是僅僅foo(std::get<0>(bar), std::get<1>(bar))因為我想在不知道args數量的模板中執行此操作。更完整的示例:template<typename Func, typename... Args> void caller(Func func, Args... args) { auto argtuple = std::make_tuple(args...); do_stuff_with_tuple(argtuple); func(insert_magic_here(argtuple)); // <-- this is the hard part }我應該注意,我寧愿不要創建一個適用于一個arg的模板,也不創建另一個適用于兩個arg的模板,等等。
- 2 回答
- 0 關注
- 510 瀏覽
添加回答
舉報
0/150
提交
取消