Custom implementation of GNU grep in C++