boost.tokenizer는 많은 멋진 것들을 할 수 있지만 실제로는 불가능합니다. 대답은 실제로 "아니오"입니다.
#include <iostream>
#include <string>
#include <boost/range/adaptor/uniqued.hpp>
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace boost;
using namespace boost::adaptors;
int main()
{
std::string text = "token, test string test, test test";
char_separator<char> sep(", ");
tokenizer< char_separator<char> > tokens(text, sep);
BOOST_FOREACH (const std::string& t, tokens | uniqued) {
std::cout << t << "." << '\n';
}
}
이 인쇄 :
token.
test.
string.
test.
세계적 만에 어떤 행동을하기 위해
만 인접한 중복을 삭제하고자하는 경우
, Boost.Range에게 그것이 seemless 내릴 수 있습니다 고유 한 토큰을 사용하면 상태를 저장할 필요가 있습니다. 가장 간단한 해결책은 중간 집합 일 것입니다 :
char_separator<char> sep(", ");
tokenizer< char_separator<char> > tokens(text, sep);
std::set<std::string> unique_tokens(tokens.begin(), tokens.end());
BOOST_FOREACH (const std::string& t, unique_tokens) {
std::cout << t << "." << '\n';
}
'std :: unique'는 정렬 된 범위에서만 작동합니다. 입력 내용은 항상 정렬되어 있습니까? (그렇지 않다면 모든 중복을 필터링하거나 서로 인접한 요소를 필터링하는 데 관심이 있습니까?) – Mankarse
저는 tokenizer가 이전 토큰을 추적하지 않으므로 응답이 없다고 확신합니다. 현재의 토큰이 새로운 토큰인지 또는 이전의 토큰을 복제하는지 알기 위해. –
@Mankarse : 맞아, boost :: split case에서 만든 std :: sort에 대한 추가 호출이있다. – tt293