Skip to content

Commit

Permalink
improved formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pezy committed Feb 4, 2015
1 parent 31c2eed commit e087ecf
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions ch13/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,33 +228,34 @@ In this case, `swap` function is special. It will be clear two `Message`'s folde
## Exercise 13.39 [hpp](ex13_39.h) | [cpp](ex13_39.cpp)
## Exercise 13.40 [hpp](ex13_40.h) | [cpp](ex13_40.cpp)
## Exercise 13.41: Why did we use postfix increment in the call to construct inside push_back? What would happen if it used the prefix increment?
```cpp
|a|b|c|d|f|..............|
^ ^ ^
elements first_free cap
// if use alloc.construct(first_free++, "g");
|a|b|c|d|f|g|.............|
^ ^ ^
elements first_free cap
// if use alloc.construct(++first_free, "g");
|a|b|c|d|f|.|g|............|
^ ^ ^ ^
elements | first_free cap
|
"unconstructed"
```

## Exercise 13.42: Test your StrVec class by using it in place of the vector<string> in your TextQuery and QueryResult classes (12.3, p. 484).
## Exercise 13.41:
>Why did we use postfix increment in the call to construct inside push_back? What would happen if it used the prefix increment?
|a|b|c|d|f|..............|
^ ^ ^
elements first_free cap
// if use alloc.construct(first_free++, "g");
|a|b|c|d|f|g|.............|
^ ^ ^
elements first_free cap
// if use alloc.construct(++first_free, "g");
|a|b|c|d|f|.|g|............|
^ ^ ^ ^
elements | first_free cap
|
"unconstructed"
## Exercise 13.42:
>Test your StrVec class by using it in place of the vector<string> in your TextQuery and QueryResult classes (12.3, p. 484).
- StrVec : [hpp](ex13_42_StrVec.h) | [cpp](ex13_42_StrVec.cpp)
- TextQuery and QueryResult : [hpp](ex13_42_TextQuery.h) | [cpp](ex13_42_TextQuery.cpp)
- Text : [ex13_42.cpp](ex13_42.cpp)
## Exercise 13.43: Rewrite the free member to use `for_each` and a lambda (10.3.2, p. 388) in place of the for loop to destroy the elements. Which implementation do you prefer, and why?
## Exercise 13.43:
>Rewrite the free member to use `for_each` and a lambda (10.3.2, p. 388) in place of the for loop to destroy the elements. Which implementation do you prefer, and why?
**Rewrite**
```cpp
Expand All @@ -264,4 +265,4 @@ for_each(elements, first_free, [this](std::string &rhs){ alloc.destroy(&rhs); })
@Mooophy:
The new version is better. Compared to the old one, it doesn't need to worry about the order and decrement.So more straightforward and handy. The only thing to do for using this approach is to add "&" to build the pointers to string pointers.

## Exercise 13.44 [hpp](ex13_44.h) | [cpp](ex13_44.cpp) | [Test](ex13_44_TEST.cpp)
## Exercise 13.44 [hpp](ex13_44.h) | [cpp](ex13_44.cpp) | [Test](ex13_44_TEST.cpp)

0 comments on commit e087ecf

Please sign in to comment.