[mlpack-git] master: Allow std::cout << mlpackObject, as per #319. (319d50b)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:01:28 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40
>---------------------------------------------------------------
commit 319d50ba0e9d96491f6571226508ac172cfc1784
Author: Ryan Curtin <ryan at ratml.org>
Date: Mon Oct 13 15:40:58 2014 +0000
Allow std::cout << mlpackObject, as per #319.
>---------------------------------------------------------------
319d50ba0e9d96491f6571226508ac172cfc1784
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
More information about the mlpack-git
mailing list