Skip to content

Commit

Permalink
Merge pull request #56 from sketchylizard/FixTemplateParameters
Browse files Browse the repository at this point in the history
Forward declare to_string function
  • Loading branch information
mariusbancila authored Jan 14, 2022
2 parents 1da3294 + c4728ee commit 66a4ade
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions include/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ namespace uuids
name_based_sha1 = 5 // The name-based version specified in RFS 4122 with SHA1 hashing
};

// Forward declare uuid & to_string so that we can declare to_string as a friend later.
class uuid;
template <class CharT = char,
class Traits = std::char_traits<CharT>,
class Allocator = std::allocator<CharT>>
std::basic_string<CharT, Traits, Allocator> to_string(uuid const &id);

// --------------------------------------------------------------------------------------------------------------------------
// uuid class
// --------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -550,9 +557,9 @@ namespace uuids
return lhs.data < rhs.data;
}

template<class CharT = char,
class Traits = std::char_traits<CharT>,
class Allocator = std::allocator<CharT>>
template <class CharT,
class Traits,
class Allocator>
inline std::basic_string<CharT, Traits, Allocator> to_string(uuid const & id)
{
std::basic_string<CharT, Traits, Allocator> uustr{detail::empty_guid<CharT>};
Expand Down Expand Up @@ -920,7 +927,7 @@ namespace std
static_cast<uint64_t>(uuid.data[14]) << 8 |
static_cast<uint64_t>(uuid.data[15]);

if (sizeof(result_type) > 4)
if constexpr (sizeof(result_type) > 4)
{
return result_type(l ^ h);
}
Expand Down

0 comments on commit 66a4ade

Please sign in to comment.