Bug 961289 - Add a ToString utility to MFBT. r=froydnj
authorBotond Ballo <botond@mozilla.com>
Wed, 07 May 2014 14:54:45 -0400
changeset 195752 1418ea88f93436a4286dfd1ee885ffc6ddf8fdd5
parent 195751 868026800a5931c07074d13f346d1674981a8557
child 195753 c200536ef0c0be1ef466c9522442a946bb260076
push id5990
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:40:24 +0000
treeherdermozilla-aurora@0796197efbc9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs961289
milestone32.0a1
Bug 961289 - Add a ToString utility to MFBT. r=froydnj
mfbt/ToString.h
mfbt/moz.build
new file mode 100644
--- /dev/null
+++ b/mfbt/ToString.h
@@ -0,0 +1,32 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* Utilities for converting an object to a string representation. */
+
+#ifndef mozilla_ToString_h
+#define mozilla_ToString_h
+
+#include <string>
+#include <sstream>
+
+namespace mozilla {
+
+/**
+ * A convenience function for converting an object to a string representation.
+ * Supports any object which can be streamed to an std::ostream.
+ */
+template<typename T>
+std::string
+ToString(const T& t)
+{
+  std::ostringstream stream;
+  stream << t;
+  return stream.str();
+}
+
+} // namespace mozilla
+
+#endif /* mozilla_ToString_h */
--- a/mfbt/moz.build
+++ b/mfbt/moz.build
@@ -55,16 +55,17 @@ EXPORTS.mozilla = [
     'ReentrancyGuard.h',
     'RefPtr.h',
     'RollingMean.h',
     'Scoped.h',
     'SHA1.h',
     'SplayTree.h',
     'TemplateLib.h',
     'ThreadLocal.h',
+    'ToString.h',
     'TypedEnum.h',
     'TypedEnumBits.h',
     'TypedEnumInternal.h',
     'Types.h',
     'TypeTraits.h',
     'Vector.h',
     'WeakPtr.h',
 ]