小编War*_*arp的帖子

C++17 template argument deduction mystery

In C++17 you can do this:

#include <iostream>
#include <algorithm>
#include <functional>

int main()
{
    double values[5] = { 1.1, 2.2, 3.3, 4.4, 5.5 };

    // Notice this:
    std::sort(values, values+5, std::greater());

    for(double v: values) std::cout << v << " ";
    std::cout << "\n";
}
Run Code Online (Sandbox Code Playgroud)

You don't actually need to specify the template parameter of std::greater. It will be automatically deduced as double. That's really nice.

But wait... How?!?

There's nothing telling std::greater that the template parameter should be …

c++ templates c++17

5
推荐指数
1
解决办法
88
查看次数

标签 统计

c++ ×1

c++17 ×1

templates ×1