class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined arrays, while making efficient use of the inherent sort order of such arrays. More...
template<class KeyType, class ValueType, class KeyCompare = less<KeyType>>class CStaticArrayMap<> is an array adaptor that provides an STLish interface to statically-defined arrays, while making efficient use of the inherent sort order of such arrays.
This class can be used both to verify sorted order of a static array and to access a static array cleanly. The template parameters are as follows:
KeyType – type of key object used for access ValueType – type of object used for access KeyCompare – comparison functor. This must provide an operator(). This is patterned to accept PCase and PNocase and similar objects.
To use this class, define your static array as follows:
static const char* sc_MyArray[] = { "val1", "val2", "val3" };
Then, declare a static variable such as:
typedef StaticArraySet<const char*, PNocase_CStr> TStaticArray; static TStaticArray sc_Array(sc_MyArray, sizeof(sc_MyArray));
In debug mode, the constructor will scan the list of items and insure that they are in the sort order defined by the comparator used. If the sort order is not correct, then the constructor will ASSERT().
This can then be accessed as
if (sc_Array.find(some_value) != sc_Array.end()) { ... }
or
size_t idx = sc_Array.index_of(some_value); if (idx != TStaticArray::eNpos) { ... }
class CStaticPairArrayMap<> provides access to a static array of pairs in much the same way as CStaticArraySet<>, except that it provides binding of a value type to each sorted key, much like an STL map<> would. Its first template parameter must satisfy STL pair<> requirements: 1. it must define first_type and second_type typedefs, 2. it must have two data members: first and second.
Definition at line 103 of file static_map.hpp.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4