constexprchar ZERO = '0', NINE = '9' ;
inlinebool is_unsigned_number( const std::string& number )
{
for( char c : number ) if( c < '0' || c > '9' ) returnfalse ;
return !number.empty() ;
}
std::string operator+ ( const std::string& number, unsignedint value )
{
assert( is_unsigned_number(number) ) ;
constexprint TEN = 10 ;
std::string result ;
result.reserve( number.size() + 2 ) ;
for( auto iter = number.rbegin() ; iter != number.rend() ; ++iter )
{
int digit = *iter - ZERO + value ;
value = digit / TEN ;
result = char( digit % TEN + ZERO ) + result ;
}
while( value > 0 )
{
result = char( value % TEN + ZERO ) + result ;
value = value / TEN ;
}
return result ;
}
inline std::string operator+ ( unsignedint value, const std::string& number )
{ return number + value ; }
int main()
{
std::string n = "12345" ;
std::cout << n + 999999U << ' ' << 1234U + n << '\n' ;
}