Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/erikzenker/multikeymap
MultiKeyMap is C++ class similar to the std::map but with multiple key types
https://github.com/erikzenker/multikeymap
cpp14 map
Last synced: 26 days ago
JSON representation
MultiKeyMap is C++ class similar to the std::map but with multiple key types
- Host: GitHub
- URL: https://github.com/erikzenker/multikeymap
- Owner: erikzenker
- Created: 2016-08-23T08:36:18.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-05T20:15:07.000Z (over 6 years ago)
- Last Synced: 2024-10-30T01:44:48.577Z (2 months ago)
- Topics: cpp14, map
- Language: CMake
- Homepage:
- Size: 45.9 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MultiKeyMap #
[![Build Status](https://travis-ci.org/erikzenker/multikeymap.svg?branch=master)](https://travis-ci.org/erikzenker/multikeymap) [![codecov](https://codecov.io/gh/erikzenker/multikeymap/branch/master/graph/badge.svg)](https://codecov.io/gh/erikzenker/multikeymap)
===========**MultiKeyMap** is C++ class similar to the std::map but with multiple keys types e.g.: `MultiKeyMap multikeymap`.
## Usage ##
```c++
// STL
#include
#include
#include// MultiKeyMap
#include// HANA
#include
namespace hana = boost::hana;int main()
{// Set types for keys and value
using Country = std::string;
using City = std::string;
using Street = std::string;
using Number = int;
using Inhabitant = std::string;// Create multi key map
MultiKeyMap inhabitants;// Set inhabitants
inhabitants("Germany", "Hamburg", "Goetheweg", 5) = "Karl Koch";
inhabitants("Germany", "Berlin", "Schillerweg", 10) = "Hans Meier";// Print inhabitant of Goetheweg 5
std::cout << inhabitants.at("Germany", "Hamburg", "Goetheweg", 5) << std::endl;// Check for inhabitants in Schillerweg 10
if (inhabitants.test("Germany", "Berlin", "Schillerweg", 10)) {
std::cout << inhabitants.at("Germany", "Berlin", "Schillerweg", 10) << std::endl;
}// Print all inhabitants of Germany
std::vector inhabitantsOfGermany;
std::vector> keys;inhabitants.values(inhabitantsOfGermany, keys, "Germany");
for (std::size_t i = 0; i < inhabitantsOfGermany.size(); ++i) {
auto country = hana::at(keys[i], hana::size_c<0>);
auto city = hana::at(keys[i], hana::size_c<1>);
auto street = hana::at(keys[i], hana::size_c<2>);
auto number = hana::at(keys[i], hana::size_c<3>);
std::cout << country << " " << city << " " << street << " " << number << " "
<< inhabitantsOfGermany[i] << std::endl;
}return 0;
}
```Output:
```text
Karl Koch
Hans Meier
Germany Berlin Schillerweg 10 Hans Meier
Germany Hamburg Goetheweg 5 Karl Koch
```## Build Example ##
```bash
mkdir build; cd build
cmake ..
cmake --build multikeymap_example
./example/multikeymap_example
```## Build Tests ##
```bash
mkdir build; cd build
cmake ..
cmake --build multikeymap_unit_test
./test/unit/multikeymap_unit_test```
## Dependencies ##
* boost 1.67
* c++14## Licence ##
MIT## Author ##
Written by Erik Zenker (erikzenker (at) hotmail.com)