How to use lambda auto parameters in C++11

前端 未结 5 751
野的像风
野的像风 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 11:02

    I know there is an accepted answer, but you can also use decltype in C++11 for this, it looks a bit messy...

    stable_sort(X.rbegin(), X.rend(), [](decltype(*X.cbegin()) lhs, decltype(lhs) rhs) { return lhs.first < rhs.first; });
    

    Use cbegin() here as you get the const correct value_type of the container.

提交回复
热议问题