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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:38:22+00:00 2026-06-02T15:38:22+00:00

Here’s the code I’m running, with g++ 4.6 and -std=c++0x std::unordered_map<int, int> um; um.insert(std::make_pair(42,

  • 0

Here’s the code I’m running, with g++ 4.6 and -std=c++0x

std::unordered_map<int, int> um;

um.insert(std::make_pair(42, 43));
um.insert(std::make_pair(342, 343));
um.insert(std::make_pair(142, 143));
um.insert(std::make_pair(242, 243));

for(auto e : um)
std::cout << e.first << std::endl;

This prints:

242
342
42
142

Now I can access 242 with um.begin()->first or um.begin(0)->first. 342 can be accessed using um.begin(1)->first. But um.begin(2)->first or um.begin(3)->first make the program crash. With different numbers I was able to access um.begin(2)->first.
I cannot explain that behavior to myself. Do I use um.begin(int) wrong?

  • 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-02T15:38:23+00:00Added an answer on June 2, 2026 at 3:38 pm

    You got this very confused. begin(1) is a very special construction only for the unordered containers that accesses a specific bucket in the underlying hash table structure and returns a local iterator. That has nothing to do with accessing any specific element in a sort of “random access” way, which you simply cannot do.

    All you can do with an unordered container is iterate over the entire collection or find a specific element by key. The elements are not accessible in any particular order, whence the name “unordered”.

    You can use the local iterators to iterate over each bucket [begin(n), end(n)), but of course you have to use the same idioms that you use for any range to deal with empty containers. The total number of buckets available can be discovered with the bucket_count member function.

    Note that in most situations you should expect a bucket to contain either zero or one elements. The average number of elements per bucket is available (and configurable) via the load_factor member function.

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

Sidebar

Related Questions

here's my code private void make_Book(int x, int y, string name) { #region Creating
Here's what I want to do: Given a table PeopleOutfit (id int primary key,
Here is some simple code: DIR* pd = opendir(xxxx); struct dirent *cur; while (cur
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
Here is an example: I write html code inside of textarea, then I swap
here is my configuration: http://domain.com (obviously fictitious name...) hosted on a server running Apache
Here's an example query: DECLARE @table table (loc varchar(10)) INSERT INTO @table VALUES ('134a'),
Here is my code, which takes two version identifiers in the form 1, 5,
Here is my code...I have two dimensional matrices A,B. I want to develop the
Here is my code sample, let me know if it can be further improved?

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.