如何从可变参数模板参数中删除元素
How to remove elements from variadic template argument?
>我正在尝试删除可变参数模板参数的第一个元素。代码是这样的:
template<typename ...T>
auto UniversalHook(T... args)
{
//I want to remove the first element of `args` here, how can I do that?
CallToOtherFunction(std::forward<T>(args)...);
}
尝试直接方法怎么样。
template<typename IgnoreMe, typename ...T>
auto UniversalHook(IgnoreMe && iamignored, T && ...args)
{
//I want to remove the first element of `args` here, how can I do that?
return CallToOtherFunction(std::forward<T>(args)...);
}
(还修复了使用转发引用,并添加了明显的return
(
我只是得到了一点帮助,并找到了解决方案:
int main()
{
Function(3,5,7);
return 0;
}
template<typename ...T>
auto CallToAnotherFunction(T&&... args)
{
(cout << ... << args);
}
template<typename ...T>
auto Function(T&&... args) {
/*Return is not needed here*/return [](auto&& /*first*/, auto&&... args_){
return CallToAnotherFunction(std::forward<decltype(args_)>(args_)...);
}(std::forward<T>(args)...);
}
//Output is "57"
相关文章:
- 是否有C++编译器选项允许激进地删除所有函数调用,并将参数传递给具有空体的函数
- 如何在不强制转换每个参数的情况下删除初始值设定项列表中从 int 到 char 的缩小转换?
- std::p ackaged_task 应该删除带有 const 参数的复制 c'tor
- Qt5 - 如何将"QList<T> *"指针作为信号参数传递,并在完成后将其删除?
- 编译器在C++中调用另一个函数时,在参数中查找已删除的构造函数
- 从函数参数包中删除最后一项
- 为什么没有为函数参数删除副本
- 删除 Netbeans 中的标准运行参数
- 文档在哪里说明如果参数不是从末端删除参数,则无法从QT信号插槽连接中删除参数?
- 是否允许删除以修改其参数
- 如何通过对象参数从指针矢量中删除对象和指针
- 简化可变参数模板:删除一些专用项
- 为什么删除默认参数会破坏此 constexpr 计数器?
- 使用自定义参数的过载删除操作员
- 如何查找/删除具有特定参数的结构向量的元素
- 带大小参数和不带大小参数的"运算符删除":当两者都可用时,选择哪一个?
- 如何从可变参数模板参数中删除元素
- 打开模板参数:GCC 是否删除开关
- 递归模板参数删除
- 基于模板参数删除成员