This is a C++ version. There are a few pain points that annoyed me. I am becoming a C# programmer. Farewell C++. (Not really).
string input = "I inserted it I inserted it in myselfin myself";
int length = input.size();
int hLength = input.size()/2;
vector<string> subsequences(hLength);
int i = 0;
generate(subsequences.begin(), subsequences.end(),
[=, &i]() { return input.substr(i++, hLength); } );
i = 0;
auto found = find_if(subsequences.begin(), subsequences.end(),
[=, &i](string sub) -> bool {
string rhs = input.substr(0, i).append(input.substr(i + hLength, length - (i+hLength)));
i++;
return sub == rhs;
});
if(found != subsequences.end()){
cout << *found << endl;
}