diff --git a/extras/AssociativeContainers/map.hpp b/extras/AssociativeContainers/map.hpp index 7cf0438..5b556d1 100644 --- a/extras/AssociativeContainers/map.hpp +++ b/extras/AssociativeContainers/map.hpp @@ -23,4 +23,6 @@ class Map static Map* make() { return new Map(); } size_t size() { return this->map.size(); } + + V& operator[] (K const& key) { return this->map[key]; } }; diff --git a/source/stdcpp/map.d b/source/stdcpp/map.d index a79c6ba..b7ab616 100644 --- a/source/stdcpp/map.d +++ b/source/stdcpp/map.d @@ -19,6 +19,15 @@ module stdcpp.map; } static Map* make(); + private void insertOrAssign(const ref Key, const ref Value); + size_t size(); + + ref Value opIndex( ref const Key key); + + ref Value opIndex(const Key key) + { + return this.opIndex(key); // handle rvalue-ref + } } \ No newline at end of file diff --git a/source/stdcpp/test/map.d b/source/stdcpp/test/map.d index 469a7a3..ecef08f 100644 --- a/source/stdcpp/test/map.d +++ b/source/stdcpp/test/map.d @@ -13,4 +13,8 @@ unittest auto mymap = Map!(int, char).make(); mymap.opIndexAssign(1, 'a'); assert(mymap.size == 1); + assert(mymap.opIndex(1) == 'a'); + mymap.opIndex(2) = 'b'; + mymap.opIndex(3) = 'c'; + assert(mymap.size == 3); }