std::vector<std::wstring> lines;
typedef std::vector<std::wstring>::iterator iterator_t;
iterator_t eventLine = std::find_if(lines.begin(), lines.end(), !is_str_empty());
how do I define is_str_empty? i don't believe boost supplies it.
std::vector<std::wstring> lines;
typedef std::vector<std::wstring>::iterator iterator_t;
iterator_t eventLine = std::find_if(lines.begin(), lines.end(), !is_str_empty());
how do I define is_str_empty? i don't believe boost supplies it.
Pure STL is enough.
#include <algorithm>
#include <functional>
...
iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::bind2nd(std::not_equal_to<std::wstring>(), L""));
Use boost::lambda and boost::bind and define it as bind(&std::wstring::size, _1))
You can use a functor:
struct is_str_empty {
bool operator() (const std::wstring& s) const { return s.empty(); }
};
std::find_if(lines.begin(), lines.end(), is_str_empty()); // NOTE: is_str_empty() instantiates the object using default constructor
Note that if you want a negation, you have to change the functor:
struct is_str_not_empty {
bool operator() (const std::wstring& s) const { return !s.empty(); }
};
Or just use find as suggested by KennyTM.
Use mem_fun / mem_fun_ref:
iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::mem_fun_ref(&std::wstring::empty));
If you want when the string is NOT empty, then:
iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::not1(std::mem_fun_ref(&std::wstring::empty)));