C++14-ish code for creating q-grams of a string
Things I like:


(Mostly) a pretty neatly packaged, self-contained component.
Written primarily to emphasize simplicity


and let the compiler deal with making it fast



Things I don't like so well:


Q, PREFIX3, and SUFFIX3 are apparently globals (or maybe class variables?) so I can't see what they really are.
Subtle interaction: PREFIX3 and SUFFIX3 both (seem to) implicitly assume that Q = 3.
qword has a well-known meaning in Intel assembly language. Unless you're sure this will only be used by an audience that immediately knows what you intend, another name might be better.
Written non-generically, for no particularly good reason.
It almost seems like qwordify is really two separate things shoved together: a generic "generate all the results in a sliding window", and a specialized "generate all the qwords from a string".
If you can use the new string_view, it would be a good choice here.


Ignoring point 6 (since it's not really C++14), we could end up with code on this order:

// the generic algorithm:
template &lt;class InIt, class OutIt, class size_type&gt;
void window(InIt b, InIt e, OutIt d, size_type len) {
    for (auto s = std::next(b, len); s != e; ++s, ++b, ++d)
        *d = { b, s };
}

// The piece specifically for q-grams
std::vector&lt;std::string&gt; generate_qgram(std::string const &amp;in, size_t q) {
    std::string input = std::string(q-1, '^') + in + std::string(q, '$');

    std::vector&lt;std::string&gt; words;

    window(input.begin(), input.end(), std::back_inserter(words), q);
    return words;
}

// and a little demo code:
int main() {
    auto ret = generate_qgram("INDEX", 3);

    std::copy(ret.begin(), ret.end(), std::ostream_iterator&lt;std::string&gt;(std::cout, "\n"));
}