83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
/*!
|
|
* \file sfinae.h
|
|
* \brief Template meta-programming SFINAE helpers
|
|
*/
|
|
#ifndef __utl_meta_sfinae_h__
|
|
#define __utl_meta_sfinae_h__
|
|
|
|
#include <utl/core/impl.h>
|
|
#include <utl/meta/basic.h>
|
|
#include <type_traits>
|
|
|
|
/*!
|
|
* \ingroup meta
|
|
* \defgroup sfinae SFINAE
|
|
* conditional use support header.
|
|
*/
|
|
//! @{
|
|
namespace utl {
|
|
namespace meta {
|
|
|
|
//! \name enable_if from STL
|
|
//! @{
|
|
|
|
//! enable_if, imported from stl
|
|
template <bool If, typename _Tp = void> using enable_if = std::enable_if<If, _Tp>;
|
|
|
|
//! alias template for enable_if
|
|
template<bool If, typename _Tp = void> using enable_if_t = eval< enable_if<If, _Tp> >;
|
|
|
|
//! @}
|
|
|
|
//! \name when implementation
|
|
//! @{
|
|
namespace details {
|
|
// template <typename... T>
|
|
// struct dev_null { using type = dev_null; }; //< Same as typelist
|
|
|
|
template <bool If> struct when_ { };
|
|
template <> struct when_<true> { using type = void; };
|
|
}
|
|
//! Tool to enable a partial specialization only if a boolean condition is true.
|
|
//! Well formed only if \p If is true
|
|
template <bool If>
|
|
using when = eval< details::when_<If> >;
|
|
|
|
// //! Well formed only if all of \p Ifs are \c true
|
|
// template <bool ...Ifs>
|
|
// using when_all = details::dev_null<
|
|
// when<Ifs>...
|
|
// >;
|
|
|
|
//! @}
|
|
|
|
//! If same type resolves to _Ret, else SFINAE
|
|
template <typename _T1, typename _T2, typename _Ret =_T1>
|
|
using use_if_same_t = enable_if_t<
|
|
same<_T1, _T2>::value, _Ret
|
|
>;
|
|
//! If not same type resolves to _Ret, else SFINAE
|
|
template <typename _T1, typename _T2, typename _Ret =_T1>
|
|
using use_if_not_same_t = enable_if_t<
|
|
!same<_T1, _T2>::value, _Ret
|
|
>;
|
|
//! If any type (_T1 or _T2) type resolves to _Ret, else to SFINAE
|
|
template <typename T1, typename... Ts>
|
|
using use_if_any_t = enable_if_t<
|
|
or_<T1, Ts...>::value, T1
|
|
>;
|
|
|
|
//! If both type (_T1 and _T2) type resolves to _Ret, else to SFINAE
|
|
template <typename T1, typename... Ts>
|
|
using use_if_all_t = enable_if_t<
|
|
and_<T1, Ts...>::value, T1
|
|
>;
|
|
|
|
|
|
|
|
}}
|
|
|
|
//! @}
|
|
|
|
#endif /* __utl_meta_sfinae_h__ */
|