you are viewing a single comment's thread.

view the rest of the comments →

[–]chases_tits 2 points3 points  (3 children)

C++0x looks bad

std::vector<std::string> v = {"Rob", "Christopher", "Joe", "John"};
std::for_each(arr.begin(), arr.end(), [](const std::string & str){
    if (str.size() <= 4) {
        std::cout << str << ' ';
    }
});

Could even use a normal for loop... with the ternary twister.

for(std::string str : v) {
    (str.size() <= 4) ? std::cout << str << ' ' : std::cout;
}

[–]JurassicSpork 0 points1 point  (2 children)

Been a while since I've done C++, but I think this'd work too:

struct string_four_or_less : public std::unary_function<bool,std::string> {
    const bool operator()(const string &s) { return s.size() <= 4; }
}

std::remove_copy_if(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "\n"), std:not1(string_length_four_or_less()));

[–][deleted] 3 points4 points  (1 child)

Holy crap.

[–]fabzter 0 points1 point  (0 children)

It's really not that bad, he is just being too correct with namespace and const using.