/*!
* \file operations.h
* \brief Integral constant operations and logical operations
*
* Copyright (C) 2018-2019 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_operations_h__
#define __utl_meta_operations_h__
#include
#include
/*!
* \ingroup meta
* \defgroup logic
* logic operators and type relations support
*/
//! @{
namespace utl {
namespace meta{
/*!
* Logical relation for types
*/
//! @{
//! Negate the *bool* constant parameter
template
using not_c = bool_;
//! not
template
using not_ = not_c<_Tp::type::value>;
//! OR implementation
//! @{
namespace detail {
template struct _or_;
template<>
struct _or_<> : false_ { };
template
struct _or_<_T1> : _T1 { };
template
struct _or_ <_T1, _T2>
: if_<_T1, _T1, _T2> { };
template
struct _or_<_T1, _T2, _T3, _Tn...>
: if_<_T1, _T1, _or_<_T2, _T3, _Tn...>> { };
}
template
using or_ = eval>;
//! @}
//! AND implementation
//! @{
namespace detail {
template struct _and_;
template<>
struct _and_<>
: true_ { };
template
struct _and_ <_T1>
: _T1 { };
template
struct _and_<_T1, _T2>
: if_<_T1, _T2, _T1> { };
template
struct _and_<_T1, _T2, _T3, _Tn...>
: if_<_T1, _and_<_T2, _T3, _Tn...>, _T1> { };
}
template
using and_ = eval>;
//! @}
//! same
//! @{
template
struct same_ : false_ { };
template
struct same_ <_Tp, _Tp> : true_ { };
//! @}
//! not same
//! @{
template
using not_same_ = not_>>;
//! @}
//! @}
}}
//! @}
/*!
* \ingroup meta
* \defgroup integral operators
* Type arithmetic and operators
*/
//! @{
namespace utl {
namespace meta {
/*!
* Math operations
* requires IntegralConstant(_Tp)
*/
//! @{
//! Negation
template
using negate = integral_;
//! Addition
template
using add = integral_<
decltype(_Tp1() + _Tp2()),
_Tp1() + _Tp2()
>;
//! Multiplication
template
using mult = integral_<
decltype(_Tp2() * _Tp2()),
_Tp1() * _Tp2()
>;
//! Division
template
using divide = integral_<
decltype(_Tp2() / _Tp2()),
_Tp1() / _Tp2()
>;
//! Modulo
template
using modulo = integral_<
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_;
//! \return bitwise and (&) operation of its arguments
template
using bitand_ = integral_;
//! \return bitwise or (|) operation of its arguments.
template
using bitor_ = integral_;
//! \return bitwise xor (^) operation of its arguments.
template
using bitxor_ = integral_;
//! \return the result of bitwise shift left (<<) operation on _Tp.
template
using shift_left = integral_;
//! \return the result of bitwise shift right (>>) operation on _Tp.
template
using shift_right = integral_> shift())>;
//! @}
}}
//!@}
#endif /* __utl_meta_operations_h__ */