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());
어떻게 is_str_empty를 정의합니까? 나는 그것이 부스트를 공급한다고 생각하지 않는다.C++ is_str_empty 술어
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());
어떻게 is_str_empty를 정의합니까? 나는 그것이 부스트를 공급한다고 생각하지 않는다.C++ is_str_empty 술어
사용 mem_fun을/mem_fun_ref :
iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::mem_fun_ref(&std::wstring::empty));
문자열이 다음, 비어 있지 않은 경우 당신이 원하는 경우
나는 여전히 mem_fun_ref 솔루션을 더 좋아iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::not1(std::mem_fun_ref(&std::wstring::empty)));
순수한 STL이면 충분합니다.
#include <algorithm>
#include <functional>
...
iterator_t eventLine = std::find_if(lines.begin(), lines.end(),
std::bind2nd(std::not_equal_to<std::wstring>(), L""));
사용 부스트 : : 람다와 당신은 펑 사용할 수 있습니다 :: 밀어 바인딩 및 bind(&std::wstring::size, _1))
그러면 비어있는 문자열이 아닌 비어있는 문자열을 알 수 있습니다. –
그는 빈 문자열을 요구하지 않습니까? 그의 코드는 그렇게 제안합니다. – UncleZeiv
좋은 지적. 도! –
로 정의 : 당신이 부정을 원한다면, 당신이 가지고
가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
주 펑터 변경 :
struct is_str_not_empty {
bool operator() (const std::wstring& s) const { return !s.empty(); }
};
또는 Kenny ™에서 제안한대로 찾기를 사용하십시오.
,하지만이 작동합니다. +1. –