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 https://github.com/Kistler-Group/sdbus-cpp/issues/513#issuecomment-3429733769
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>
This commit is contained in:
SimonBraunschmidtIBA
2025-10-23 21:08:25 +02:00
committed by GitHub
parent 7fbfcec455
commit 126ac9ffbe
2 changed files with 27 additions and 0 deletions

View File

@@ -151,6 +151,10 @@ namespace sdbus {
struct signature_of<_T&> : signature_of<_T>
{};
template <typename _T>
struct signature_of<_T&&> : signature_of<_T>
{};
template <>
struct signature_of<void>
{

View File

@@ -97,6 +97,29 @@ TEST(AVariant, CanBeCopied)
ASSERT_THAT(variantCopy2.get<std::string>(), Eq(value));
}
TEST(AVariant, CanBeMoved)
{
auto value = "hello"s;
sdbus::Variant variant(value);
auto movedVariant{std::move(variant)};
ASSERT_THAT(movedVariant.get<std::string>(), Eq(value));
ASSERT_TRUE(variant.isEmpty());
}
TEST(AVariant, CanBeMovedIntoAMap)
{
auto value = "hello"s;
sdbus::Variant variant(value);
std::map<std::string, sdbus::Variant> mymap;
mymap.try_emplace("payload", std::move(variant));
ASSERT_THAT(mymap["payload"].get<std::string>(), Eq(value));
ASSERT_TRUE(variant.isEmpty());
}
TEST(AVariant, IsNotEmptyWhenContainsAValue)
{
sdbus::Variant v("hello");