Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

to_wstring added #559

Merged
merged 1 commit into from
Aug 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ Utilities

.. doxygenfunction:: fmt::to_string(const T&)

.. doxygenfunction:: fmt::to_wstring(const T&)

.. doxygenclass:: fmt::BasicStringRef
:members:

Expand Down
18 changes: 18 additions & 0 deletions fmt/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
4 changes: 4 additions & 0 deletions test/string-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}