Index: hex.hpp =================================================================== --- hex.hpp (revision 81324) +++ hex.hpp (working copy) @@ -69,19 +69,15 @@ return std::copy ( res, res + num_hex_digits, out ); } -// this needs to be in an un-named namespace because it is not a template -// and might get included in several compilation units. This could cause -// multiple definition errors at link time. - namespace { - unsigned hex_char_to_int ( char c ) { - if ( c >= '0' && c <= '9' ) return c - '0'; - if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10; - if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10; - BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c)); - return 0; // keep dumb compilers happy + template T hex_char_to_int ( T c ) { + T r; + if ( c >= static_cast('0') && c <= static_cast('9') ) r = c - static_cast('0'); + else if ( c >= static_cast('A') && c <= static_cast('F') ) r = c - static_cast('A') + 10; + else if ( c >= static_cast('a') && c <= static_cast('f') ) r = c - static_cast('a') + 10; + else BOOST_THROW_EXCEPTION (non_hex_input() << (boost::error_info (c))); + return r; } - } - + // My own iterator_traits class. // It is here so that I can "reach inside" some kinds of output iterators // and get the type to write. @@ -134,7 +130,7 @@ for ( std::size_t i = 0; i < 2 * sizeof ( T ); ++i, ++first ) { if ( pred ( first, last )) BOOST_THROW_EXCEPTION (not_enough_input ()); - res = ( 16 * res ) + hex_char_to_int (static_cast (*first)); + res = ( 16 * res ) + hex_char_to_int (*first); } *out = res;