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

The Archive Base Latest Questions

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

I wonder is it possible to have a map that would work like boost

  • 0

I wonder is it possible to have a map that would work like boost circular buffer. Meaning it would have limited size and when it would get to its limited size it will start overwriting first inserted elements. Also I want to be capable to search thru such buffer and find or create with [name]. Is It possible to create such thing and how to do 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-05-24T23:36:46+00:00Added an answer on May 24, 2026 at 11:36 pm

    Well, I don’t think that structure is present out of the box in boost (may exist elsewhere, though), so you should create it. I wouldn’t recommend using operator[](), though, at least as it is implemented in std::map, because this may make difficult to track elements added to the map (for exapmle, using operator[]() with a value adds that empty value to the map), and go for a more explicit get and put operations for adding and retrieving elements of the map.

    As for the easiest implementation, I would go for using an actual map as the storage, and a deque for the storage of the elements added (not tested):

    template <typename K, typename V>
    struct BoundedSpaceMap
    {
        typedef std::map<K,V> map_t;
        typedef std::deque<K> deque_t;
    
        // ...
        typedef value_type map_t::value_type;
        // Reuse map's iterators
        typedef iterator map_t::iterator;
    
        // ...
        iterator begin() { return map_.begin(); }
    
        // put
        void put ( K k, V v)
        { map_.insert(std::make_pair(k,v));
          deque_.push_back(k);
          _ensure();  // ensure the size of the map, and remove the last element
        }
    
         // ...
    
    private:
         map_t map_;
         deque_t deque_;
    
         void _ensure() { 
           if (deque_size() > LIMIT) { 
             map_.erase(deque_.front()); deque_.pop_front();
           }
         }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if this is possible in jaxb2. I have a xml that can
I wonder if this is possible with ant and java : I have a
I always wonder if it is possible to have a private class? And, what
After reading this question I started to wonder: is it possible to have a
I wonder if its possible to have a watermark on hotlinked images on an
I wonder if it possible to not have jython automagicaly transform java objects to
I wonder whether it is possible to have an ElementCollection of Embeddable inside another
I wonder how is it possible to manage transaction in c# code.. I have
I am new to Rails and I wonder if it is possible to have
I wonder if it's possible to have several input fields i the JOptionPane in

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.