Skip to content

Commit

Permalink
Update ex10_13.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mooophy authored and pezy committed Jun 24, 2015
1 parent e51df91 commit da577f5
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions ch10/ex10_13.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! @Alan
//! @Yue Wang
//!
//! Exercise 10.13:
//! The library defines an algorithm named partition that takes a predicate
Expand All @@ -16,30 +16,18 @@
#include <vector>
#include <algorithm>

//! Predicate
inline
bool isLongerThan5(const std::string &s)
{
return s.size() >= 5;
bool predicate(const std::string &s)
{
return s.size() >= 5;
}

void partition_words(std::vector<std::string> &v)
int main()
{
auto iter_longerLast = std::partition(v.begin(), v.end(), isLongerThan5);

//! @note the range to be printed not whole of the v, so can't use for range.
for(auto it = v.begin(); it != iter_longerLast; ++it)
auto v = std::vector<std::string>{ "a", "as", "aasss", "aaaaassaa", "aaaaaabba", "aaa" };
auto pivot = std::partition(v.begin(), v.end(), predicate);
for (auto it = v.cbegin(); it != pivot; ++it)
std::cout << *it << " ";
std::cout << std::endl;
}

int main()
{
std::vector<std::string> v{"a","as","aasss","aaaaassaa","aaaaaabba","aaa"};
partition_words(v);

return 0;
}



0 comments on commit da577f5

Please sign in to comment.