Use optional instead of unique_ptr
In this context, unique_ptr<interface_t> was used to keep a
to-b-initialized-later member variable. In modern c++, std::optional is
a better fit for this, and a drop in replacement.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I4cfb53e13b6ffa73a48940b56db46de64dbd0bb2
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index c8f8de2..82c3315 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -733,10 +733,10 @@
initialized_ = true;
vtable_.emplace_back(vtable::end());
- interface_ = std::make_unique<sdbusplus::server::interface_t>(
- static_cast<sdbusplus::bus_t&>(*conn_), path_.c_str(),
- name_.c_str(), static_cast<const sd_bus_vtable*>(&vtable_[0]),
- this);
+ interface_.emplace(static_cast<sdbusplus::bus_t&>(*conn_),
+ path_.c_str(), name_.c_str(),
+ static_cast<const sd_bus_vtable*>(&vtable_[0]),
+ this);
conn_->emit_interfaces_added(path_.c_str(),
std::vector<std::string>{name_});
if (!skipPropertyChangedSignal)
@@ -786,7 +786,7 @@
callbacksSet_;
std::unordered_map<std::string, std::unique_ptr<callback>> callbacksMethod_;
std::vector<sd_bus_vtable> vtable_;
- std::unique_ptr<sdbusplus::server::interface_t> interface_;
+ std::optional<sdbusplus::server::interface_t> interface_;
bool initialized_ = false;
};