c++ - Cplusplus std::set of bidimensional array -
i'm new c++ , need use set
stl
i'm struggling concept.
i have array int my_data[3]
i want create (don't know if possible) set
space 3 ints , key
set
int
stored on first column.
i want make custom sort.
this i've tried no success.
struct sort_set { bool operator() (const int& a, const int& b) const { int* arr1 = (int*) a; int* arr2 = (int*) b; int diff = arr2[1] - arr1[1]; if (diff) { return true; } else if (diff == 0) { int diff2 = arr2[2] - arr1[2]; if (diff2) { return false; } } return arr1[0] < arr2[0]; } }; set<int[3],sort_set> data;
can point me in right direction?
you cannot have arrays elements of containers. they're not assignable nor copyable.
use std::array<int, 3>
if have c++11 avaliable, or define custom class otherwise.
Comments
Post a Comment