Python's dict class in C++
ANDREWVOSS (187)

Dictionary

A recreation of Python's dict class in C++

Usage

The class dict is a template:

template<key_type, val_type>
class dict

Usage is similar to Python:

dict<string,string> d;
d["foo"] = "bar";

Methods

val_type pop(key_type key)

Remove an item from from the dict and return its value


std::vector<std::pair<key_type, val_type>> items()

Return a vector containing every key-value pair in the dict


void clear()

Remove all key-value pairs in the dict


std::pair<key_type, val_type> pop_item()

Remove the most recently added key-value pair andd return it as a vector


std::vector<key_type> list_keys()

Return a vector containing all keys in the dict


std::vector<val_type> list_values()

Return a vector containing all values in the dict


key_type& get_key_by_value(val_type val)

Return a reference to a key by its value


Thanks for reading! Also, check out the project on Github!

the github repo is usually updated to the newest stable version within 48 hours

You are viewing a single comment. View All
ANDREWVOSS (187)

@Coder100 So turns out templates have to be defined in headers :/ (otherwise you just have to include the .cpp, as well as creating even more templates to handle the original template). Really stinks, since it makes the source code all funky with there not being a .cpp and all that, but it won't work with out the template. Well, at least you reminded me to use include guards. (thanks for all the help, I'll remember all this next time I make a non-template header)