How to avoid empty tokens when sharing with boost :: iter_split?

I have code that breaks a string into tokens using boost:

boost::algorithm::iter_split( result_vector, input, boost::algorithm::first_finder(delimiter)); 

What is the best and most elegant way to change this so that there are no empty tokens in the results?

For example, my input might be:

 foo.bar.baz. 

where . - delimiter.

+1
source share
1 answer

Just use remove_if for your resulting vector with a lambda function that checks the string.

 auto newEndIt = std::remove_if(result_vector.begin(), result_vector.end(), [&](const std::string& it)->bool { return it.empty(); }); 

Then just resize the vector

 result_vector.resize(newEndIt - result_vector.begin()); 
+2
source

Source: https://habr.com/ru/post/953821/


All Articles