#include #include #include #include #include template struct LookupKey { typedef KeyType type; static const int n = N; }; template const std::list& EmptyList() { static const std::list list; return list; } template class LookupTable { static_assert(sizeof...(Keys) > 0, "lookup table must have at least one key"); public: typedef const std::list& result_type; private: template void _build() { /* done! */ } template void _build() { _columns[sizeof...(Keys) - sizeof...(RemKeys) - 1] = new std::unordered_map>(); return _build(); } template void _destroy() { /* done! */ } template void _destroy() { delete (std::unordered_map>*)_columns[sizeof...(Keys) - sizeof...(RemKeys) - 1]; return _destroy(); } // search functions template result_type _check_match(typename T::type& search) { auto map = (std::unordered_map>*)_columns[sizeof...(Keys) - sizeof...(RemKeys) - 1]; auto it = map->find(search); return it == map->end() ? EmptyList() : it->second; } template result_type _check_match(SearchType& search) { return _lookup(search); } template result_type _lookup(SearchType& search) { static_assert(SearchKey != SearchKey, "key not found"); } template result_type _lookup(SearchType& search) { return _check_match, RemKeys...>(search); } // insert functions template void _insert(ValueType& value) { /* done! */ } template void _insert(ValueType& value, KeyValue& keyValue, RemKeyValues&... rem) { auto map = (std::unordered_map>*)_columns[sizeof...(Keys) - sizeof...(RemKeys) - 1]; (*map)[keyValue].push_back(value); return _insert(value, rem...); } public: LookupTable() { _build(); } ~LookupTable() { _destroy(); } template result_type lookup(SearchType search) { return _lookup(search); } template void insert(ValueType value, KeyValues... keyValues) { static_assert(sizeof...(KeyValues) == sizeof...(Keys), "wrong number of keys"); return _insert(value, keyValues...); } private: void* _columns[sizeof...(Keys)]; };