to_wstring added

This commit is contained in:
Alex Alabuzhev 2017-08-27 15:48:33 +01:00 committed by Jonathan Müller
parent 37eb419af2
commit 89654cd127
3 changed files with 24 additions and 0 deletions

View File

@ -262,6 +262,8 @@ Utilities
.. doxygenfunction:: fmt::to_string(const T&)
.. doxygenfunction:: fmt::to_wstring(const T&)
.. doxygenclass:: fmt::BasicStringRef
:members:

View File

@ -125,6 +125,24 @@ std::string to_string(const T &value) {
w << value;
return w.str();
}
/**
\rst
Converts *value* to ``std::wstring`` using the default format for type *T*.
**Example**::
#include "fmt/string.h"
std::wstring answer = fmt::to_wstring(42);
\endrst
*/
template <typename T>
std::wstring to_wstring(const T &value) {
fmt::WMemoryWriter w;
w << value;
return w.str();
}
}
#endif // FMT_STRING_H_

View File

@ -78,3 +78,7 @@ TEST(StringWriterTest, WString) {
TEST(StringTest, ToString) {
EXPECT_EQ("42", fmt::to_string(42));
}
TEST(StringTest, ToWString) {
EXPECT_EQ(L"42", fmt::to_wstring(42));
}