================
@@ -548,45 +580,52 @@ template <typename Instance> class PluginInstances {
// to the returned instances will not be reflected back to instances
// stored by the PluginInstances object.
std::vector<Instance> GetSnapshot() {
+ std::lock_guard<std::mutex> lock(m_mutex);
std::vector<Instance> enabled_instances;
- for (const auto &instance : m_instances) {
+ for (const Instance &instance : m_instances) {
if (instance.enabled)
enabled_instances.push_back(instance);
}
return enabled_instances;
}
- const Instance *GetInstanceAtIndex(uint32_t idx) {
+ // Return a field from the idx-th enabled instance, or default_val if none.
+ template <typename Ret, typename Callback>
+ Ret GetFieldAtIndex(uint32_t idx, Ret default_val, Callback callback) {
----------------
ashgti wrote:
Should we use `std::optional<Ret>` to make it more explicit that
`std::nullopt`?
At the call site, you can do `GetFieldAtIndex(idx,
callback).value_or(default_val)`, which pushes the default value handling to
the call site and better supports move only types.
https://github.com/llvm/llvm-project/pull/184452
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits