Created
March 25, 2012 17:01
-
-
Save klmr/2198296 to your computer and use it in GitHub Desktop.
Map that works with incomplete types.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef TEST_HASHMAP_HPP | |
#define TEST_HASHMAP_HPP | |
#include <vector> | |
namespace test { | |
template <typename F, typename S> | |
struct pair; | |
template <typename K, typename V> | |
struct hashmap { | |
typedef pair<K, V> value_type; | |
hashmap(); | |
hashmap(hashmap const&); | |
~hashmap(); | |
void insert(K, V); | |
V& find(K const&); | |
private: | |
value_type* store; | |
}; | |
template <typename F, typename S> | |
struct pair { | |
F first; | |
S second; | |
}; | |
template <typename K, typename V> | |
inline hashmap<K, V>::hashmap() | |
: store(new value_type[10]) | |
{ } | |
template <typename K, typename V> | |
inline hashmap<K, V>::hashmap(hashmap const& other) | |
: store(new value_type[10]) | |
{ | |
for (unsigned i = 0; i < 10; ++i) | |
store[i] = other.store[i]; | |
} | |
template <typename K, typename V> | |
inline hashmap<K, V>::~hashmap() | |
{ | |
delete [] store; | |
} | |
} // namespace test | |
#endif // ndef TEST_HASHMAP_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "hashmap.hpp" | |
struct state { | |
int value; | |
test::hashmap<int, state> transitions; | |
}; | |
int main() { | |
state automaton; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment