In this article on defining your own extensions to ::std::error_code the author recommends this code:
namespace std
{
template <>
struct is_error_code_enum<http_error>
: public true_type {};
}
in order to enable conversions from your own error constants to the system error type.
Is this reasonable? It always makes me nervous to put things into the std namespace. Is there a better way of accomplishing the goal? Failing all that, is there a part of the standard that says this is always OK to do?
Yep, specializations (for user-defined types) of existing std types are the only thing you’re allowed to put in the
stdnamespace, as long as the specialization meets the requirements for the original template.See 17.6.4.2.1 in the C++0x draft.
New types, function overloads and anything else, of course, is forbidden. But specializations of existing templates is allowed.