How to map a bool to a 3d point struct with std::map?

后端 未结 6 790
情话喂你
情话喂你 2020-12-10 06:21

How do I use the following struct:

struct point 
{
    int x;
    int y;
    int z;
};

as a key for std::map

6条回答
  •  一生所求
    2020-12-10 07:00

    Just a guess guys,

    bool operator<(const point& other) const
    {
      return( memcmp( (void*) this, (void*) &other, sizeof(point)) < 0);
    }
    

    Of course, the order is kind of weird since x,y and z are signed values, but this should be suitable to order into a std::map, isn't it ?

提交回复
热议问题