ChessPlusPlus  WIP
cplusplus.com Community Project
chesspp::util::Position< T > Class Template Reference

#include <Position.hpp>

Public Types

using value_type = T
 

Public Member Functions

 Position (T x_=T(), T y_=T()) noexcept
 
 Position (Position const &)=default
 
 Position (Position &&)=default
 
Positionoperator= (Position const &)=default
 
Positionoperator= (Position &&)=default
 
 ~Position ()=default
 
bool isWithin (Position const &topleft, Position const &bottomright) const noexcept
 
Positionmove (typename MakeSigned< T >::type xoff, typename MakeSigned< T >::type yoff) noexcept
 
Positionmove (Direction const &d, signed times=1) noexcept
 

Static Public Member Functions

static Position const & Origin () noexcept
 

Public Attributes

x
 
y
 

Friends

auto operator== (Position const &a, Position const &b) noexcept-> typename std::enable_if< std::is_integral< T >::value, bool >::type
 
bool operator< (Position const &a, Position const &b) noexcept
 

Detailed Description

template<typename T>
class chesspp::util::Position< T >

Represents a two-dimensional point or position.

Template Parameters
Tcoordinate type, must be a scalar type.

Member Typedef Documentation

template<typename T >
using chesspp::util::Position< T >::value_type = T

Constructor & Destructor Documentation

template<typename T >
chesspp::util::Position< T >::Position ( x_ = T(),
y_ = T() 
)
inlinenoexcept

Initializes x and y to the provided values, or from T's default constructor otherwise.

Parameters
x_the x coordinate of this position, or T()
y_the y coordinate of this position, or T()
template<typename T >
chesspp::util::Position< T >::Position ( Position< T > const &  )
default
template<typename T >
chesspp::util::Position< T >::Position ( Position< T > &&  )
default
template<typename T >
chesspp::util::Position< T >::~Position ( )
default

Member Function Documentation

template<typename T >
bool chesspp::util::Position< T >::isWithin ( Position< T > const &  topleft,
Position< T > const &  bottomright 
) const
inlinenoexcept

Checks if this position is within a boundry of top-left and bottom-right positions, including edges.

Parameters
topleftthe lowest coordinate corner
bottomrightthe highest coordinate corner
Returns
whether this position is inclusively within the given boundaries.
template<typename T >
Position& chesspp::util::Position< T >::move ( typename MakeSigned< T >::type  xoff,
typename MakeSigned< T >::type  yoff 
)
inlinenoexcept

Moves this position relative to itself.

Parameters
xoffthe value to add to x, of type signed T
yoffthe value to add to y, of type signed T
Returns
*this
template<typename T >
Position& chesspp::util::Position< T >::move ( Direction const &  d,
signed  times = 1 
)
inlinenoexcept

Move position relative to itself in a direction a given number of times.

Parameters
dthe dirction in which to move.
timesthe number of times to move in direction d.
Returns
*this
template<typename T >
Position& chesspp::util::Position< T >::operator= ( Position< T > const &  )
default
template<typename T >
Position& chesspp::util::Position< T >::operator= ( Position< T > &&  )
default
template<typename T >
static Position const& chesspp::util::Position< T >::Origin ( )
inlinestaticnoexcept

Returns the position at the origin. This position is the result of x and y being initialized by T's default constructor.

Returns
the position at the origin.

Friends And Related Function Documentation

template<typename T >
bool operator< ( Position< T > const &  a,
Position< T > const &  b 
)
friend

Less-than comparison operator, to be used for sorting purposes only.

Parameters
athe left-hand position.
bthe right-hand position.
Returns
true if a comes before b.
template<typename T >
auto operator== ( Position< T > const &  a,
Position< T > const &  b 
) -> typename std::enable_if<std::is_integral<T>::value, bool>::type
friend

Equality comparison operator.

Parameters
athe left-hand position.
bthe right-hand position
Returns
whether a equals b.

Member Data Documentation

template<typename T >
T chesspp::util::Position< T >::x
template<typename T >
T chesspp::util::Position< T >::y

The documentation for this class was generated from the following file: