diff --git a/extras/AssociativeContainers/map.hpp b/extras/AssociativeContainers/map.hpp index ff947fe..8c6b591 100644 --- a/extras/AssociativeContainers/map.hpp +++ b/extras/AssociativeContainers/map.hpp @@ -20,22 +20,24 @@ class Map std::map map; public: // msvc mangles public and private static fields differently so need for public - static Map* make() { return new Map(); } + static Map* make() { return new Map(); } - size_t size() { return this->map.size(); } + size_t size() { return this->map.size(); } - V& operator[] (K const& key) { return this->map[key]; } + V& operator[] (K const& key) { return this->map[key]; } - V& at(K const& key) { return this->map.at(key); } + V& at(K const& key) { return this->map.at(key); } - bool empty() const noexcept { return this->map.empty(); } + bool empty() const noexcept { return this->map.empty(); } - size_t max_size() const { return this->map.max_size(); } + size_t max_size() const { return this->map.max_size(); } - void clear() noexcept { this->map.clear(); } + void clear() noexcept { this->map.clear(); } - size_t count(K const& key ) const { return this->map.count(key); } + size_t count(K const& key ) const { return this->map.count(key); } - bool contains(K const& key ) const { return this->map.contains(key);} + bool contains(K const& key ) const { return this->map.contains(key);} + + void swap( Map* other) noexcept { this->map.swap(other->map); } // swap with the function parameter's map }; diff --git a/extras/test.cpp b/extras/test.cpp index 00302b0..ba928ac 100644 --- a/extras/test.cpp +++ b/extras/test.cpp @@ -39,4 +39,4 @@ template std::size_t stdcpp::test::cppSizeOf >(); template class std::set; template std::size_t stdcpp::test::cppSizeOf >(); -template class Map; +template class Map; \ No newline at end of file diff --git a/source/stdcpp/map.d b/source/stdcpp/map.d index 24f2df3..8395b55 100644 --- a/source/stdcpp/map.d +++ b/source/stdcpp/map.d @@ -58,4 +58,6 @@ module stdcpp.map; { return this.contains(key); } + /// + void swap( Map* other) nothrow; } \ No newline at end of file diff --git a/source/stdcpp/test/map.d b/source/stdcpp/test/map.d index a6add12..243dbac 100644 --- a/source/stdcpp/test/map.d +++ b/source/stdcpp/test/map.d @@ -25,4 +25,14 @@ unittest assert(mymap.size == 0); assert(mymap.empty == 1); assert(mymap.count(1) == 0); // container cleared + /* utilities to use to test after a swap */ + mymap.opIndex(2) = 'b'; + mymap.opIndex(3) = 'c'; + + /* testing for swap*/ + auto mymap2 = Map!(int, char).make(); + mymap2.swap(mymap); + assert(mymap2.size == 2); + assert(mymap2.at(2) == 'b'); + assert(mymap2.at(3) == 'c'); // swap works! }