Skip to content

Commit

Permalink
Workaround for NVIDIA C++ compiler being unable to parse variadic exp…
Browse files Browse the repository at this point in the history
…ansions in range of range-based for loop

Fixes: abseil#1629
PiperOrigin-RevId: 611131201
Change-Id: I787731e00207b544ee16055e6e0d323a5094a433
  • Loading branch information
Abseil Team authored and netkex committed Apr 3, 2024
1 parent 50b88d6 commit 288ce8d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions absl/strings/str_cat.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,18 +606,17 @@ StrAppend(absl::Nonnull<String*> str, T... args) {
ptrdiff_t n; // The length of the current argument
typename String::pointer pos = &(*str)[old_size];
using SomeTrivialEmptyType = std::false_type;
// Ugly code due to the lack of C++14 fold expression makes us.
const SomeTrivialEmptyType dummy1;
for (const SomeTrivialEmptyType& dummy2 :
{(/* Comma expressions are poor man's C++17 fold expression for C++14 */
(void)(n = lengths[i]),
(void)(n < 0 ? (void)(*pos++ = '-'), (n = ~n) : 0),
(void)absl::numbers_internal::FastIntToBufferBackward(
absl::numbers_internal::UnsignedAbsoluteValue(std::move(args)),
pos += n, static_cast<uint32_t>(n)),
(void)++i, dummy1)...}) {
(void)dummy2; // Remove & migrate to fold expressions in C++17
}
const SomeTrivialEmptyType dummy;
// Ugly code due to the lack of C++17 fold expressions
const SomeTrivialEmptyType dummies[] = {
(/* Comma expressions are poor man's C++17 fold expression for C++14 */
(void)(n = lengths[i]),
(void)(n < 0 ? (void)(*pos++ = '-'), (n = ~n) : 0),
(void)absl::numbers_internal::FastIntToBufferBackward(
absl::numbers_internal::UnsignedAbsoluteValue(std::move(args)),
pos += n, static_cast<uint32_t>(n)),
(void)++i, dummy)...};
(void)dummies; // Remove & migrate to fold expressions in C++17
}

// Helper function for the future StrCat default floating-point format, %.6g
Expand Down

0 comments on commit 288ce8d

Please sign in to comment.