jeudi 30 mai 2019

What is the point/function of auto in this template parameter?

The following code is extracted from the accepted answer in C++ std::priority_queue uses the lambda expression

#include <vector>
#include <queue>

auto main()
    -> int
{
    std::priority_queue< int, std::vector<int>, auto(*)(int,int)->bool > pq{
        []( int a, int b )->bool { return a < b; }
        };
}

What is the benefit or significance of using auto as opposed to:

    std::priority_queue< int, std::vector<int>, bool(*)(int,int)> pq{
        []( int a, int b )->bool { return a < b; }
        };
}

I thought the whole point of auto is, well, automatic type deduction. But in this case, ->bool is used which seems to make automatic type deduction moot here. So why not just use bool? Am I misunderstanding something here?

Aucun commentaire:

Enregistrer un commentaire