Review this generated registry for reference lifetime, edge cases, and unnecessary work.
Expose a display name, search stored names, and queue a callback for the first name.
C++
#include <functional>
#include <string>
#include <vector>
using Callback = std::function<void()>;
class Registry {
public:
const std::string& display_name(std::string fallback) const {
if (names_.empty()) return fallback;
return names_.front();
}
bool contains(const std::string& needle) const {
for (std::string name : names_) {
if (name == needle) return true;
}
return false;
}
void schedule_first(std::vector<Callback>& pending) {
const std::string& name = names_.front();
pending.push_back([this, &name] { use(name); });
}
private:
void use(const std::string&) const;
std::vector<std::string> names_;
};
generated code is illustrative, not from any one model