首页 > 解决方案 > 绑定可变参数函数 C++

问题描述

假设我有这样的功能:

template <typename... T>
void sum(int start, T... next);

我想绑定这个。我该怎么做?


更准确地说,如果函数有固定数量的参数,它看起来像:

void sum(int start, int next); // function signature

// ...

auto binded_sum = std::bind(sum, 0, std::placeholders::_1);

现在我将如何“占位”可变数量的参数?

标签: c++variadic-templates

解决方案


这些方面的东西:

auto binded_sum = [](auto... next) { sum(0, next...); };

推荐阅读