Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 748575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:20:09+00:00 2026-05-14T14:20:09+00:00

Given a sequence (for example a string Xa), I want to get the next

  • 0

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”

A motivating use case where this function is useful is described here.

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?

Notes

  • Even if the examples are strings, the function should work for any Sequence.
  • The lexicographic order should be a template parameter of the function.

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.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:20:10+00:00Added an answer on May 14, 2026 at 2:20 pm

    I’m not sure I understand the semantics by which you wish the string to transform, but maybe something like the following can be a starting point for you. The code will increment the sequence, as if it was a sequence of digits representing a number.

    template<typename Bi, typename I>
    bool increment(Bi first, Bi last, I minval, I maxval)
    {
        if( last == first ) return false;
        while( --last != first && *last == maxval ) *last = minval;
        if( last == first && *last == maxval ) {
            *last = minval;
            return false;
        }
        ++*last;
        return true;
    }
    

    Maybe you wish to add an overload with a function object, or an overload or specialization for primitives. A couple of examples:

    string s1("aaz");
    increment(s1.begin(), s1.end(), 'a', 'z');
    cout << s1 << endl;     // aba
    
    string s2("95");
    do {
        cout << s2 << ' ';  // 95 96 97 98 99
    } while( increment(s2.begin(), s2.end(), '0', '9') );
    cout << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I wrote a post about this at http://www.shanison.com/2010/05/10/stop-the-browser-%E2%80%9Cthrobber-of-doom%E2%80%9D-while-loading-comet-forever-iframe/ Below are… May 14, 2026 at 7:10 pm
  • Editorial Team
    Editorial Team added an answer This is an issue apparently only coming up with 1.8-head… May 14, 2026 at 7:09 pm
  • Editorial Team
    Editorial Team added an answer Note that a more idiomatic approach within F# would probably… May 14, 2026 at 7:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.