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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:25:48+00:00 2026-06-10T03:25:48+00:00

Did you ever went through the process of replacing the BOOST_FOREACH by the range-based

  • 0

Did you ever went through the process of replacing the BOOST_FOREACH by the range-based for loop? Are there any gotchas when doing it mechanically (i.e. not doing a deep study of the code around).

Background: I do have sources with about 250K lines, compiled with Microsoft VC++ 10 (Visual Studio 2010). The code uses also BOOST_FOREACH from the boost library. I am just trying the VC++ 11 (Visual Studio 2012 RC) that implements also the range-based for loop with the auto.

So far, I have met the situation where the element was declared outside the BOOST_FOREACH (no declaration in the parentheses):

BOOST_FOREACH (element, container) {
    ...
}

… and the element was expected to have the value set in the loop after the break. Can you remember similar problems?

When the BOOST_FOREACH contains the declaration, would you choose to replace the explicit type by auto? Is there any advantage to do so when one just mechanically rewrites the BOOST_FOREACH instead of leaving the explicit declaration there?

Thanks for your help,
Petr

  • 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-10T03:25:49+00:00Added an answer on June 10, 2026 at 3:25 am

    The advantage of auto over using the actual type or reference type is that the code will continue to work if the container type changes. This may not be what you want if you’re intentionally performing a type conversion on the result of indirecting the container iterator.

    Example:

    std::vector<int> v;
    for (int i: v) ...
    

    If v changes to std::vector<long> or std::vector<unsigned> then the type conversion may be unwanted; still, a compiler warning should catch this (especially for a narrowing conversion). On the other hand, you could have code where a (widening) conversion is intended:

    std::vector<char> v;
    for (int i: v) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did anybody ever installed wkhtmltopdf on Fedora 14? On http://code.google.com/p/wkhtmltopdf/wiki/compilation there is a step
Did you ever have the following situation: you need to store information, but a
Why did programmers ever start using status codes? I mean, I guess I could
Did you ever used EF4 and Velocity(or other caching framework) together? I found this
Did anybody ever used the new Spring3 with JSF2 and portlets (JSR286) ? I
Did anyone ever manage to create forms within the grid? Attempt (which does not
Does (or did) Twitter ever have a method in their API that allowed client-side
Did you ever have a day when nothing works? Now I can't even succeed
Did you ever make a rounding like that: [0.95,1) rounds to 1 [0.90,0.95) rounds
Did anyone ever try to create a jQuery LightBox-Like Popup (WPF UserControl) for displaying

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.