struct map_location
{
  int x,y;
};

template<typename T>
inline bool is_odd(T num) {
  int n = static_cast< int >(num);
  return static_cast< unsigned int >(n >= 0 ? n : -n) & 1;
}

template<typename T>
inline bool is_even(T num) { return !is_odd(num); }

void get_adjacent_tiles(const map_location& a, map_location* res)
{
  static const int shift_x[] = {0, 1, 1, 0, -1, -1};
  static const int shift_y[2][6] = {{-1, 0, 1, 1, 1, 0}, // If a.x odd.
                                    {-1, -1, 0, 1, 0, -1}}; // If a.x even.

  bool parity = is_even(a.x);
  for(int i=0; i < 6; ++i, ++res)
  {
    res->x = a.x + shift_x[i];
    res->y = a.y + shift_y[parity][i];
  }
}

void get_adjacent_tiles2(const map_location& a, map_location* res)
{
  res->x = a.x;
  res->y = a.y-1;
  ++res;
  res->x = a.x+1;
  res->y = a.y - (is_even(a.x) ? 1:0);
  ++res;
  res->x = a.x+1;
  res->y = a.y + (is_odd(a.x) ? 1:0);
  ++res;
  res->x = a.x;
  res->y = a.y+1;
  ++res;
  res->x = a.x-1;
  res->y = a.y + (is_odd(a.x) ? 1:0);
  ++res;
  res->x = a.x-1;
  res->y = a.y - (is_even(a.x) ? 1:0);
}

void get_adjacent_tiles3(const map_location& a, map_location* res)
{
  bool parity = is_even(a.x);
  res->x = a.x;
  res->y = a.y-1;
  ++res;
  res->x = a.x+1;
  res->y = a.y - parity;
  ++res;
  res->x = a.x+1;
  res->y = a.y + !parity;
  ++res;
  res->x = a.x;
  res->y = a.y+1;
  ++res;
  res->x = a.x-1;
  res->y = a.y + !parity;
  ++res;
  res->x = a.x-1;
  res->y = a.y - parity;
}


int main()
{
  map_location res[6];
  map_location test;
  for(test.x = 0, test.y = 0; test.x < 100000000; ++test.x, ++test.y)
    get_adjacent_tiles(test, res); 
}
