Skip to content

Commit

Permalink
Clarify auto type for MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
mabraham committed Sep 5, 2024
1 parent b48a0e9 commit 35dddf8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/gromacs/hardware/tests/device_management.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,38 @@ std::string uuidToString(const std::array<std::byte, 16>& uuid)
// xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, where every x represents 4 bits
std::string result;
result.reserve(37);
const auto* uuidIt = uuid.cbegin();
#ifdef _MSVC
// Somehow MSVC won't cast from the return type of cbegin():
//
// error C2440: 'static_cast': cannot convert from 'std::_Array_const_iterator<_Ty,16>'
// to 'const unsigned int *' with [ _Ty=std::byte ]
const auto *uuidIt = static_cast<const unsigned int*>(&uuid[0]);
#else
const auto* uuidIt = static_cast<const unsigned int*>(uuid.cbegin());
#endif
for (int i = 0; i < 4; ++i, ++uuidIt)
{
result += gmx::formatString("%2.2x", static_cast<unsigned int>(*uuidIt));
result += gmx::formatString("%2.2x", *uuidIt);
}
result.append(1, '-');
for (int i = 0; i < 2; ++i, ++uuidIt)
{
result += gmx::formatString("%2.2x", static_cast<unsigned int>(*uuidIt));
result += gmx::formatString("%2.2x", *uuidIt);
}
result.append(1, '-');
for (int i = 0; i < 2; ++i, ++uuidIt)
{
result += gmx::formatString("%2.2x", static_cast<unsigned int>(*uuidIt));
result += gmx::formatString("%2.2x", *uuidIt);
}
result.append(1, '-');
for (int i = 0; i < 2; ++i, ++uuidIt)
{
result += gmx::formatString("%2.2x", static_cast<unsigned int>(*uuidIt));
result += gmx::formatString("%2.2x", *uuidIt);
}
result.append(1, '-');
for (int i = 0; i < 6; ++i, ++uuidIt)
{
result += gmx::formatString("%2.2x", static_cast<unsigned int>(*uuidIt));
result += gmx::formatString("%2.2x", *uuidIt);
}
return result;
}
Expand Down

0 comments on commit 35dddf8

Please sign in to comment.