/*!
* \file operators.h
* \brief Template meta-programming integral constant arithmetic
*
* Copyright (C) 2018 Christos Choutouridis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#ifndef __utl_meta_arithmetic_h__
#define __utl_meta_arithmetic_h__
#include
#include
/*!
* \ingroup meta
* \defgroup integral operators
* Type arithmetic and operators
*/
//! @{
namespace utl {
namespace meta {
/*!
* Math operations
* requires IntegralConstant(_Tp)
*/
//! @{
//! Negation
template
using negate = integral_constant;
//! Addition
template
using add = integral_constant<
decltype(_Tp1() + _Tp2()),
_Tp1() + _Tp2()
>;
//! Multiplication
template
using mult = integral_constant<
decltype(_Tp2() * _Tp2()),
_Tp1() * _Tp2()
>;
//! Division
template
using divide = integral_constant<
decltype(_Tp2() / _Tp2()),
_Tp1() / _Tp2()
>;
//! Modulo
template
using modulo = integral_constant<
decltype(_Tp1() % _Tp2()),
_Tp1() % _Tp2()
>;
//! Substruction
template
using sub = add<_Tp1, negate<_Tp2>>;
//! Increase
template
using inc = add<_Tp, int_<1>>;
//! decrease
template
using dec = add<_Tp, int_<-1>>;
//! @}
/*!
* Comparison operations
* requires IntegralConstant(_Tp)
*/
//! @{
//! \return a true-valued Integral Constant if _Tp1 and _Tp2 are equal.
template using comp_eq = bool_<_Tp1() == _Tp2()>;
//! \return a true-valued Integral Constant if _Tp1 is less than _Tp2.
template using comp_lt = bool_<(_Tp1() < _Tp2())>;
//! Not equal
template using comp_ne = not_>;
//! Greater than
template using comp_gt = comp_lt <_Tp2, _Tp1>;
//! Less or equal
template using comp_le = not_>;
//! Greater or equal
template using comp_ge = not_>;
//! @}
/*!
* Bitwise operations
* requires IntegralConstant(_Tp)
*/
//! @{
//! \return bitwise not (~) operation of its argument.
template using bitnot_ = integral_c;
//! \return bitwise and (&) operation of its arguments
template
using bitand_ = integral_c;
//! \return bitwise or (|) operation of its arguments.
template
using bitor_ = integral_c;
//! \return bitwise xor (^) operation of its arguments.
template
using bitxor_ = integral_c;
//! \return the result of bitwise shift left (<<) operation on _Tp.
template
using shift_left = integral_c;
//! \return the result of bitwise shift right (>>) operation on _Tp.
template
using shift_right = integral_c> shift())>;
//! @}
}}
//!@}
#endif /* __utl_meta_integral_h__ */