#include <userver/utils/trivial_map.hpp>
Bidirectional unordered map for trivial types, including string literals; could be efficiently used as a unordered non-bidirectional map.
utils::TrivialBiMap and utils::TrivialSet are known to outperform std::unordered_map if:
Implementation of string search is very efficient due to modern compilers optimize it to a switch by input string length and an integral comparison (rather than a std::memcmp call). In other words, it usually takes O(1) to find the match in the map.
The same story with integral or enum mappings - compiler optimizes them into a switch and it usually takes O(1) to find the match.
Empty map:
For a single value Case statements see utils::TrivialSet.
Definition at line 665 of file trivial_map.hpp.
Classes | |
class | iterator |
struct | value_type |
Public Types | |
using | First = typename TypesPair::first_type |
using | Second = typename TypesPair::second_type |
template<class T> | |
using | MappedTypeFor = std::conditional_t<std::is_convertible_v<T, DecayToStringView<First>>, Second, First> |
Public Member Functions | |
constexpr | TrivialBiMap (BuilderFunc &&func) noexcept |
constexpr std::optional< Second > | TryFindByFirst (DecayToStringView< First > value) const noexcept |
constexpr std::optional< First > | TryFindBySecond (DecayToStringView< Second > value) const noexcept |
template<class T> | |
constexpr std::optional< MappedTypeFor< T > > | TryFind (T value) const noexcept |
constexpr std::optional< Second > | TryFindICaseByFirst (std::string_view value) const noexcept |
Case insensitive search for value. | |
constexpr std::optional< First > | TryFindICaseBySecond (std::string_view value) const noexcept |
Case insensitive search for value. | |
constexpr std::optional< MappedTypeFor< std::string_view > > | TryFindICase (std::string_view value) const noexcept |
Case insensitive search for value that calls either TryFindICaseBySecond or TryFindICaseByFirst. | |
constexpr std::size_t | size () const noexcept |
Returns count of Case's in mapping. | |
std::string | Describe () const |
std::string | DescribeFirst () const |
std::string | DescribeSecond () const |
template<typename T> | |
std::string | DescribeByType () const |
constexpr value_type | GetValuesByIndex (std::size_t index) const |
constexpr iterator | begin () const |
constexpr iterator | end () const |
constexpr iterator | cbegin () const |
constexpr iterator | cend () const |
using utils::TrivialBiMap< BuilderFunc >::First = typename TypesPair::first_type |
Definition at line 669 of file trivial_map.hpp.
using utils::TrivialBiMap< BuilderFunc >::MappedTypeFor = std::conditional_t<std::is_convertible_v<T, DecayToStringView<First>>, Second, First> |
Returns Second if T is convertible to First, otherwise returns Second type.
Definition at line 680 of file trivial_map.hpp.
using utils::TrivialBiMap< BuilderFunc >::Second = typename TypesPair::second_type |
Definition at line 670 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Definition at line 682 of file trivial_map.hpp.
|
inlineconstexpr |
Definition at line 827 of file trivial_map.hpp.
|
inlineconstexpr |
Definition at line 829 of file trivial_map.hpp.
|
inlineconstexpr |
Definition at line 830 of file trivial_map.hpp.
|
inline |
Returns a string of comma separated quoted values of Case parameters.
Example: "('a', '1'), ('b', '2'), ('c', '3')"
Parameters of Case should be formattable.
Definition at line 753 of file trivial_map.hpp.
|
inline |
Returns a string of comma separated quoted values of Case parameters that matches by type.
Example: "'1', '2', '3'"
Corresponding Case must be formattable
Definition at line 784 of file trivial_map.hpp.
|
inline |
Returns a string of comma separated quoted values of first Case parameters.
Example: "'a', 'b', 'c'"
First parameters of Case should be formattable.
Definition at line 763 of file trivial_map.hpp.
|
inline |
Returns a string of comma separated quoted values of second Case parameters.
Example: "'1', '2', '3'"
Second parameters of Case should be formattable.
Definition at line 773 of file trivial_map.hpp.
|
inlineconstexpr |
Definition at line 828 of file trivial_map.hpp.
|
inlineconstexpr |
Definition at line 792 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Returns count of Case's in mapping.
Definition at line 744 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Definition at line 701 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Definition at line 692 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Definition at line 696 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Case insensitive search for value that calls either TryFindICaseBySecond or TryFindICaseByFirst.
Definition at line 731 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Case insensitive search for value.
For efficiency reasons, first parameter in Case() should be lower case string literal.
Definition at line 717 of file trivial_map.hpp.
|
inlineconstexprnoexcept |
Case insensitive search for value.
For efficiency reasons, second parameter in Case() should be lower case string literal.
Definition at line 725 of file trivial_map.hpp.