Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
non-const-references [2015/01/07 21:30] – awf | non-const-references [2015/01/07 21:34] – awf | ||
---|---|---|---|
Line 45: | Line 45: | ||
If your function is more complex than inc, and you believe the code is more readable with the reference, just capture the argument locally. | If your function is more complex than inc, and you believe the code is more readable with the reference, just capture the argument locally. | ||
< | < | ||
- | | + | void set_first_element_to_one_if_has_at_least_one_elemet(std:: |
- | { | + | { |
- | | + | if (pv->size() == 0) return; |
- | | + | (*pv)[0] = 1; // Don't like this? |
- | const auto& v = vp; | + | auto& v = *pv; |
- | | + | v[0] = 1; // Look, much nicer |
- | + | } | |
- | | + | |
</ | </ |