Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/rime/candidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,29 @@ class Candidate {
void set_end(size_t end) { end_ = end; }
void set_quality(double quality) { quality_ = quality; }

// per-candidate data
void set_data(const string& data_tag, an<void> datum = nullptr) {
Copy link

Copilot AI Oct 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using void-erased pointers for arbitrary data is unsafe and forces consumers to manage casting/lifetimes. If feasible for the codebase standard, consider std::any (or an existing project-wide any/variant) for type-safe storage while still allowing arbitrary data.

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is safer but is not naturally nullable, and optional<any> seems to have too many overheads.

data_[data_tag] = datum;
}
an<void> get_data(const string& data_tag) const {
auto it = data_.find(data_tag);
return it != data_.end() ? it->second : nullptr;
}
vector<string> get_data_keys() const {
vector<string> keys;
keys.reserve(data_.size());
for (const auto& pair : data_) {
keys.push_back(pair.first);
}
return keys;
}

private:
string type_;
size_t start_ = 0;
size_t end_ = 0;
double quality_ = 0.;
hash_map<string, an<void>> data_;
};

using CandidateQueue = list<of<Candidate>>;
Expand Down
Loading