94 lines
1.8 KiB
C++
94 lines
1.8 KiB
C++
|
|
#pragma once
|
|
|
|
#if !defined(MIJIN_CONTAINER_MAP_VIEW_HPP_INCLUDED)
|
|
#define MIJIN_CONTAINER_MAP_VIEW_HPP_INCLUDED 1
|
|
|
|
#include <unordered_map>
|
|
|
|
namespace mijin
|
|
{
|
|
|
|
//
|
|
// public defines
|
|
//
|
|
|
|
//
|
|
// public constants
|
|
//
|
|
|
|
//
|
|
// public types
|
|
//
|
|
|
|
template<typename TKey, typename TValue, typename TMap = std::unordered_map<TKey, TValue>>
|
|
struct MapView
|
|
{
|
|
private:
|
|
TMap& map;
|
|
public:
|
|
MapView() = delete;
|
|
MapView(const MapView&) = default;
|
|
MapView(MapView&&) noexcept = default;
|
|
inline MapView(TMap& map_) : map(map_) {}
|
|
|
|
MapView& operator=(const MapView&) = default;
|
|
MapView& operator=(MapView&&) noexcept = default;
|
|
|
|
[[nodiscard]] TValue& operator[](const TKey& key)
|
|
{
|
|
return at(key);
|
|
}
|
|
[[nodiscard]] const TValue& operator[](const TKey& key) const
|
|
{
|
|
return at(key);
|
|
}
|
|
|
|
[[nodiscard]] TValue& at(const TKey& key)
|
|
{
|
|
return map.at(key);
|
|
}
|
|
|
|
[[nodiscard]] const TValue& at(const TKey& key) const
|
|
{
|
|
return map.at(key);
|
|
}
|
|
|
|
[[nodiscard]] auto begin() const
|
|
{
|
|
return map.begin();
|
|
}
|
|
|
|
[[nodiscard]] auto begin()
|
|
{
|
|
return map.begin();
|
|
}
|
|
|
|
[[nodiscard]] auto end()
|
|
{
|
|
return map.end();
|
|
}
|
|
|
|
[[nodiscard]] auto end() const
|
|
{
|
|
return map.end();
|
|
}
|
|
};
|
|
|
|
// template<typename TKey, typename TValue, template<typename, typename, typename...> typename TMap>
|
|
// MapView(TMap<TKey, TValue>& map) -> MapView<TKey, TValue, TMap<TKey, TValue>>;
|
|
|
|
template<typename TMap>
|
|
MapView(TMap& map) -> MapView<typename TMap::key_type, typename TMap::mapped_type, TMap>;
|
|
|
|
template<typename TMap>
|
|
MapView(const TMap& map) -> MapView<typename TMap::key_type, const typename TMap::mapped_type, const TMap>;
|
|
|
|
//
|
|
// public functions
|
|
//
|
|
|
|
} // namespace mijin
|
|
|
|
#endif // !defined(MIJIN_CONTAINER_MAP_VIEW_HPP_INCLUDED)
|