Skip to content

Instantly share code, notes, and snippets.

@klmr
Created March 25, 2012 17:01
Show Gist options
  • Save klmr/2198296 to your computer and use it in GitHub Desktop.
Save klmr/2198296 to your computer and use it in GitHub Desktop.
Map that works with incomplete types.
#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
#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