/*! * \file logical.h * \brief Template meta-programming logic operator and type relations. * * 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_logical_h__ #define __utl_meta_logical_h__ #include #include #include /*! * \ingroup meta * \defgroup logic * logic operator and type relations support header */ //! @{ namespace utl { //! NOT implementation template struct not_ : bool_ { }; //! OR implementation //! @{ template struct or_; template<> struct or_<> : false_ { }; template struct or_<_T1> : _T1 { }; template struct or_ <_T1, _T2> : if_<_T1::value, _T1, _T2>::type { }; template struct or_<_T1, _T2, _T3, _Tn...> : if_<_T1::value, _T1, or_<_T2, _T3, _Tn...>>::type { }; //! @} //! AND implementation //! @{ template struct and_; template<> struct and_<> : true_ { }; template struct and_ <_T1> : _T1 { }; template struct and_<_T1, _T2> : if_<_T1::value, _T2, _T1>::type { }; template struct and_<_T1, _T2, _T3, _Tn...> : if_<_T1::value, and_<_T2, _T3, _Tn...>, _T1>::type { }; //! @} //! same //! @{ template struct same_ : false_ { }; template struct same_ <_Tp, _Tp> : true_ { }; //! @} //! not same //! @{ template struct not_same_ : true_ { }; template struct not_same_ <_Tp, _Tp> : false_ { }; //! @} } #endif /* __utl_meta_logical_h__ */