Thread: Choice of std:: Container

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209

    Choice of std:: Container

    Hello all,

    I'm trying to pin down the kind of container I need to select, and if there isn't one that works, to determine what I need to write my own that isn't too slow. Here are the requirements :

    - Associative. I need it to work like a std::map in the way it can be used to return some value object based on a unique key object ( keys are unique in this scenario ).
    - Unordered. I don't want the container ordering my pairs based on their keys.
    - end() deletion, begin() insertion. I need to effectively be able to push() onto the end and pop() from the beginning - hence the unordered criterion above.

    I came across unordered_map from C++11, but it's still ordering the objects by key, even when I provide a hint, unless I'm doing it wrong :

    Code:
    unordered_map <int, int> umap;
    
    umap.insert(pair <int, int> (1, 123));
    umap.insert(pair <int, int> (3, 345));
    umap.insert(pair <int, int> (2, 234));
    When I iterate from begin() to end(), my output is
    Code:
    123
    234
    345
    I've also used
    Code:
    umap.insert(umap.end(), pair <int, int> (1, 123));
    as a hint, to no avail.

    Any suggestions would be hugely appreciated. Thank you !
    Last edited by Korhedron; 04-02-2012 at 09:04 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. multiple choice
    By iLike in forum C Programming
    Replies: 6
    Last Post: 10-30-2009, 03:53 PM
  2. Replies: 1
    Last Post: 01-23-2006, 07:12 PM
  3. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM
  4. Replies: 4
    Last Post: 03-21-2004, 03:34 PM
  5. Os of Choice
    By Fordy in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 09-26-2001, 08:27 AM