Add given code

This commit is contained in:
Bruno BELANYI 2024-08-23 21:40:22 +01:00
parent c4d81c4e81
commit 3c0ddf3021

View file

@ -1 +1,27 @@
#pragma once #pragma once
#include <map>
namespace amby {
template <typename K, typename V> class interval_map {
public:
interval_map(V const& init) : init_(init) {}
void assign(K const& begin, K const& end, V const& val) {
// TODO: implement
}
V const& operator[](K const& key) const {
auto it = underlying_.upper_bound(key);
if (it == underlying_.begin())
return init_;
return std::prev(it)->second;
}
private:
V init_;
std::map<K, V> underlying_{};
};
} // namespace amby