Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Initializing a map...
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Jeff Schwab, post: 3450757"] That's a neat idea. It could probably be made a little more efficient by replacing the calls to map::operator[] with calls to map::find and map::insert. If the OP is willing to have two statements rather than one, a copy of the map's data can also be saved by adding a swap function: template<typename K, typename V> struct map_initializer_proxy { // ... void swap(std::map<K, V>& m) { map_.swap(m); } }; int main() { std::map<int, int> m; map_initializer(3,4)(5,6)(7,8).swap(m); } This is admittedly not as nifty, since it's not really an initialization. It's more like a map_filler. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Initializing a map...
Top