mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-01 02:41:48 +00:00
[upstream_utils] StringMap: fix structured bindings with move-only types (#7127)
This commit is contained in:
@@ -159,7 +159,17 @@ decltype(auto) get(const StringMapEntry<ValueTy> &E) {
|
||||
if constexpr (Index == 0)
|
||||
return E.first();
|
||||
else
|
||||
return E.second;
|
||||
return (E.second);
|
||||
}
|
||||
|
||||
// Allow structured bindings on StringMapEntry.
|
||||
template <std::size_t Index, typename ValueTy>
|
||||
decltype(auto) get(StringMapEntry<ValueTy> &E) {
|
||||
static_assert(Index < 2);
|
||||
if constexpr (Index == 0)
|
||||
return E.first();
|
||||
else
|
||||
return (E.second);
|
||||
}
|
||||
|
||||
} // end namespace wpi
|
||||
|
||||
@@ -525,6 +525,16 @@ TEST_F(StringMapTest, StructuredBindings) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(StringMapTest, StructuredBindingsMoveOnly) {
|
||||
StringMap<MoveOnly> A;
|
||||
A.insert(std::make_pair("a", MoveOnly(42)));
|
||||
|
||||
for (auto &&[Key, Value] : A) {
|
||||
EXPECT_EQ("a", Key);
|
||||
EXPECT_EQ(42, Value.i);
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
// Simple class that counts how many moves and copy happens when growing a map
|
||||
struct CountCtorCopyAndMove {
|
||||
|
||||
Reference in New Issue
Block a user