From cf8f91ebd60efa2ba857de78b669678766b933e4 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <jan.travnicek@.fit.cvut.cz>
Date: Fri, 14 Jun 2019 11:54:40 +0200
Subject: [PATCH] use constexpr_switch elsewhere

---
 .../src/common/AbstractionHelpers.hpp         | 38 +++++++++----------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/alib2abstraction/src/common/AbstractionHelpers.hpp b/alib2abstraction/src/common/AbstractionHelpers.hpp
index 4a86d5dec0..f4e84c11bb 100644
--- a/alib2abstraction/src/common/AbstractionHelpers.hpp
+++ b/alib2abstraction/src/common/AbstractionHelpers.hpp
@@ -50,33 +50,29 @@ struct CheckInput {
 };
 
 template < class ... Params >
-struct ParamType;
+struct ParamType {
+	static ext::type_index paramType ( unsigned index ) {
+		ext::type_index res ( typeid ( void ) );
 
-template < >
-struct ParamType < > {
-	static ext::type_index paramType ( unsigned ) {
-		throw std::logic_error ( "Out of types to check" );
-	}
+		auto lambda = [ & ] ( auto I ) {
+			res = ext::type_index ( typeid ( std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > ) );
+		};
 
-	static ext::set < abstraction::ParamQualifiers::ParamQualifier > paramTypeQualifiers ( unsigned ) {
-		throw std::logic_error ( "Out of types to check" );
-	}
-};
+		ext::constexpr_switch < sizeof ... ( Params ) > ( index, lambda );
 
-template < class Param, class ... Params >
-struct ParamType < Param, Params ... > {
-	static ext::type_index paramType ( unsigned index ) {
-		if ( index == 0 )
-			return ext::type_index ( typeid ( Param ) );
-		else
-			return ParamType < Params ... >::paramType ( index - 1 );
+		return res;
 	}
 
 	static ext::set < abstraction::ParamQualifiers::ParamQualifier > paramTypeQualifiers ( unsigned index ) {
-		if ( index == 0 )
-			return abstraction::ParamQualifiers::paramQualifiers < Param > ( );
-		else
-			return ParamType < Params ... >::paramTypeQualifiers ( index - 1 );
+		ext::set < abstraction::ParamQualifiers::ParamQualifier > res;
+
+		auto lambda = [ & ] ( auto I ) {
+			res = abstraction::ParamQualifiers::paramQualifiers < std::tuple_element_t < decltype ( I )::value, std::tuple < Params ... > > > ( );
+		};
+
+		ext::constexpr_switch < sizeof ... ( Params ) > ( index, lambda );
+
+		return res;
 	}
 };
 
-- 
GitLab