QArrayDataPointer: add missing std::invoke call to projection

To ensure the correct invocation of the projection function, this patch
introduces the usage of std::invoke for all accesses to it. This
modification expands the coverage to include cases where the callable
object is a pointer to a member function.

Amends: 7ca633d9a82f90e5bba5e12ba923bfb0a257af63.

Change-Id: If666012d785ac74c8e856ea9be2a46b3307c8a06
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Dennis Oberst 2023-05-30 17:50:58 +02:00
parent 2d77051f9d
commit 8f0d2e2874

View File

@ -334,7 +334,7 @@ public:
const auto capacityBegin = begin() - offset; const auto capacityBegin = begin() - offset;
const auto prependBufferEnd = begin(); const auto prependBufferEnd = begin();
if constexpr (!std::is_nothrow_constructible_v<T, decltype(proj(*first))>) { if constexpr (!std::is_nothrow_constructible_v<T, decltype(std::invoke(proj, *first))>) {
// If construction can throw, and we have freeSpaceAtBegin(), // If construction can throw, and we have freeSpaceAtBegin(),
// it's easiest to just clear the container and start fresh. // it's easiest to just clear the container and start fresh.
// The alternative would be to keep track of two active, disjoint ranges. // The alternative would be to keep track of two active, disjoint ranges.
@ -366,7 +366,8 @@ public:
size = dst - begin(); size = dst - begin();
return; return;
} }
q20::construct_at(dst, proj(*first)); // construct element in prepend buffer // construct element in prepend buffer
q20::construct_at(dst, std::invoke(proj, *first));
++dst; ++dst;
++first; ++first;
} }
@ -383,12 +384,12 @@ public:
break; break;
} else { } else {
do { do {
(*this)->emplace(size, proj(*first)); (*this)->emplace(size, std::invoke(proj, *first));
} while (++first != last); } while (++first != last);
return; // size() is already correct (and dst invalidated)! return; // size() is already correct (and dst invalidated)!
} }
} }
*dst = proj(*first); // overwrite existing element *dst = std::invoke(proj, *first); // overwrite existing element
++dst; ++dst;
++first; ++first;
} }