Re: Map Needs Merge
- Posted by euphoric (admin) Jul 23, 2019
- 911 views
ghaberek said...
euphoric said...
Anybody want to try their hand at a fast and efficient map:merge() function?
map:merge( map_one, map_two ) -- merge map_two into map_one (?)
or something like that.
This needs to be in std/map.e.
Is this what you want?
map:copy( map_one, map_two ) delete( map_two )
From the docs... (emphasis mine)
docs said...
Returns:
If dest_map was not provided, an exact duplicate of source_map otherwise dest_map, which does not have to be empty, is returned with the new values copied from source_map, according to the put_operation value.
No, that is obviously NOT what I wanted. That is a copy and delete. I want a merge.
HAHAHAA!
OK, OK. Sure. I'll take it.
But map:merge() is a much better name for merging two (or more) maps.
P.S. Your example deletes the "destination" map... So...