(core): simplify getAutoConnections() implementation
Description
IService::getAutoConnections()
uses IService::KeyConnectionsMap
class to declare auto connections. The current API of this class does not allow to use static const initializers, which would lead to a simpler code. See the proposal below.
Proposal
Here is the current usual way of declaring auto connections:
IService::KeyConnectionsMap getAutoConnections() const override
{
KeyConnectionsMap connections;
connections.push("data1", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT);
connections.push("data2", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT);
return connections;
}
We would like to propose a constructor with an initializer list so that we could write:
IService::KeyConnectionsMap getAutoConnections() const override
{
static const KeyConnectionsMap connections = {
{"data1", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT},
{"data2", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT}
};
return connections;
}
Or maybe even (but this would recreate the map at each call, right ?):
IService::KeyConnectionsMap getAutoConnections() const override
{
return {
{"data1", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT},
{"data2", data::Object::s_MODIFIED_SIG, s_UPDATE_SLOT}
};
}
Outcomes
A more modern approach, which would allow respecting the constness.