Skip to content

Instantly share code, notes, and snippets.

@SethHamilton
Last active November 21, 2017 15:53

Revisions

  1. SethHamilton revised this gist Nov 21, 2017. No changes.
  2. SethHamilton revised this gist Nov 21, 2017. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions reverse_map_snippit.hpp
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,7 @@
    #pragma once
    #include <unordered_map>
    #include <utility>

    enum class test_e : int64_t
    {
    one,
  3. SethHamilton created this gist Nov 21, 2017.
    21 changes: 21 additions & 0 deletions reverse_map_snippit.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    enum class test_e : int64_t
    {
    one,
    two,
    three
    };

    // forward map
    static const std::unordered_map<string, test_e> testForwardMap = {
    {"one", test_e::one},
    {"two", test_e::two},
    {"three", test_e::three}
    };

    // reverse map
    static const std::unordered_map<test_e, string> testReverseMap([]()->std::unordered_map<test_e,string>{
    std::unordered_map<test_e, string> res;
    for (auto &i : testForwardMap)
    res.emplace(i.second, i.first);
    return std::move(res);
    }());