mirror of
https://github.com/Kistler-Group/sdbus-cpp.git
synced 2026-01-25 15:12:20 +01:00
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:
committed by
GitHub
parent
7fbfcec455
commit
126ac9ffbe
@@ -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>
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user