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

  • Home
  • SEARCH
  • 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 9274833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:26:43+00:00 2026-06-18T16:26:43+00:00

I’m using Visual Studio 2010. One feature I’d like to use, what has been

  • 0

I’m using Visual Studio 2010. One feature I’d like to use, what has been left out of VS2010, but is included in VS2012 is the range-based for-loop.

In VS2012 you can do neat and super-tidy for-loops like:

for( auto& it: myElements )
    it->something();

So far, the closest I could get in VS2010 is this syntax:

for( auto it = myElements.begin(), end = myElements.end(); it != end; it++ )
    it->something();

Upon reading some related questions, I found that using boost\foreach I have access to the following macro:

BOOST_FOREACH( auto it, myElements ){
    it.something();
}

My problem with this method is that it gives a copy (or something similar), not a pointer. Here is where I get confused. The foreach reference says the following:

It does no dynamic allocations, makes no virtual function calls or
calls through function pointers, and makes no calls that are not
transparent to the compiler’s optimizer.

What does it mean? Isn’t it a copy?

How can I get a pointer back from BOOST_FOREACH? Or should I use some other boost function?

I’ve seen this syntax in other questions here:

BOOST_FOREACH( auto& it, myElements ){
    it->something();
}

however this doesn’t compile for me and throws errors in the editor. What’s wrong with this? Why did I find it as a valid code on many other questions here?

Are there any nice and tidy solution in VS2010 for a range-based for-loop? (including using boost)

  • 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-18T16:26:44+00:00Added an answer on June 18, 2026 at 4:26 pm

    The main question is, do you have a container of pointers? Even in VS2012, for(auto& it: myElements) it->something(); only works on containers of (smart) pointers. The & tells you that it is a reference, and the -> tells you that it’s a pointer. That’s not a contradiction; you can have references to pointers.

    But why would you want a pointer anyway? A reference is far more idiomatic.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using JSon response to parse title,date content and thumbnail images and place
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.