#include <vector>
#include <algorithm>
namespace cv
{
struct Rect
{
float x1, y1, x2, y2;
};
}; // 비스무리하게 만들어주자~
struct CUSTOM
{
cv::Rect rect;
int index;
};
#include <iostream>
using namespace std;
int main()
{
std::vector< CUSTOM > rect_list =
{
{ { 1, 4, 0, 0 }, 5 },
{ { 2, 3, 0, 0 }, 4 },
{ { 3, 2, 0, 0 }, 3 },
{ { 4, 1, 0, 0 }, 2 },
{ { 5, 0, 0, 0 }, 1 },
}; // 있다 쳐. 만들기 귀찮.
std::sort( rect_list.begin(), rect_list.end(),
[]( CUSTOM& a, CUSTOM& b ) // 구조체가 8바이트 보다 크니까 스택에 복사하느니 걍 참조로 받아버리는게 싸겠쥬?
{
return a.rect.y1 != b.rect.y1 ? a.rect.y1 < b.rect.y1 :
a.rect.x1 < b.rect.x1;
}
);
for( auto r : rect_list )
cout << r.rect.x1 << ", " << r.rect.y1 << " : " << r.index << endl;
return 0;
}
ㄱㅅㄱㅅ