.


:




:

































 

 

 

 


std::map




 

std::map - (Balanced BST). std::map - (red-black trees), 2 .

 

: < (). . . , , , std::string - .

 

, , <, . :

 

struct ChessCoordinate

{

//

const short m_xPosition, m_yPosition;

 

//

ChessCoordinate (short _xPosition, short _yPosition)

: m_xPosition(_xPosition), m_yPosition(_yPosition)

{

// : X 1 8

if (m_xPosition < 1 || m_xPosition > 8)

throw std::logic_error(X coordinate out of range [1:8]);

 

// : Y 1 8

if (m_yPosition < 1 || m_yPosition > 8)

throw std::logic_error(Y coordinate out of range [1:8]);

}

 

// - std::map

Bool operator< (ChessCoordinate c) const

{

if (m_xPosition < c.m_xPosition)

return true;

 

else if (m_xPosition == c.m_xPosition)

return m_yPosition < c.m_yPosition;

 

Else

return true;

}

};

 

<, std::map:

 

class Figure;

std::map< ChessCoordinate, Figure * > chessDesk;

// ^
// <

 

, - <. , , .

 

< , . < .. X- , - Y-, - .

 

, std::map , ( comparator). - , , , , . :

 

// : X Y

struct ChessCoordinateComparatorXY

{

//

Booloperator () (ChessCoordinate _c1, ChessCoordinate _c2) const

{

if (_c1.m_xPosition < _c2.m_xPosition)

return true;

 

else if (_c1.m_xPosition == _c2.m_xPosition)

return _c1.m_yPosition < _c2.m_yPosition;

 

Else

return true;

}

};

 

// : Y X

struct ChessCoordinateComparatorYX

{

//





:


: 2017-01-21; !; : 805 |


:

:

.
==> ...

1721 - | 1508 -


© 2015-2024 lektsii.org - -

: 0.007 .