Sorted String Map

API Reference

template <typename _ValueT>
class sorted_string_map

sorted_string_map provides an efficient way to map string keys to arbitrary values, provided that the keys are known at compile time and are sorted in ascending order.

Public Types

typedef _ValueT value_type
typedef size_t size_type

Public Functions

sorted_string_map(const entry *entries, size_type entry_size, value_type null_value)

Constructor.

Parameters
  • entries: pointer to the array of key-value entries.
  • entry_size: size of the key-value entry array.
  • null_value: null value to return when the find method fails to find a matching entry.

value_type find(const char *input, size_type len) const

Find a value associated with a specified string key.

Return
value associated with the key, or the null value in case the key is not found.
Parameters
  • input: pointer to a C-style string whose value represents the key to match.
  • len: length of the matching string value.

size_type size() const

Return the number of entries in the map. Since the number of entries is statically defined at compile time, this method always returns the same value.

Return
the number of entries in the map.

struct entry

Single key-value entry. Caller must provide at compile time a static array of these entries.

Public Members

template<>
const char *key
template<>
size_type keylen
template<>
value_type value