Skip to content

Commit

Permalink
Add an overload of to_chars taking Ch(&)[N]
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed May 4, 2024
1 parent 8414713 commit 0967b94
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions include/boost/uuid/uuid_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/detail/to_chars.hpp>
#include <boost/uuid/detail/static_assert.hpp>
#include <iosfwd>
#include <istream>
#include <locale>
#include <algorithm>
#include <string>
#include <cstddef>

#if defined(_MSC_VER)
#pragma warning(push) // Save warning settings.
Expand Down Expand Up @@ -45,13 +47,31 @@ inline bool to_chars( uuid const& u, Ch* first, Ch* last ) noexcept
return true;
}

template<class Ch, std::size_t N>
inline Ch* to_chars( uuid const& u, Ch (&buffer)[ N ] ) noexcept
{
BOOST_UUID_STATIC_ASSERT( N >= 37 );

detail::to_chars( u, buffer + 0 );
buffer[ 36 ] = 0;

return buffer + 36;
}

// only provided for compatibility; deprecated
inline char* to_chars( uuid const& u, char (&buffer)[ 36 ] ) noexcept
{
detail::to_chars( u, buffer + 0 );
return buffer + 36;
}

// operator<<

template<class Ch, class Traits>
std::basic_ostream<Ch, Traits>& operator<<( std::basic_ostream<Ch, Traits>& os, uuid const& u )
{
char tmp[ 37 ] = {};
detail::to_chars( u, tmp );
char tmp[ 37 ];
to_chars( u, tmp );

os << tmp;
return os;
Expand Down

0 comments on commit 0967b94

Please sign in to comment.