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

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Mon Oct 13 11:40:59 EDT 2014


Author: rcurtin
Date: Mon Oct 13 11:40:58 2014
New Revision: 17251

Log:
Allow std::cout << mlpackObject, as per #319.


Added:
   mlpack/trunk/src/mlpack/core/util/ostream_extra.hpp

Added: mlpack/trunk/src/mlpack/core/util/ostream_extra.hpp
==============================================================================
--- (empty file)
+++ mlpack/trunk/src/mlpack/core/util/ostream_extra.hpp	Mon Oct 13 11:40:58 2014
@@ -0,0 +1,37 @@
+/**
+ * @file ostream_extra.hpp
+ * @author Ryan Curtin
+ *
+ * Allow ostream::operator<<(T&) for mlpack objects that have ToString
+ * implemented.
+ */
+#ifndef __MLPACK_CORE_UTIL_OSTREAM_EXTRA_HPP
+#define __MLPACK_CORE_UTIL_OSTREAM_EXTRA_HPP
+
+#include "sfinae_utility.hpp"
+
+// Hide in a namespace so we don't pollute the global namespace.
+
+namespace mlpack {
+namespace util {
+namespace misc {
+
+HAS_MEM_FUNC(ToString, HasToString);
+
+} // namespace misc
+} // namespace util
+} // namespace mlpack
+
+template<
+    typename T,
+    typename junk1 = typename boost::enable_if<boost::is_class<T> >::type,
+    typename junk2 = typename boost::enable_if<
+        mlpack::util::misc::HasToString<T, std::string(T::*)() const> >::type
+>
+std::ostream& operator<<(std::ostream& stream, const T& t)
+{
+  stream << t.ToString();
+  return stream;
+}
+
+#endif



More information about the mlpack-svn mailing list