我有一个可变函数动物园,它带有N个参数,其中N在编译时是已知的(它是包含该函数的类的模板参数).
template <int N>
struct B
{
template <typename... Args>
static void zoo(Args... args)
{
static_assert(size of...(args) == N, "");
// do something
}
};
Run Code Online (Sandbox Code Playgroud)
我有另一个可变函数foo,它接受M个参数,其中M> N并且在编译时是已知的(它是包含该函数的类的模板参数).我有一个静态index_array,其中包含我要传递给zoo的foo参数的索引.
从foo的主体我想调用zoo传递foo参数的选定子集.
做这个的最好方式是什么?理想情况下实现完美的内联,即所有内容都只编译成一条没有函数指针间接指令的指令?
template<int...I>
struct indices
{
static constexpr int N = sizeof...(I);
};
template <int M, typename...X>
struct A
{
// here I am simplifying, in reality IS will be built at compile time based on X
typedef indices<0,2,3> …Run Code Online (Sandbox Code Playgroud)