Header-only compile time key-value map written in C++20.

C++ Static Map

Requirement CMake build Codacy grade

Header-only compile time key-value map written in C++20.

Getting Started

Simply add the files in your source and #include "@dir/Static_map.hpp", and replace @dir with the actual directory they are put in.

Usage

Creating a map

To generate a Static_map containing data: {1,"One"},{2,"Two"},{3,"Three}:

constexpr auto map = sm::make_static_map(1, "One", 2, "Two", 3, "Three");

To generate a Static_map where key and value are the same type, you can also do:

constexpr auto map = sm::make_static_map({"1", "One"}, {"2", "Two"}, {"3", "Three"});

Alternatively, you can first create an std::array , N> object manually, and it can be explicitly converted to Static_map .


Retrieving data

There are three methods to retrieve value from the map with a given key:

  1. Static_map.at(KEY) it returns an std::optional . If key was not found it will return an std::nullopt.
  2. Static_map[KEY] it returns the pointed value. If key was not found it will throw std::out_of_range.
  3. Static_map.at_or_default(KEY, DEFAULT=VALUE{}) it returns the pointed value. If key was not found DEFAULT will be returned. If no default was given, the default constructed VALUE will be returned.
  • Note: The first option will always return an std::optional, whereas the other two will attempt to return the VALUE type directly.
  • Note: The second method would fail in compile time if key was not found, as it requires exception handling.

Duplicated Key

By default, Static_map will not check for duplicated keys. When retrieving data from a given key, only the first matched key will be considered.

Optionally, you can pass a custom flag SM_NO_DUPLICATE, it will throw std::invalid_argument if duplicate KEY were presented.

Prerequisites

C++20 with range library support is required for now. C++14/17 support will be added later.

Similar Resources

Easy to use, header only, macro generated, generic and type-safe Data Structures in C

Easy to use, header only, macro generated, generic and type-safe Data Structures in C

C Macro Collections Easy to use, header only, macro generated, generic and type-safe Data Structures in C. Table of Contents Installation Contributing

Sep 21, 2022

nanoplan is a header-only C++11 library for search-based robot planning.

nanoplan is a header-only C++11 library for search-based robot planning.

nanoplan is a header-only C++11 library for search-based robot planning. The primary design goals are correctness, ease-of-use, and efficiency (in tha

May 17, 2022

Simple Useful Libraries: C++17/20 header-only dynamic bitset

dynamic_bitset Simple Useful Libraries: C++17/20 header-only dynamic bitset Requirements To use this dynamic bitset, you will need a C++17 (or later)

Aug 28, 2022

a header-only, constexpr alternative to gperf for C++14 users

Frozen Header-only library that provides 0 cost initialization for immutable containers, fixed-size containers, and various algorithms. Frozen provide

Sep 15, 2022

A family of header-only, very fast and memory-friendly hashmap and btree containers.

A family of header-only, very fast and memory-friendly hashmap and btree containers.

The Parallel Hashmap Overview This repository aims to provide a set of excellent hash map implementations, as well as a btree alternative to std::map

Sep 21, 2022

C++14 header only result monad implementation

constexpr Either S, E C++14 header only result monad implementation. Features constexpr support 0 dependencies single header Status in development T

Oct 7, 2021

ring-span lite - A C++yy-like ring_span type for C++98, C++11 and later in a single-file header-only library

ring-span lite: A circular buffer view for C++98 and later Contents Example usage In a nutshell Dependencies Installation Synopsis Reported to work wi

Aug 23, 2022

Multi-Purpose Header-Only C Data Structures

USAGE These header files are meant to be a simple means of using datastructures in a C project. They are universally useable with any other C datatype

Jul 15, 2022

A simple single header 64 and 32 bit hash function using only add, sub, ror, and xor.

A simple single header 64 and 32 bit hash function using only add, sub, ror, and xor.

K-HASH A simple single header 64 bit hash function using only add, sub, ror, and xor. This a just general-purpose hash function for like making hash m

Jul 31, 2022
lightweight, compile-time and rust-like wrapper around the primitive numerical c++ data types

prim_wrapper header-only, fast, compile-time, rust-like wrapper around the primitive numerical c++ data types dependencies gcem - provides math functi

Oct 22, 2021
Postmodern immutable and persistent data structures for C++ — value semantics at scale
Postmodern immutable and persistent data structures for C++ — value semantics at scale

immer is a library of persistent and immutable data structures written in C++. These enable whole new kinds of architectures for interactive and concu

Sep 22, 2022
A fast hash map/hash table (whatever you want to call it) for the C programming language.

C HashMap A fast hash map/hash table (whatever you want to call it) for the C programming language. It can associate a key with a pointer or integer v

Sep 9, 2022
C++ implementation of a fast hash map and hash set using hopscotch hashing

A C++ implementation of a fast hash map and hash set using hopscotch hashing The hopscotch-map library is a C++ implementation of a fast hash map and

Sep 20, 2022
C++ implementation of a fast hash map and hash set using robin hood hashing

A C++ implementation of a fast hash map and hash set using robin hood hashing The robin-map library is a C++ implementation of a fast hash map and has

Sep 16, 2022
Unofficial .hmap map viewer for HumandKind
Unofficial .hmap map viewer for HumandKind

bhkmap Main Features Read/Write .hmap files Display elevation level, territories, biomes, tile types, strategic resources, luxury resources, natural w

Apr 9, 2022
Diablo II Resurrected map revealing tool.

D2RMH Diablo II Resurrected map revealing tool. What's New v0.2 add display for Unique Chest, Well, neighbour map path fix display of correct taltomb

Aug 29, 2022
C++ hash map and hash set which preserve the order of insertion

C++ hash map and hash set which preserves the order of insertion The ordered-map library provides a hash map and a hash set which preserve the order o

Sep 22, 2022
Practice is the key!

DSA-Weekly-LeetCode-Practice Hello Learners! This repository is for getting knowledge of Data Structures and Algorithms and practicing some good quest

Mar 16, 2022
BladeBit - Fast Chia (XCH) RAM-only k32-only Plotter

BladeBit Chia Plotter A fast RAM-only, k32-only, Chia plotter. Requirements 416 GiB of RAM are required to run it, plus a few more megabytes for stack

Sep 15, 2022