Skip to content

Commit 126ac9f

Browse files
SimonBraunschmidtIBAStanislav Angelovic
andauthored
fix: add signature_of specialization for r-value references (#515)
* test: add Variant move test * fix: provide signature_of<_T&&> Provide signature_of specialization for rvalue references resp. allow when forwarding references resolve to rvalue references signature_of<_T&&> is needed e.g. for std::map::try_emplace() when the emplaced sdbus:: type is passed as rvalue reference, otherwise the static_assert "Unsupported D-Bus type ..." would trigger See #513 (comment) for an elaborate explanation Signed-off-by: Simon Braunschmidt <simon.braunschmidt@iba-group.com> --------- Signed-off-by: Simon Braunschmidt <simon.braunschmidt@iba-group.com> Co-authored-by: Stanislav Angelovic <stanislav.angelovic.ext@siemens.com>
1 parent 7fbfcec commit 126ac9f

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

include/sdbus-c++/TypeTraits.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ namespace sdbus {
151151
struct signature_of<_T&> : signature_of<_T>
152152
{};
153153

154+
template <typename _T>
155+
struct signature_of<_T&&> : signature_of<_T>
156+
{};
157+
154158
template <>
155159
struct signature_of<void>
156160
{

tests/unittests/Types_test.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ TEST(AVariant, CanBeCopied)
9797
ASSERT_THAT(variantCopy2.get<std::string>(), Eq(value));
9898
}
9999

100+
TEST(AVariant, CanBeMoved)
101+
{
102+
auto value = "hello"s;
103+
sdbus::Variant variant(value);
104+
105+
auto movedVariant{std::move(variant)};
106+
107+
ASSERT_THAT(movedVariant.get<std::string>(), Eq(value));
108+
ASSERT_TRUE(variant.isEmpty());
109+
}
110+
111+
TEST(AVariant, CanBeMovedIntoAMap)
112+
{
113+
auto value = "hello"s;
114+
sdbus::Variant variant(value);
115+
116+
std::map<std::string, sdbus::Variant> mymap;
117+
mymap.try_emplace("payload", std::move(variant));
118+
119+
ASSERT_THAT(mymap["payload"].get<std::string>(), Eq(value));
120+
ASSERT_TRUE(variant.isEmpty());
121+
}
122+
100123
TEST(AVariant, IsNotEmptyWhenContainsAValue)
101124
{
102125
sdbus::Variant v("hello");

0 commit comments

Comments
 (0)