|
- /*!
- * \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 <http://www.gnu.org/licenses/>.
- */
- #ifndef __utl_meta_logical_h__
- #define __utl_meta_logical_h__
-
- #include <utl/impl/impl.h>
- #include <utl/meta/bool.h>
- #include <utl/meta/if.h>
-
- /*!
- * \ingroup meta
- * \defgroup logic
- * logic operator and type relations support header
- */
- //! @{
- namespace utl {
-
- //! NOT implementation
- template<bool C_>
- struct not_ : bool_<!C_> { };
-
- //! OR implementation
- //! @{
- template<typename...> struct or_;
-
- template<>
- struct or_<>
- : false_ { };
-
- template<typename _T1>
- struct or_<_T1>
- : _T1 { };
-
- template<typename _T1, typename _T2>
- struct or_ <_T1, _T2>
- : select_<_T1::value, _T1, _T2> { };
-
- template<typename _T1, typename _T2, typename _T3, typename... _Tn>
- struct or_<_T1, _T2, _T3, _Tn...>
- : select_<_T1::value, _T1, or_<_T2, _T3, _Tn...>> { };
- //! @}
-
- //! AND implementation
- //! @{
- template<typename...> struct and_;
-
- template<>
- struct and_<>
- : true_ { };
-
- template<typename _T1>
- struct and_ <_T1>
- : _T1 { };
-
- template<typename _T1, typename _T2>
- struct and_<_T1, _T2>
- : select_<_T1::value, _T2, _T1> { };
-
- template<typename _T1, typename _T2, typename _T3, typename... _Tn>
- struct and_<_T1, _T2, _T3, _Tn...>
- : select_<_T1::value, and_<_T2, _T3, _Tn...>, _T1> { };
- //! @}
-
- //! same
- //! @{
- template<typename _T1, typename _T2>
- struct same_ : false_ { };
-
- template<typename _Tp>
- struct same_ <_Tp, _Tp> : true_ { };
- //! @}
-
- //! not same
- //! @{
- template<typename _T1, typename _T2>
- struct not_same_ : true_ { };
-
- template<typename _Tp>
- struct not_same_ <_Tp, _Tp> : false_ { };
- //! @}
- }
-
- #endif /* __utl_meta_logical_h__ */
|