[libsigc++2] Revert "C++11: Use std::is_base_of<> instead of our sigc::is_base_and_derived<>."



commit f090f5958db1dfb64da8032ef14ee06819b4ca6e
Author: Murray Cumming <murrayc murrayc com>
Date:   Sat Jul 18 11:05:44 2015 +0200

    Revert "C++11: Use std::is_base_of<> instead of our sigc::is_base_and_derived<>."
    
    This reverts commit bf89034e116d4d9eb761ceb4597c69f0f2b9c597.
    I didn't meat to push that quite yet.

 sigc++/adaptors/macros/adaptor_trait.h.m4      |    4 +-
 sigc++/adaptors/macros/deduce_result_type.h.m4 |    2 +-
 sigc++/functors/macros/functor_trait.h.m4      |    2 +-
 sigc++/macros/limit_reference.h.m4             |    2 +-
 sigc++/type_traits.h                           |   81 ++++++++++++++++++++++++
 5 files changed, 86 insertions(+), 5 deletions(-)
---
diff --git a/sigc++/adaptors/macros/adaptor_trait.h.m4 b/sigc++/adaptors/macros/adaptor_trait.h.m4
index 3522d7d..cb95f6b 100644
--- a/sigc++/adaptors/macros/adaptor_trait.h.m4
+++ b/sigc++/adaptors/macros/adaptor_trait.h.m4
@@ -209,9 +209,9 @@ struct visitor<adaptor_functor<T_functor> >
  * @ingroup adaptors
  */
 #ifndef DOXYGEN_SHOULD_SKIP_THIS
-template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct 
adaptor_trait;
+template <class T_functor, bool I_isadaptor = is_base_and_derived<adaptor_base, T_functor>::value> struct 
adaptor_trait;
 #else
-template <class T_functor, bool I_isadaptor = std::is_base_of<adaptor_base, T_functor>::value> struct 
adaptor_trait {};
+template <class T_functor, bool I_isadaptor = is_base_and_derived<adaptor_base, T_functor>::value> struct 
adaptor_trait {};
 #endif
 
 /** Trait that specifies what is the adaptor version of a functor type.
diff --git a/sigc++/adaptors/macros/deduce_result_type.h.m4 b/sigc++/adaptors/macros/deduce_result_type.h.m4
index 5d3f4ed..1c1f416 100644
--- a/sigc++/adaptors/macros/deduce_result_type.h.m4
+++ b/sigc++/adaptors/macros/deduce_result_type.h.m4
@@ -86,7 +86,7 @@ struct adaptor_base : public functor_base {};
  */
 template <class T_functor,
           LOOP(class T_arg%1=void, CALL_SIZE),
-          bool I_derives_adaptor_base = std::is_base_of<adaptor_base,T_functor>::value>
+          bool I_derives_adaptor_base=is_base_and_derived<adaptor_base,T_functor>::value>
 struct deduce_result_type
   { typedef typename functor_trait<T_functor>::result_type type; };
 
diff --git a/sigc++/functors/macros/functor_trait.h.m4 b/sigc++/functors/macros/functor_trait.h.m4
index cd82ff5..c5fc039 100644
--- a/sigc++/functors/macros/functor_trait.h.m4
+++ b/sigc++/functors/macros/functor_trait.h.m4
@@ -157,7 +157,7 @@ public:
  * @ingroup sigcfunctors
  */
 template <class T_functor,
-          bool I_derives_functor_base = std::is_base_of<functor_base,T_functor>::value,
+          bool I_derives_functor_base = is_base_and_derived<functor_base,T_functor>::value,
           bool I_can_use_decltype = can_deduce_result_type_with_decltype<T_functor>::value>
 struct functor_trait
 {
diff --git a/sigc++/macros/limit_reference.h.m4 b/sigc++/macros/limit_reference.h.m4
index 679a86c..bb4b3b7 100644
--- a/sigc++/macros/limit_reference.h.m4
+++ b/sigc++/macros/limit_reference.h.m4
@@ -41,7 +41,7 @@ define([LIMIT_REFERENCE],[dnl
  */
 template <class T_type,
           bool I_derives_trackable =
-            std::is_base_of<trackable, T_type>::value>
+            is_base_and_derived<trackable, T_type>::value>
 class [$1]limit_reference
 {
 public:
diff --git a/sigc++/type_traits.h b/sigc++/type_traits.h
index 597b23b..811be19 100644
--- a/sigc++/type_traits.h
+++ b/sigc++/type_traits.h
@@ -69,6 +69,87 @@ struct type_trait<void>
   typedef void* pointer;
 };
 
+
+// From Esa Pulkkin:
+/**
+ * Compile-time determination of base-class relationship in C++
+ * (adapted to match the syntax of boost's type_traits library).
+ *
+ * Use this to provide a template specialization for a set of types.
+ * For instance,
+ *
+ * @code
+ * template < class T_thing, bool Tval_derives_from_something = sigc::is_base_and_derived<Something, 
T_thing>::value >
+ * class TheTemplate
+ * {
+ *   //Standard implementation.
+ * }
+ *
+ * //Specialization for T_things that derive from Something (Tval_derives_from_something is true)
+ * template <class T_thing>
+ * class TheTemplate<T_thing, true>
+ * {
+ *   T_thing thing;
+ *   thing.method_that_is_in_something();
+ * }
+ * @endcode
+ *
+ * sigc::is_base_and_derived<> is used internally in libsigc++. If you need such a
+ * template class elsewhere, and you have a C++11 compiler, std::is_base_of<>
+ * is recommended.
+ */
+template <class T_base, class T_derived>
+struct is_base_and_derived
+{
+private:
+  struct big {
+    char memory[64];
+  };
+
+#ifndef SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
+
+  //Allow the internal inner class to access the other (big) inner
+  //class.  The Tru64 compiler needs this. murrayc.
+  friend struct internal_class;
+
+  //Certain compilers, notably GCC 3.2, require these functions to be inside an inner class.
+  struct internal_class
+  {
+    static big  is_base_class_(...);
+    static char is_base_class_(typename type_trait<T_base>::pointer);
+  };
+
+public:
+  static const bool value =
+    sizeof(internal_class::is_base_class_(reinterpret_cast<typename 
type_trait<T_derived>::pointer>(nullptr))) ==
+    sizeof(char);
+
+#else //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
+
+  //The AIX xlC compiler does not like these 2 functions being in the inner class.
+  //It says "The incomplete type "test" must not be used as a qualifier.
+  //It does not seem necessary anyway. murrayc.
+  static big  is_base_class_(...);
+  static char is_base_class_(typename type_trait<T_base>::pointer);
+
+public:
+  static const bool value =
+    sizeof(is_base_class_(reinterpret_cast<typename type_trait<T_derived>::pointer>(0))) ==
+    sizeof(char);
+
+#endif //SIGC_SELF_REFERENCE_IN_MEMBER_INITIALIZATION
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+  void avoid_gcc3_warning_(); //Not implemented. g++ 3.3.5 (but not 3.3.4, and not 3.4) warn that there are 
no public methods, even though there is a public variable.
+#endif
+};
+
+template <class T_base>
+struct is_base_and_derived<T_base, T_base>
+{
+  static const bool value = true;
+};
+
 } /* namespace sigc */
 
 #endif /* _SIGC_TYPE_TRAIT_H_ */


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