[mlpack-svn] r13455 - mlpack/trunk/src/mlpack/core/util

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Aug 24 12:53:46 EDT 2012


Author: trironk3
Date: 2012-08-24 12:53:46 -0400 (Fri, 24 Aug 2012)
New Revision: 13455

Modified:
   mlpack/trunk/src/mlpack/core/util/prefixedoutstream.hpp
   mlpack/trunk/src/mlpack/core/util/prefixedoutstream_impl.hpp
   mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp
Log:
#164:
Started documenting sfinae_utilities.hpp.

Moved implementations of CallBaseLogic into prefixedoutstream_impl.hpp


Modified: mlpack/trunk/src/mlpack/core/util/prefixedoutstream.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/prefixedoutstream.hpp	2012-08-24 16:24:24 UTC (rev 13454)
+++ mlpack/trunk/src/mlpack/core/util/prefixedoutstream.hpp	2012-08-24 16:53:46 UTC (rev 13455)
@@ -122,40 +122,28 @@
   void CallBaseLogic(T s,
       typename boost::disable_if<
           boost::is_class<T>
-      >::type* = 0)
-  {
-    BaseLogic<T>(s);
-  }
+      >::type*);
 
-  // Forward all objects that do not implement a ToString() method transparently
+  //! Forward all objects that do not implement a ToString() method 
   template<typename T>
   void CallBaseLogic(T s,
       typename boost::enable_if<
           boost::is_class<T>
-      >::type* = 0,
+      >::type*,
       typename boost::disable_if<
           HasToString<T, std::string(T::*)() const>
-      >::type* = 0)
-  {
-    BaseLogic<T>(s);
-  }
+      >::type*);
   
-  // Call ToString() on all objects that implement ToString() before forwarding
+  //! Call ToString() on all objects that implement ToString() before forwarding
   template<typename T>
   void CallBaseLogic(T s,
       typename boost::enable_if<
           boost::is_class<T>
-      >::type* = 0,
+      >::type*,
       typename boost::enable_if<
           HasToString<T, std::string(T::*)() const>
-      >::type* = 0)
-  {
-    std::string result = s.ToString();
-    BaseLogic<std::string&>(result);
-  }
+      >::type*);
 
-
-
   /**
    * @brief Conducts the base logic required in all the operator << overloads.
    *   Mostly just a good idea to reduce copy-pasta.

Modified: mlpack/trunk/src/mlpack/core/util/prefixedoutstream_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/prefixedoutstream_impl.hpp	2012-08-24 16:24:24 UTC (rev 13454)
+++ mlpack/trunk/src/mlpack/core/util/prefixedoutstream_impl.hpp	2012-08-24 16:53:46 UTC (rev 13455)
@@ -19,6 +19,43 @@
   return *this;
 }
 
+//! This handles forwarding all primitive types transparently
+template<typename T> 
+void PrefixedOutStream::CallBaseLogic(T s,
+    typename boost::disable_if<
+        boost::is_class<T>
+    >::type* = 0)
+{ 
+  BaseLogic<T>(s);
+}
+
+// Forward all objects that do not implement a ToString() method transparently
+template<typename T> 
+void PrefixedOutStream::CallBaseLogic(T s,
+    typename boost::enable_if<
+        boost::is_class<T>
+    >::type* = 0,
+    typename boost::disable_if<
+        HasToString<T, std::string(T::*)() const>
+    >::type* = 0)
+{ 
+  BaseLogic<T>(s);
+}
+
+// Call ToString() on all objects that implement ToString() before forwarding
+template<typename T> 
+void PrefixedOutStream::CallBaseLogic(T s,
+    typename boost::enable_if<
+        boost::is_class<T>
+    >::type* = 0,
+    typename boost::enable_if<
+        HasToString<T, std::string(T::*)() const>
+    >::type* = 0)
+{ 
+  std::string result = s.ToString();
+  BaseLogic<std::string&>(result);
+}
+
 template<typename T>
 void PrefixedOutStream::BaseLogic(T val)
 {

Modified: mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp	2012-08-24 16:24:24 UTC (rev 13454)
+++ mlpack/trunk/src/mlpack/core/util/sfinae_utility.hpp	2012-08-24 16:53:46 UTC (rev 13455)
@@ -2,10 +2,10 @@
  * @file sfinae_utility.hpp
  * @author Trironk Kiatkungwanglai
  *
- * Utilities for the SFINAE Paradigm.
- *
- * Taken from http://stackoverflow.com/a/6324863/391618
- *
+ * This file contains macro utilities for the SFINAE Paradigm. These utilities
+ * determine if classes passed in as template parameters contain members at
+ * compile time, which is useful for changing functionality depending on what
+ * operations an object is capable of performing.
  */
 #ifndef __MLPACK_CORE_SFINAE_UTILITY
 #define __MLPACK_CORE_SFINAE_UTILITY
@@ -13,15 +13,23 @@
 #include <boost/utility/enable_if.hpp>
 #include <boost/type_traits.hpp>
 
-// Taken from: http://stackoverflow.com/a/264088/391618
-
-#define HAS_MEM_FUNC(func, name)                                               \
+/*
+ * Note: This macro is taken from http://stackoverflow.com/a/264088/391618
+ *
+ * This macro generates a template struct that is useful for enabling/disabling
+ * a method if the template class passed in contains a member function matching
+ * a given signature with a specified name.
+ * 
+ * @param NAME the name of the struct to construct. For example: HasToString
+ * @param FUNC the name of the function to check for. For example: ToString
+ */
+#define HAS_MEM_FUNC(FUNC, NAME)                                               \
     template<typename T, typename sig>                                         \
-    struct name {                                                              \
+    struct NAME {                                                              \
         typedef char yes;                                                      \
         typedef long no;                                                       \
         template <typename U, U> struct type_check;                            \
-        template <typename _1> static yes &chk(type_check<sig, &_1::func> *);  \
+        template <typename _1> static yes &chk(type_check<sig, &_1::FUNC> *);  \
         template <typename   > static no  &chk(...);                           \
         static bool const value = sizeof(chk<T>(0)) == sizeof(yes);            \
     };




More information about the mlpack-svn mailing list