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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:43:45+00:00 2026-05-24T04:43:45+00:00

I am using heavily BOOST_FOREACH for iteration over containers, and since I moved to

  • 0

I am using heavily BOOST_FOREACH for iteration over containers, and since I moved to c++0x recently, I thought I could replace BOOST_FOREACH with range-based for construct. The following piece of code

#include<vector>
#include<boost/shared_ptr.hpp>
#include<boost/range.hpp>
using std::vector; using boost::shared_ptr;
class Node;
int main(void){
   vector<shared_ptr<Node>> nodes;
   for(const shared_ptr<Node>& n: nodes);
}

does not compile with gcc 4.6, leading to

error: call of overloaded 'end(std::vector<boost::shared_ptr<Node> >&)' is ambiguous
note: candidates are:
/usr/include/c++/4.6/bits/range_access.h:78:5: note: decltype (__cont->end()) std::end(const _Container&) [with _Container = std::vector<boost::shared_ptr<Node> >, decltype (__cont->end()) = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Node>*, std::vector<boost::shared_ptr<Node> > >]
/usr/include/c++/4.6/bits/range_access.h:68:5: note: decltype (__cont->end()) std::end(_Container&) [with _Container = std::vector<boost::shared_ptr<Node> >, decltype (__cont->end()) = __gnu_cxx::__normal_iterator<boost::shared_ptr<Node>*, std::vector<boost::shared_ptr<Node> > >]
/usr/include/boost/range/end.hpp:103:47: note: typename boost::range_iterator<const T>::type boost::end(const T&) [with T = std::vector<boost::shared_ptr<Node> >, typename boost::range_iterator<const T>::type = __gnu_cxx::__normal_iterator<const boost::shared_ptr<Node>*, std::vector<boost::shared_ptr<Node> > >]
/usr/include/boost/range/end.hpp:92:41: note: typename boost::range_iterator<C>::type boost::end(T&) [with T = std::vector<boost::shared_ptr<Node> >, typename boost::range_iterator<C>::type = __gnu_cxx::__normal_iterator<boost::shared_ptr<Node>*, std::vector<boost::shared_ptr<Node> > >]

Is there a way to avoid such ambiguity, or is range-based for simply unusable in such situation?

  • 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-24T04:43:48+00:00Added an answer on May 24, 2026 at 4:43 am

    Tricky. You’re pulling in std::end and boost::end because the associated namespaces of std::vector<boost::shared_ptr> are both std and boost. Both are templates that match.

    However, a non-template end() would be an even better match. So, just provide your own:

    inline std::vector<boost::shared_ptr<Node> >::iterator
       end(std::vector<boost::shared_ptr<Node> > vsn&)
    {
      return std::end(vsn); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are heavily using VirtualBox on our developer workstations. Since we share the images
I am heavily using byte array to transfer objects, primitive data, over the network
I just recently begun using TFrames heavily (OK, yes, I've been living under a
I recently switched form ubuntu to MacOSX. I also recently started heavily using multi
Recently I saw a person heavily using var and default keywords for declaration of
I recently work on a project that heavily using collection filter function provided by
Our project is a VS2008 based project using Boost and Qt heavily. However, today
I'm using XML Serialization heavily in a web service (the contracts pass complex types
so I'm using LinQ2SQL quite heavily in my current application, and although I have
We have a thick client app using jQuery heavily and want to profile the

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.