c++ - Passing a const reference of std::pair to a function -
i wrote following. however, i'm confused managed compile. did, have questions...
void tree_walk(const std::pair<tree, node> &tree_root) { tree t = tree_root.first; node current = tree_root.second; // code walks tree, updating current go along. }
i'm wondering if calling tree.first copies tree? semantics of passing std::pair reference?
tree_rooting.first
not copy anything, but
tree t = tree_root.first;
does. if not want copy tree, can do
const tree &t = tree_root.first;
to answer second question: correctly passed pair
function const
reference. if want modify input, leave out const
in functions signature pass non-const
reference.