ToString.h 855 B

1234567891011121314151617181920212223242526272829303132
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set ts=8 sts=2 et sw=2 tw=80: */
  3. /* This Source Code Form is subject to the terms of the Mozilla Public
  4. * License, v. 2.0. If a copy of the MPL was not distributed with this
  5. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6. /* Utilities for converting an object to a string representation. */
  7. #ifndef mozilla_ToString_h
  8. #define mozilla_ToString_h
  9. #include <string>
  10. #include <sstream>
  11. namespace mozilla {
  12. /**
  13. * A convenience function for converting an object to a string representation.
  14. * Supports any object which can be streamed to an std::ostream.
  15. */
  16. template<typename T>
  17. std::string
  18. ToString(const T& aValue)
  19. {
  20. std::ostringstream stream;
  21. stream << aValue;
  22. return stream.str();
  23. }
  24. } // namespace mozilla
  25. #endif /* mozilla_ToString_h */