intial commit
This commit is contained in:
90
source/mijin/container/map_view.hpp
Normal file
90
source/mijin/container/map_view.hpp
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
#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>;
|
||||
|
||||
//
|
||||
// public functions
|
||||
//
|
||||
|
||||
} // namespace mijin
|
||||
|
||||
#endif // !defined(MIJIN_CONTAINER_MAP_VIEW_HPP_INCLUDED)
|
||||
Reference in New Issue
Block a user