Skip to content

Commit

Permalink
Merge pull request #23 from rickyviking/streamOperator
Browse files Browse the repository at this point in the history
Stream << operator: restore original flags after streaming the uuid
  • Loading branch information
mariusbancila authored Sep 9, 2020
2 parents 207f06b + 904224f commit f08b54b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion include/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,11 @@ namespace uuids
template <class Elem, class Traits>
std::basic_ostream<Elem, Traits> & operator<<(std::basic_ostream<Elem, Traits> &s, uuid const & id)
{
return s << std::hex << std::setfill(static_cast<Elem>('0'))
// 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) << (int)id.data[0]
<< std::setw(2) << (int)id.data[1]
<< std::setw(2) << (int)id.data[2]
Expand All @@ -562,6 +566,11 @@ namespace uuids
<< std::setw(2) << (int)id.data[13]
<< std::setw(2) << (int)id.data[14]
<< std::setw(2) << (int)id.data[15];

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

return s;
}

template<class CharT = char,
Expand Down

0 comments on commit f08b54b

Please sign in to comment.