|
Boost : |
From: Oleg Abrosimov (olegabr_at_[hidden])
Date: 2007-05-12 22:34:29
Beman Dawes wrote:
> The C++ committee accepted what is essentially Boost.System for C++0x.
> See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2241.html
> for the final proposal.
Looks nice. With one issue:
This document has following wording:
virtual string message(error_code::value_type ev) const=0;
Returns: A string that describes the error condition denoted by ev.
[Note: The intent is to return a locale sensitive string that
describes the error corresponding to ev. --end note.]
Throws: Nothing.
virtual wstring wmessage(error_code::value_type ev) const=0;
Returns: A string that describes the error condition denoted by ev.
[Note: The intent is to return a locale sensitive string that
describes the error corresponding to ev. --end note.]
Throws: Nothing.
[snip]
class error_code
{
public:
// snipped code
string message() const;
wstring wmessage() const;
// snipped code
};
locale sensitivity is good, but in this form user is enforced to
set/unset global locale each time he wants to use locale sensitive
output from error_category like this:
std::locale oldLocale = std::locale::global(myLocale);
std::cout << err_cat.message(ev);
std::locale::global(oldLocale);
It is tedious, requires additional work to make it exception safe and
thread safe.
I propose to change wording to the following:
virtual string message(error_code::value_type ev, std::locale loc =
std::locale()) const=0;
Returns: A string that describes the error condition denoted by ev.
[Note: The intent is to return a locale sensitive string that
describes the error corresponding to ev. --end note.]
Throws: Nothing.
virtual wstring wmessage(error_code::value_type ev, std::locale loc =
std::locale()) const=0;
Returns: A string that describes the error condition denoted by ev.
[Note: The intent is to return a locale sensitive string that
describes the error corresponding to ev. --end note.]
Throws: Nothing.
[snip]
class error_code
{
public:
// snipped code
string message(std::locale loc = std::locale()) const;
wstring wmessage(std::locale loc = std::locale()) const;
// snipped code
};
Then user code would be as simple as:
std::cout << err_cat.message(ev, myLocale);
global state is not touched here, so no problems with exception and
thread safety (I don't take cout into account here)
Oleg Abrosimov.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk