fix: make Variant conversion operator explicit (#428)

Having explicit conversion operator is a good practice according to the C++ core guidelines, as it makes the code safer and better follows the principle of least astonishment. Also, it is consistent with the standard library style, where wrappers like std::variant, std::any, std::optional... also do not provide an implicit conversion to the underlying type. Last but not least, it paves the way for the upcoming std::variant <-> sdbus::Variant implicit conversions without surprising behavior in some edge cases.
This commit is contained in:
Stanislav Angelovič
2024-04-24 20:20:29 +02:00
parent 42f0bd07c0
commit 32a97f214f
5 changed files with 9 additions and 8 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ namespace sdbus {
// Only allow conversion operator for true D-Bus type representations in C++
template <typename _ValueType, typename = std::enable_if_t<signature_of<_ValueType>::is_valid>>
operator _ValueType() const
explicit operator _ValueType() const
{
return get<_ValueType>();
}