简体   繁体   English

错误的模板参数数量

[英]wrong number of template arguments

I want to write template Merge Sort. 我想写模板Merge Sort。

    template <class RandomAccessIterator, class Comparator = std::less<>>
void MergeSort(RandomAccessIterator begin, RandomAccessIterator end, Comparator compare) {
    int s = end - begin;
    if (s > 1)
    {
        RandomAccessIterator middle = begin + s / 2 + 1;
        MergeSort(begin, middle, compare);
        MergeSort(middle, end, compare);
        std::inplace_merge(begin, middle, end, compare);
    }
}

And the message I get is: error: wrong number of template arguments (0, should be 1) template >. 我收到的消息是:错误:模板参数的数量错误(0,应该是1)模板>。

I tried to move std::less to function declaration, but also failed. 我试图将std :: less移动到函数声明,但也失败了。 What do I need to do? 我需要做什么?

Since you tagged your question as C++11 , it seem you cannot use diamond operators. 由于您将问题标记为C++11 ,因此您似乎无法使用菱形运算符。

As you can see in the documentation , the form std::less<> is only allowed since C++14 . 正如您在文档中看到的那样,表单std::less<>仅在C++14才被允许。

What you can do here is to use the other form: 你在这里可以做的是使用另一种形式:

std::less<typename std::iterator_traits<RandomAccessIterator>::value_type>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM