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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:26:36+00:00 2026-06-02T13:26:36+00:00

i have this iterator loop, typedef boost::unordered_map<std::pair<int, int>, NavigationNode> NodesMap; NodesMap nodes; for (NodesMap::iterator

  • 0

i have this iterator loop,

typedef  boost::unordered_map<std::pair<int, int>, NavigationNode> NodesMap;
NodesMap nodes;
for (NodesMap::iterator it= nodes.begin(); it != nodes.end() ; ++it)
{

  if(it->second.type == NavigationNodeType_Walkable)
  {
    ConnectNode(&it->second);
  }

}

ConnectNode function seems to be invalidating the iterator. It pushes new elements inside the NavigationNode and modifies existing members of the NavigationNode.

i have two questions

  • Is passing it->second as pointer bad?
  • What’s the best way to iterate through this container?

thank you.

edit:

does accessing container’s elements like this

   nodes[intpair(x, y)]

inside ConnectNode function would cause this problem?

edit2
yes it does.

Why is that? and How would i get around it?

  • 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-02T13:26:37+00:00Added an answer on June 2, 2026 at 1:26 pm
    • Is passing it->second as pointer bad?

      It depends on what the function that takes the pointer itself does. Taken in isolation, there is nothing inherently wrong with passing a pointer.

    • What’s the best way to iterate through this container?

      The way that you are using is fine. Using begin() and end() to iterate is pretty standard.

    So I think the problem must be with the ConnectNode, and it is likely that you do not have an iterator invalidation problem, but something else.

    “does accessing container’s elements like this”

    nodes[intpair(x, y)]
    

    This will add a new entry to the map is one with key intpair(x,y) doesn’t exist, so yes, this could mess up the iteration. You can avoid this by checking if the element exists for that key before accessing with the [] operator.

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

Sidebar

Related Questions

I have this code: int main() { vector<int> res; res.push_back(1); vector<int>::iterator it = res.begin();
I have this loop for (it= someCollection.iterator; it.hasNext(); ) { //some code here }
I have 2 loops: //Loop 1 for ( vector<string>::iterator iter = vecv.begin() ; iter
I have this simple code public String toString() { **Iterator it = list.iterator();** String
I have this code: FVDTO.setStatus(fail); List<String[]> invalidFields = new ArrayList<String[]>(); Iterator<ConstraintViolation<HazardSubmission>> iterator = cv.iterator();
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
I have this loop which splits a Boolean LinkedList by 8 bits and return
I have this query: var iterator = criteria.binaryAssetBranchNodeIds.GetEnumerator(); iterator.MoveNext(); var binaryAssetStructures = from bas
I have a set of classes something like this: abstract class CollectionAbs implements Iterator
I have this loop running after a click(), and it does not return false

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.