Skip to content

Commit

Permalink
Merge pull request #51 from rickyviking/stream_operator
Browse files Browse the repository at this point in the history
Implement stream operator<< in terms of the faster to_string() method.
  • Loading branch information
mariusbancila authored Dec 23, 2021
2 parents 7a3e380 + b6f1515 commit 487f364
Showing 1 changed file with 1 addition and 29 deletions.
30 changes: 1 addition & 29 deletions include/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -552,35 +552,7 @@ namespace uuids
template <class Elem, class Traits>
std::basic_ostream<Elem, Traits> & operator<<(std::basic_ostream<Elem, Traits> &s, uuid const & id)
{
// save current flags
std::ios_base::fmtflags f(s.flags());

// manipulate stream as needed
s << std::hex << std::setfill(static_cast<Elem>('0'))
<< std::setw(2) << static_cast<int>(id.data[0])
<< std::setw(2) << static_cast<int>(id.data[1])
<< std::setw(2) << static_cast<int>(id.data[2])
<< std::setw(2) << static_cast<int>(id.data[3])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[4])
<< std::setw(2) << static_cast<int>(id.data[5])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[6])
<< std::setw(2) << static_cast<int>(id.data[7])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[8])
<< std::setw(2) << static_cast<int>(id.data[9])
<< '-'
<< std::setw(2) << static_cast<int>(id.data[10])
<< std::setw(2) << static_cast<int>(id.data[11])
<< std::setw(2) << static_cast<int>(id.data[12])
<< std::setw(2) << static_cast<int>(id.data[13])
<< std::setw(2) << static_cast<int>(id.data[14])
<< std::setw(2) << static_cast<int>(id.data[15]);

// restore original flags
s.flags(f);

s << to_string(id);
return s;
}

Expand Down

0 comments on commit 487f364

Please sign in to comment.