diff --git a/src/layer/topk.cpp b/src/layer/topk.cpp index 6392b9420214..481794dfc35f 100644 --- a/src/layer/topk.cpp +++ b/src/layer/topk.cpp @@ -49,36 +49,41 @@ int TopK::forward(const Mat& bottom_blob, Mat& top_blob, const Option& opt) cons vec.push_back(std::make_pair(ptr[i], i)); } - if (largest == 1) + // [](const std::pair& a, const std::pair& b) {return a.first > b.first;}); // fix Lambda with lower version of C++ + struct CompareGreater { - std::partial_sort(vec.begin(), vec.begin() + k_, vec.end(), - [](const std::pair& a, const std::pair& b) { + bool operator()(const std::pair& a, const std::pair& b) const + { return a.first > b.first; - }); + } + }; + + struct CompareLess + { + bool operator()(const std::pair& a, const std::pair& b) const + { + return a.first < b.first; + } + }; + + if (largest == 1) + { + std::partial_sort(vec.begin(), vec.begin() + k_, vec.end(), CompareGreater()); } else { - std::partial_sort(vec.begin(), vec.begin() + k_, vec.end(), - [](const std::pair& a, const std::pair& b) { - return a.first < b.first; - }); + std::partial_sort(vec.begin(), vec.begin() + k_, vec.end(), CompareLess()); } if (sorted) { if (largest == 1) { - std::sort(vec.begin(), vec.begin() + k_, - [](const std::pair& a, const std::pair& b) { - return a.first > b.first; - }); + std::sort(vec.begin(), vec.begin() + k_, CompareGreater()); } else { - std::sort(vec.begin(), vec.begin() + k_, - [](const std::pair& a, const std::pair& b) { - return a.first < b.first; - }); + std::sort(vec.begin(), vec.begin() + k_, CompareLess()); } }