Wiki

Clone wiki

kick / map

The Skinny

A map is an associative container. Items are represented by key and value pairs. By default, map uses array_allocator<T> (same as vector) for memory management.

Container Features

  • Associative - Items are accessed by their unique keys
  • Dynamic - Items can be added/removed dynamically
  • Allocation - Any map can use custom allocators based on performance needs

Template Parameters

  • K - The object type for key
  • V - The object type for value
  • A - The allocator type for managing memory

Basic Usage

#include <iostream>

#include <kick/string.h>
#include <kick/map.h>

int main( int argc, const char* argv[] ){
    kick::map<kick::string, int> myMap; 

    // Adding items using insert
    myMap.insert( kick::pair<kick::string, int>( "one", 100 ) ); 
    myMap.insert( kick::pair<kick::string, int>( "two", 200 ) ); 

    // Adding items using the subscript operator
    myMap.["three"] = 300; 
    myMap.["four"]  = 400; 

    // Access individual items, outputs 100
    std::cout << myMap["one"] << std::endl; 

    // Iterate through all items in the map
    for( kick::map<kick::string, int>::iterator it = myMap.begin(); it != myMap.end() ++it )
        std::cout << (*it).key() << " = " << (*it).val() << std::endl; 


}

Updated