[mlpack] 43/149: Allow std::cout << mlpackObject, as per #319.

Barak A. Pearlmutter barak+git at pearlmutter.net
Sat May 2 09:11:07 UTC 2015


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch svn-trunk
in repository mlpack.

commit 890a60192ca7cefd40698a4dfe44725134e9f42d
Author: rcurtin <rcurtin at 9d5b8971-822b-0410-80eb-d18c1038ef23>
Date:   Mon Oct 13 15:40:58 2014 +0000

    Allow std::cout << mlpackObject, as per #319.
    
    
    git-svn-id: http://svn.cc.gatech.edu/fastlab/mlpack/trunk@17251 9d5b8971-822b-0410-80eb-d18c1038ef23
---
 src/mlpack/core/util/ostream_extra.hpp | 37 ++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/src/mlpack/core/util/ostream_extra.hpp b/src/mlpack/core/util/ostream_extra.hpp
new file mode 100644
index 0000000..c96cb70
--- /dev/null
+++ b/src/mlpack/core/util/ostream_extra.hpp
@@ -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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list