Utilities - EnableForHierarchy< T1 , T2 >

Templated horror that corresponds to a std::enable_if for which the
condition will be true if T1 and T2 are in the same type hierarchy.
This commit is contained in:
Emmanuel BENOîT 2019-01-02 17:39:55 +01:00
parent 5f3911a067
commit b916df3b62

View file

@ -136,8 +136,7 @@ template< typename... List >
template< template<
typename Parent , typename Parent ,
typename Child typename Child
> > using EnableForChild =
using EnableForChild =
std::enable_if< std::enable_if<
std::is_base_of< Parent , Child >::value , std::is_base_of< Parent , Child >::value ,
bool bool
@ -151,8 +150,7 @@ using T_EnableForChild = typename EnableForChild<C, P>::type;
template< template<
typename Child , typename Child ,
typename Parent typename Parent
> > using EnableForParent =
using EnableForParent =
std::enable_if< std::enable_if<
std::is_base_of< Parent , Child >::value std::is_base_of< Parent , Child >::value
&& !std::is_same< Parent , Child >::value , && !std::is_same< Parent , Child >::value ,
@ -162,6 +160,25 @@ using EnableForParent =
template< typename C , typename P > template< typename C , typename P >
using T_EnableForParent = typename EnableForParent<C, P>::type; using T_EnableForParent = typename EnableForParent<C, P>::type;
// EnableForHierarchy< T1 , T2 > - Enable if T1 and T2 are the same, or if
// T1 is the child of T2 or if T2 is the child of T1
template<
typename T1 ,
typename T2
> using EnableForHierarchy =
std::enable_if< MetaOr<
std::is_same< T1 , T2 > ,
std::is_base_of< T1 , T2 > ,
std::is_base_of< T2 , T1 >
>::value ,
bool
>;
template<
typename T1 ,
typename T2
> using T_EnableForHierarchy = typename EnableForHierarchy< T1 , T2 >::type;
/*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/
// Remove const and topmost reference // Remove const and topmost reference