In the following code which implements the Viterbi algorithm: (Wikipedia link)
std::pair<std::vector<index_t>, float> viterbi_get_optimal_path(const SoundGraph &g,
SequenceIter s_first,
SequenceIter s_last,
index_t curr_index) {
if (s_first == s_last) {
return {std::vector<index_t>({curr_index}), 1.0f};
}
std::vector<index_t> seq;
float prob = 0.0f;
for (const auto &[next_index, curr_sound] : g.edges(curr_index)) {
if (curr_sound.sound_ == *s_first) {
auto [res_seq, res_prob] =
viterbi_get_optimal_path(g, std::next(s_first), s_last, next_index);
if (res_prob > 0.0f && curr_sound.prob_ * res_prob > prob) {
prob = curr_sound.prob_ * res_prob;
std::swap(seq, res_seq);
seq.push_back(curr_index);
}
}
}
return {seq, prob};
}
Is the std::vector<index_t> copied or moved in this line?
auto [res_seq, res_prob] =
viterbi_get_optimal_path(g, std::next(s_first), s_last, next_index);
I'd like to believe it was moved but I'm not sure.
index_t is just std::ptrdiff_t