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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:35:46+00:00 2026-06-07T08:35:46+00:00

I have a list like below typedef std::list<std::string> SegmentValue; then in a iteration I

  • 0

I have a list like below

typedef std::list<std::string> SegmentValue;

then in a iteration I need check if this is last iteration.

     for(Field::SegmentValue::const_iterator it = m_segmentValue.begin();It != 
           m_segmentValue.end();It++){
              if((segIt + 1) == m_segmentValue.end())//last iteration
              ...
        }

but I get error in compile that:

 error C2678: binary '+' : no operator found which takes a left-hand operand of type 'std::list<_Ty>::_Const_iterator<_Secure_validation>'

how I can check if this is last itration?

  • 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-06-07T08:35:48+00:00Added an answer on June 7, 2026 at 8:35 am

    You can’t use binary + and - operators with std::list iterators. std::list iterators are bidirectional iterators, but they are not random access iterators, meaning that you can’t shift them by an arbitrary constant value.

    Use unary ++ and -- instead

    Field::SegmentValue::const_iterator it_last = m_segmentValue.end();
    --it_last;
    

    Now it_last is the last element iterator. Just make sure it remains valid. If you are not making any iterator-invalidating modifications to your container, you can pre-compute it_last and use it in the cycle. Otherwise, you’ll have to re-compute it as necessary.

    In fact, in generic algorithms it is always a good idea to prefer using -- and ++ with iterators whenever possible (instead of binary + 1 and - 1), since it reduces your algorithm’s requirements: binary + and - require random access iterators, while ++ and -- work with bidirectional ones.

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

Sidebar

Related Questions

I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
I have a list which contains some strings like below: List<String> l = new
I have string containing a list of name like below: John asked Kim, Kelly,
I have method to get list of bean properities like below. How to check
I have a standard list view setup with backbone that looks something like below.
I have a list of items like how its listed below, and I'm trying
I have a panel whose items are a list and a panel like below
I have a list like this: <ul> <li> <span>USA:</span> Newyork <span>USA:</span> Dallas </li> <li>
I have a list like this: <select name=select_list_name id=list_id> <option value=>Select Option</option> <option value=value1>Option
I have a list box like below. <ListBox x:Name=CouponListBox ItemsSource={Binding Item} SelectionChanged=CouponListBox_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>

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.