[libsigcplusplus] with_type/with_type_pointer: Use is_base_of_or_same_v<> in declaration.



commit 0e810834689cc45b78fde8a0e7d3a2f40484fc08
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Apr 15 09:25:20 2016 +0200

    with_type/with_type_pointer: Use is_base_of_or_same_v<> in declaration.
    
    Instead of in the instantiation. This makes the relationship between
    the two template types, and their specialiations, slightly clearer.

 sigc++/visit_each.h |   22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/sigc++/visit_each.h b/sigc++/visit_each.h
index 98e575b..43dee4e 100644
--- a/sigc++/visit_each.h
+++ b/sigc++/visit_each.h
@@ -37,19 +37,19 @@ constexpr bool is_base_of_or_same_v =
 // But the SUN CC 5.7 (not earlier versions) compiler finds it ambiguous when we specify a
 // particular specialization of it.
 // and does not seem to allow us to tell it explicitly that it's an inner class.
-template <bool I_derived, class T_type, class T_limit>
+template <class T_type, class T_limit, bool I_derived = is_base_of_or_same_v<typename T_limit::target_type, 
T_type>>
 struct with_type;
 
 // Specialization for I_derived = false
 template <class T_type, class T_limit>
-struct with_type<false, T_type, T_limit>
+struct with_type<T_type, T_limit, false>
 {
   static void execute_(const T_type&, const T_limit&) {}
 };
 
 // Specialization for I_derived = true
 template <class T_type, class T_limit>
-struct with_type<true, T_type, T_limit>
+struct with_type<T_type, T_limit, true>
 {
   static void execute_(const T_type& _A_type, const T_limit& _A_action)
   {
@@ -61,13 +61,14 @@ struct with_type<true, T_type, T_limit>
 template <class T_target, class T_action>
 struct limit_derived_target
 {
+  using target_type = T_target;
+
   template <class T_type>
   void operator()(T_type&& _A_type) const
   {
     using T_self = limit_derived_target<T_target, T_action>;
 
-    with_type<is_base_of_or_same_v<T_target, T_type>,
-      T_type, T_self>::execute_(std::forward<T_type>(_A_type), *this);
+    with_type<T_type, T_self>::execute_(std::forward<T_type>(_A_type), *this);
   }
 
   explicit limit_derived_target(const T_action& _A_action) : action_(_A_action) {}
@@ -78,19 +79,19 @@ struct limit_derived_target
 // Specialization for T_target pointer types, to provide a slightly different execute_()
 // implementation.
 
-template <bool I_derived, class T_type, class T_limit>
+template <class T_type, class T_limit, bool I_derived = is_base_of_or_same_v<typename T_limit::target_type, 
T_type>>
 struct with_type_pointer;
 
 // Specialization for I_derived = false
 template <class T_type, class T_limit>
-struct with_type_pointer<false, T_type, T_limit>
+struct with_type_pointer<T_type, T_limit, false>
 {
   static void execute_(const T_type&, const T_limit&) {}
 };
 
 // Specialization for I_derived = true
 template <class T_type, class T_limit>
-struct with_type_pointer<true, T_type, T_limit>
+struct with_type_pointer<T_type, T_limit, true>
 {
   static void execute_(const T_type& _A_type, const T_limit& _A_action)
   {
@@ -101,13 +102,14 @@ struct with_type_pointer<true, T_type, T_limit>
 template <class T_target, class T_action>
 struct limit_derived_target<T_target*, T_action>
 {
+  using target_type = T_target;
+
   template <class T_type>
   void operator()(T_type&& _A_type) const
   {
     using T_self = limit_derived_target<T_target*, T_action>;
 
-    with_type_pointer<is_base_of_or_same_v<T_target, T_type>,
-      T_type, T_self>::execute_(std::forward<T_type>(_A_type), *this);
+    with_type_pointer<T_type, T_self>::execute_(std::forward<T_type>(_A_type), *this);
   }
 
   explicit limit_derived_target(const T_action& _A_action) : action_(_A_action) {}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]