Skip to content

Instantly share code, notes, and snippets.

@bwiklak
Created April 6, 2012 21:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwiklak/2323041 to your computer and use it in GitHub Desktop.
Save bwiklak/2323041 to your computer and use it in GitHub Desktop.
RLE encoding in C++
template< typename C >
string rle( const C& input )
{
stringstream out;
typedef C::const_iterator::value_type el_tyle;
pair<C::const_iterator,C::const_iterator> bounds;
bounds.second=input.begin();
while( (bounds.first=bounds.second)!=input.end() )
{
bounds.second=find_if(
bounds.first, input.end(),
bind1st(not_equal_to<el_tyle>(), *bounds.first)
);
out << distance(bounds.first,bounds.second) << *bounds.first;
}
return out.str();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment