Skip to content

Commit 5570fa5

Browse files
authored
1-tuple: fix copy assignment of tuple containing refs (#1812)
follow up on #1811
1 parent 656d47b commit 5570fa5

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

include/gridtools/common/tuple.hpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,6 @@ namespace gridtools {
235235

236236
tuple(tuple const &) = default;
237237
tuple(tuple &&) = default;
238-
tuple &operator=(tuple const &) = default;
239-
tuple &operator=(tuple &&) = default;
240238

241239
constexpr GT_FUNCTION tuple(T const &arg) noexcept : m_value(arg) {}
242240

@@ -260,6 +258,15 @@ namespace gridtools {
260258
swap(m_value, other.m_value);
261259
}
262260

261+
constexpr GT_FUNCTION tuple &operator=(tuple const &other) noexcept {
262+
m_value = other.m_value;
263+
return *this;
264+
}
265+
constexpr GT_FUNCTION tuple &operator=(tuple &&other) noexcept {
266+
m_value = std::move(other.m_value);
267+
return *this;
268+
}
269+
263270
template <class Arg, std::enable_if_t<std::is_assignable_v<T &, Arg const &>, int> = 0>
264271
constexpr GT_FUNCTION tuple &operator=(tuple<Arg> const &src) noexcept {
265272
m_value = src.m_value;

tests/unit_tests/common/test_tuple.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ namespace gridtools {
226226
EXPECT_EQ(1, get<0>(testee));
227227
}
228228

229+
TEST(onetuple, copy_assign_nested_ref) {
230+
int src_int = 1;
231+
int dst_int = 0;
232+
tuple<tuple<int &>> src = {{src_int}};
233+
tuple<tuple<int &>> testee = {{dst_int}};
234+
testee = src;
235+
EXPECT_EQ(1, get<0>(get<0>(testee)));
236+
}
237+
229238
TEST(tuple, move_assign) {
230239
tuple<move_only, move_only> testee;
231240
auto &res = testee = tuple<move_only, move_only>{move_only{47}, move_only{2}};

0 commit comments

Comments
 (0)