|
- /*!
- * \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/core/impl.h>
- #include <utl/meta/selection.h>
-
- /*!
- * \ingroup meta
- * \defgroup logic
- * logic operator and type relations support header
- */
- //! @{
- namespace utl {
- namespace meta{
-
- /*!
- * Logical relation for types
- */
- //! @{
-
- //! Negate the *bool* constant parameter
- template <bool B>
- using not_c = bool_<!B>;
-
- //! not
- template<typename _Tp>
- using not_ = not_c<_Tp::type::value>;
-
- //! OR implementation
- //! @{
- namespace detail {
- template<typename...> struct _or_;
-
- template<>
- struct _or_<> : false_ { };
-
- template<typename _T1>
- struct _or_<_T1> : _T1 { };
-
- template<typename _T1, typename _T2>
- struct _or_ <_T1, _T2>
- : if_<_T1, _T1, _T2> { };
-
- template<typename _T1, typename _T2, typename _T3, typename... _Tn>
- struct _or_<_T1, _T2, _T3, _Tn...>
- : if_<_T1, _T1, _or_<_T2, _T3, _Tn...>> { };
- }
-
- template <typename... _Ts>
- using or_ = type_<detail::_or_<_Ts...>>;
- //! @}
-
- //! AND implementation
- //! @{
- namespace detail {
- template<typename...> struct _and_;
-
- template<>
- struct _and_<>
- : true_ { };
-
- template<typename _T1>
- struct _and_ <_T1>
- : _T1 { };
-
- template<typename _T1, typename _T2>
- struct _and_<_T1, _T2>
- : if_<_T1, _T2, _T1> { };
-
- template<typename _T1, typename _T2, typename _T3, typename... _Tn>
- struct _and_<_T1, _T2, _T3, _Tn...>
- : if_<_T1, _and_<_T2, _T3, _Tn...>, _T1> { };
- }
-
- template <typename... _Ts>
- using and_ = type_<detail::_and_<_Ts...>>;
- //! @}
-
- //! same
- //! @{
- template<typename _T1, typename _T2>
- struct same_ : false_ { };
-
- template<typename _Tp>
- struct same_ <_Tp, _Tp> : true_ { };
- //! @}
-
- //! not same
- //! @{
- template<typename _T1, typename _T2>
- using not_same_ = not_<type_<same_<_T1, _T2>>>;
- //! @}
-
- //! @}
- }}
-
- //! @}
-
- #endif /* __utl_meta_logical_h__ */
|