Ticket #7679: patchfile.patch

File patchfile.patch, 1.8 KB (added by Gary Sanders <lex21@…>, 10 years ago)
  • hex.hpp

     
    6969        return std::copy ( res, res + num_hex_digits, out );
    7070        }
    7171
    72 // this needs to be in an un-named namespace because it is not a template
    73 // and might get included in several compilation units. This could cause
    74 // multiple definition errors at link time.
    75     namespace {
    76     unsigned hex_char_to_int ( char c ) {
    77         if ( c >= '0' && c <= '9' ) return c - '0';
    78         if ( c >= 'A' && c <= 'F' ) return c - 'A' + 10;
    79         if ( c >= 'a' && c <= 'f' ) return c - 'a' + 10;
    80         BOOST_THROW_EXCEPTION (non_hex_input() << bad_char (c));
    81         return 0;     // keep dumb compilers happy
     72    template <typename T> T hex_char_to_int ( T c ) {
     73                T r;
     74        if      ( c >= static_cast<T>('0') && c <= static_cast<T>('9') ) r = c - static_cast<T>('0');
     75        else if ( c >= static_cast<T>('A') && c <= static_cast<T>('F') ) r = c - static_cast<T>('A') + 10;
     76        else if ( c >= static_cast<T>('a') && c <= static_cast<T>('f') ) r = c - static_cast<T>('a') + 10;
     77                else    BOOST_THROW_EXCEPTION (non_hex_input() << (boost::error_info<struct bad_char_,T> (c)));
     78        return r;
    8279        }
    83     }   
    84 
     80 
    8581//  My own iterator_traits class.
    8682//  It is here so that I can "reach inside" some kinds of output iterators
    8783//      and get the type to write.
     
    134130        for ( std::size_t i = 0; i < 2 * sizeof ( T ); ++i, ++first ) {
    135131            if ( pred ( first, last ))
    136132                BOOST_THROW_EXCEPTION (not_enough_input ());
    137             res = ( 16 * res ) + hex_char_to_int (static_cast<char> (*first));
     133            res = ( 16 * res ) + hex_char_to_int (*first);
    138134            }
    139135       
    140136        *out = res;