How to use lambda auto parameters in C++11

前端 未结 5 750
野的像风
野的像风 2020-12-05 10:33

I have a code in C++14. However, when I used it in C++11, it has an error at const auto. How to use it in C++11?

vector &g         


        
5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 10:41

    const auto is not supported in C++11 as a lambda parameter (actually generic lambdas are not supported in C++11).

    To fix:

    using pair_type = std::pair>;
    vector X;
    
    std::stable_sort(X.rbegin(), X.rend(),
                    [](const pair_type&lhs, const pair_type& rhs)
                    { return lhs.first < rhs.first; });
    

提交回复
热议问题