相关疑难解决方法(0)

如何提取可变参数函数的一组选定参数并使用它们来调用另一个函数

我有一个可变函数动物园,它带有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,其中包含我要传递给zoofoo参数的索引.

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)

c++ c++11

13
推荐指数
2
解决办法
1843
查看次数

标签 统计

c++ ×1

c++11 ×1