#include #include #include #include template class VectorMap { std::vector keys_; std::vector values_; static_assert(std::is_default_constructible::value, "Value should have the default constructor"); static_assert(std::is_default_constructible_v, "Value should have the default constructor"); public: using K = Key; using V = Value; void insert(const Key& k, const Value& v) { keys_.emplace_back(k); values_.emplace_back(v); } static constexpr bool isIntKey() { // if (std::is_integral_v) { if (std::is_same_v) { return true; } return false; } Value& operator[](const Key& k); Value& at(const Key& k); }; template Value& VectorMap::operator[](const Key& k) { auto it = std::find(std::begin(keys_), std::end(keys_), k); if (it == std::end(keys_)) { keys_.emplace_back(k); values_.emplace_back(Value{}); return values_.back(); } auto dist = std::distance(keys_.begin(), it); return values_[dist]; } template Value& VectorMap::at(const Key& k) { auto it = std::find(std::begin(keys_), std::end(keys_), k); if (it == std::end(keys_)) { throw std::out_of_range("This key does not exist"); } auto dist = std::distance(keys_.begin(), it); return values_[dist]; }