如何在C ++中为偶数位置做可变参数模板?

问题描述

我必须编写一个可变参数模板函数,如果每个偶数位置的值都小于下一个位置的参数值,则返回true。 例: f(4,5,7,9,9,2)-> true(4

我尝试过这个:

template<typename T>
T check()
{
    auto even_number = [](T x)
    {  return (x % 2) == 0 ? x : 0; };
}

template <typename T,typename... A>
bool check(T first,A... args)
{
    return first < check(args...) ? true : false;
}


int main()
{
    std::cout << check(4,5,7,9,2,4);
}

,这个程序给了我这些错误: 1.'check':找不到匹配的重载函数 2.'T check(void)':无法推断出T的模板参数->如果第二个模板我添加了“ T check(T first,A ... args)”,则会出现此错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)