|
- /*!
- * \file use.h
- * \brief Template meta-programming SFINAE helpers
- *
- * 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_use_h__
- #define __utl_meta_use_h__
-
- #include <utl/impl/impl.h>
- #include <utl/meta/logical.h>
-
-
- /*!
- * \ingroup meta
- * \defgroup use
- * conditional use support header. This is a SFINAE helper
- */
- //! @{
- namespace utl {
-
- /*!
- * void_t
- * Utility meta-function that maps a sequence of any types to the type void
- * \note The idea is:
- * template <typename ...>
- * using void_t = void;
- *
- * Until CWG 1558 (a C++14 defect), unused parameters in alias templates were not
- * guaranteed to ensure SFINAE and could be ignored, so earlier compilers require
- * a more complex definition of void_t, such as the following implementation
- * https://en.cppreference.com
- */
- //! @{
- template<typename... _Ts>
- struct void_t_impl {
- typedef void type;
- };
- //! The actual void_t type alias
- template<typename... _Ts>
- using void_t = typename void_t_impl<_Ts...>::type;
- //! @}
-
- //! Alias template for if_
- template<bool _Check, typename _Tp = void>
- using if_t = typename if_<_Check, _Tp>::type;
-
- //! Publicly recognized alias template for if_
- template<bool _Check, typename _Tp = void>
- using enable_if_t = typename if_<_Check, _Tp>::type;
-
- //! Uniform alias template for if_
- template<bool _Check, typename _Tp = void>
- using use_if_t = typename if_<_Check, _Tp>::type;
-
- //! If same type resolves to _Ret, else SFINAE
- template <typename _T1, typename _T2, typename _Ret =_T1>
- using use_if_same_t = typename if_<same_<_T1, _T2>::value, _Ret>::type;
-
- //! If not same type resolves to _Ret, else SFINAE
- template <typename _T1, typename _T2, typename _Ret =_T1>
- using use_if_not_same_t = typename if_<!same_<_T1, _T2>::value, _Ret>::type;
-
- //! If any type (_T1 or _T2) type resolves to _Ret, else to SFINAE
- template <typename _T1, typename _T2, typename _Ret =_T1>
- using use_if_any_t = typename if_<or_<_T1, _T2>::value, _Ret>::type;
-
- //! If both type (_T1 and _T2) type resolves to _Ret, else to SFINAE
- template <typename _T1, typename _T2, typename _Ret =_T1>
- using use_if_both_t = typename if_<and_<_T1, _T2>::value, _Ret>::type;
-
- }
-
- //! @}
- #endif /* __utl_meta_use_h__ */
|