How to get the next prefix in C++?
<p>Given a sequence (for example a string "Xa"), I want to get the next prefix in order lexicographic (i.e "Xb"). The next of "aZ" should be "b"</p>

<p>A motivating use case where this function is useful is described <a href="http://stackoverflow.com/questions/2689963/container-for-database-like-searches/2690246#2690246">here</a>.</p>

<p>As I don't want to reinvent the wheel, I'm wondering if there is any function in C++ STL or boost that can help to define this generic function easily?
If not, do you think that this function can be useful?</p>

<p>Notes </p>

<ul>
<li>Even if the examples are strings, the function should work for any Sequence. </li>
<li>The lexicographic order should be a template parameter of the function.</li>
</ul>

<p>From the answers I conclude that there is nothing on C++/Boost that can help to define this generic function easily and also that this function is too specific to be proposed for free. I will implement a generic next_prefix and after that I will request if you find it useful.</p>

<p>I have accepted the single answer that gives some hints on how to do that even if the proposed implementation is not generic.</p>
