Skip to content

Commit

Permalink
fixed transform version to in-place
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Apr 12, 2014
1 parent a95e2c4 commit aebc51d
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions from_goto_to_std-transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,13 @@ Many people stop here, but we can do better in terms of readability ease.
OK, how can we express more clearly without explicit comments what our code does, i.e. make it self explaining?

```c++
vector<int> squareVec6(const vector<int>& v)
vector<int> squareVec5(vector<int> v)
{
vector<int> result;
result.reserve(v.size());
transform(begin(v), end(v), back_inserter(result), [](int i)
transform(begin(v), end(v), begin(v), [](int i)
{
return i*i;
});
return result;
return v;
}
```
`std::transform` tells the reader at one glance that all `v.size()` elements of `v` will be transformed into something else.
Expand Down

0 comments on commit aebc51d

Please sign in to comment.