From b916df3b6208697b7af9c00cbd75cf58c173e228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Wed, 2 Jan 2019 17:39:55 +0100 Subject: [PATCH] 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. --- include/ebcl/Utilities.hh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/include/ebcl/Utilities.hh b/include/ebcl/Utilities.hh index 875cc1a..86ba32b 100644 --- a/include/ebcl/Utilities.hh +++ b/include/ebcl/Utilities.hh @@ -136,8 +136,7 @@ template< typename... List > template< typename Parent , typename Child -> -using EnableForChild = +> using EnableForChild = std::enable_if< std::is_base_of< Parent , Child >::value , bool @@ -151,8 +150,7 @@ using T_EnableForChild = typename EnableForChild::type; template< typename Child , typename Parent -> -using EnableForParent = +> using EnableForParent = std::enable_if< std::is_base_of< Parent , Child >::value && !std::is_same< Parent , Child >::value , @@ -162,6 +160,25 @@ using EnableForParent = template< typename C , typename P > using T_EnableForParent = typename EnableForParent::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