# polymap **Repository Path**: deusomax/polymap ## Basic Information - **Project Name**: polymap - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-11 - **Last Updated**: 2024-12-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Poly map [![test](https://github.com/andreiavrammsd/polymap/workflows/test/badge.svg)](https://github.com/andreiavrammsd/polymap/actions/workflows/cmake.yml) [![bazel](https://github.com/andreiavrammsd/polymap/workflows/bazel/badge.svg)](https://github.com/andreiavrammsd/polymap/actions/workflows/bazel.yml) [![codecov](https://codecov.io/github/andreiavrammsd/polymap/graph/badge.svg?token=CKSCACRJXC)](https://codecov.io/github/andreiavrammsd/polymap) ### Polymorphic map container. A recursive map that can have any shape and can hold multiple types for keys and values. * Header-only library. * Key types are provided at construct time as template arguments. They must meet the type conditions for [std::variant](https://en.cppreference.com/w/cpp/utility/variant). * Value types must be copy constructible as the map takes ownership on the objects assigned. * Can be visualised as a tree. ## Requirements * C++17 * CMake 3.17+ or Bazel ## Usage ```c++ #include #include #include #include #include struct visitor { template bool operator()(const double key, V&, M&) { std::cout << "double = " << key << "\n"; return true; } template bool operator()(K& key, V&, M&) { std::cout << "other = " << key << "\n"; return true; } }; int main() { msd::poly_map map; map[1] = 22; map.at(1) = 23; map[1] = std::string{"a"}; map[1][2] = 9; map.at(1, 2) = 8; map[1][2][3.1] = 1; map[1][2][3.1]["f"] = 199; map[1][2][3.1][4.2]["g"] = std::make_pair(1, 2); assert(map[1][2].get() == 8); map.for_each(visitor{}); assert(!map[1].empty()); assert(map.size() == 6); assert(map[1].size() == 5); assert(map.contains(1, 2, 3.1)); map[1][2].clear(); map.clear(); } ``` See [tests](tests/poly_map_test.cpp).