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 3429482
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:05:13+00:00 2026-05-18T07:05:13+00:00

I am looking for a readable, elegant way to do the following in C++,

  • 0

I am looking for a readable, elegant way to do the following in C++, here shown in Python:

for datum in data[1:]:
    # do work.

The iterators on the data in question may not support random access iterators, so I can’t just use:

for (mIter = data.begin() + 1; mIter != data.end(); mIter++)

The best I’ve come up with is the following:

iterable::iterator mIter = data.begin();
for (mIter++;  mIter != allMjds.end(); mjdIter++) {
    // do work.
}

It’s not too lengthy, but it’s hardly expository – at first glance it actually looks like a mistake!

Another solution is to have an "nth element" helper function, I guess. Is there a more concise way?

  • 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-18T07:05:13+00:00Added an answer on May 18, 2026 at 7:05 am

    You can use std::next(iter, n) for a linear-time advance. You can also use the standard std::advance algorithm, though it isn’t as simple to use (it takes the iterator by a non-const reference and doesn’t return it).

    For example,

    for (mIter = std::next(data.begin()); mIter != data.end(); ++mIter)
    

    or,

    mIter = data.begin();
    std::advance(mIter, 1);
    for (; mIter != data.end(); ++mIter)
    

    Note that you must make sure that data.size() >= 1, otherwise the code will fail in a catastrophic manner.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a method to parse readable (i.e., not binary) data files
I'm not used to doing things the python way yet, but I'm almost certain
I am looking a smart and easily readable way to get the id of
Who has the most readable and useful function/class commenting convention? I'm not looking for
I am looking for best practices on externalizing simple data structures into human readable
Looking to move data from a table A to history table B every X
Looking at adding some data graphing to a new iPhone app in development (ala
I am trying not to re-invent the wheel, and thus I am looking for
I hope I can make this question clear enough. I'm looking to put a
Is there a way to automatically grab the rules, in their original, human readable

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.