Is there any way to limit the size of an STL Map?
        Posted  
        
            by Nathan Fellman
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nathan Fellman
        
        
        
        Published on 2010-04-26T07:26:16Z
        Indexed on 
            2010/04/26
            7:33 UTC
        
        
        Read the original article
        Hit count: 391
        
I want to implement some sort of lookup table in C++ that will act as a cache. It is meant to emulate a piece of hardware I'm simulating.
The keys are non-integer, so I'm guessing a hash is in order. I have no intention of inventing the wheel so I intend to use stl::map for this (though suggestions for alternatives are welcome).
The question is, is there any way to limit the size of the hash to emulate the fact that my hardware is of finite size? I'd expect the hash's insert method to return an error message or throw an exception if the limit is reached.
If there is no such way, I'll simply check its size before trying to insert, but that seems like an inelegant way to do it.
© Stack Overflow or respective owner