From 386b88ab0dceede2157614870fffda6d0c72dbac Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sat, 3 Sep 2016 07:59:39 +0200
Subject: [PATCH] add trait to match cv, and ref qualifiers

---
 alib2std/src/extensions/type_traits.hpp | 38 +++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/alib2std/src/extensions/type_traits.hpp b/alib2std/src/extensions/type_traits.hpp
index c70b412e20..f44e22e44b 100644
--- a/alib2std/src/extensions/type_traits.hpp
+++ b/alib2std/src/extensions/type_traits.hpp
@@ -21,6 +21,8 @@ namespace std {
 		static const bool value = sizeof(Yes) == sizeof(has_clone::test((typename std::remove_reference<T>::type*)0));
 	};
 
+// ----------------------------------------------------------------------------------------------------
+
 	template <typename T>
 	struct is_base_of<T, T> {
 		static const bool value = true;
@@ -41,6 +43,8 @@ namespace std {
 		static const bool value = is_base_of<T, F>::value || is_base_of_any<T, Ts...>::value;
 	};
 
+// ----------------------------------------------------------------------------------------------------
+
 	template < size_t N, typename ... T >
 	struct get_type_pack_element;
 
@@ -54,6 +58,8 @@ namespace std {
 		typedef typename get_type_pack_element < N - 1, Ts ... >::type type;
 	};
 
+// ----------------------------------------------------------------------------------------------------
+
 	template < typename T, typename ... Ts >
 	struct is_in;
 
@@ -66,6 +72,38 @@ namespace std {
 	template < typename T, typename ... Ts >
 	struct is_in < T, T, Ts ... > : std::true_type { };
 
+// ----------------------------------------------------------------------------------------------------
+
+	template < class Ref, class Type >
+	struct match_cv_ref_rec {
+		typedef Type type;
+	};
+
+	template < class Ref, class Type >
+	struct match_cv_ref_rec < const Ref, Type > {
+		typedef typename add_const < typename match_cv_ref_rec < Ref, Type >::type >::type type;
+	};
+
+	template < class Ref, class Type >
+	struct match_cv_ref_rec < Ref &, Type > {
+		typedef typename add_lvalue_reference < typename match_cv_ref_rec < Ref, Type >::type >::type type;
+	};
+
+	template < class Ref, class Type >
+	struct match_cv_ref_rec < Ref &&, Type > {
+		typedef typename add_rvalue_reference < typename match_cv_ref_rec < Ref, Type >::type >::type type;
+	};
+
+	template < class Ref, class Type >
+	struct match_cv_ref_rec < volatile Ref, Type > {
+		typedef typename add_volatile < typename match_cv_ref_rec < Ref, Type >::type >::type type;
+	};
+
+	template < class Ref, class Type >
+	struct match_cv_ref {
+		typedef typename match_cv_ref_rec < Ref, typename decay < Type >::type >::type type;
+	};
+
 } /* namespace std */
 
 #endif /* __TYPE_TRAITS_HPP_ */
-- 
GitLab