Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
EnumMapper.h File Reference

Generic utilities for bidirectional enum–string mappings. More...

#include <map>
#include <string>
#include <vector>
Include dependency graph for EnumMapper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  EnumMapperBase< Enum, Derived >
 CRTP base class for enum–string mappers. More...
 

Functions

template<typename K , typename V >
std::map< V, Kinvert_map (const std::map< K, V > &original)
 Builds the inverse of a std::map by swapping keys and values.
 

Detailed Description

Generic utilities for bidirectional enum–string mappings.

This header provides:

  • a CRTP base class EnumMapperBase for defining enum-to-string and string-to-enum mappers,
  • a small helper function invert_map() to build inverse maps.

A typical usage pattern is:

  • define an enum type,
  • define a struct Derived : EnumMapperBase<Enum, Derived> that exposes:
    • static const std::map<Enum, std::string>& mapping();
    • static const std::map<std::string, Enum>& inverse_mapping();
  • use Derived::str(e) to get the name of an enum value, and Derived::enum_elt(name) to recover the enum from its string.

Definition in file EnumMapper.h.

Function Documentation

◆ invert_map()

template<typename K , typename V >
std::map< V, K > invert_map ( const std::map< K, V > &  original)

Builds the inverse of a std::map by swapping keys and values.

Given an ordered map original of type std::map<K, V>, this helper constructs a new std::map<V, K> where each value becomes a key and each key becomes a value.

If multiple keys in original share the same value, the last one encountered in iteration order will overwrite the previous entry in the inverse map. This is intentional and tested behaviour.

Template Parameters
KKey type of the original map.
VValue type of the original map.
Parameters
originalMap to invert.
Returns
Inverted map where values become keys and keys become values.

Definition at line 131 of file EnumMapper.h.