map

How to use std::for_each on a map element method with input?

烂漫一生 提交于 2020-01-24 11:11:27
问题 I have: struct Mystruct { void Update(float Delta); } typedef std::map<int, Mystruct*> TheMap; typedef TheMap::iterator TheMapIt; TheMap Container; and wants to do: for(TheMapIt It = Container.begin(), Ite = Container.end(); It != Ite; ++It) { It->second->Update(Delta); } using std::for_each , how to do this? I think I can declare function like: void Do(const std::pair<int, Mystruct*> Elem) { Elem->Update(/*problem!*/); ---> How to pass Delta in? } Or make another struct: struct Doer { Doer

How to use std::for_each on a map element method with input?

ぃ、小莉子 提交于 2020-01-24 11:10:50
问题 I have: struct Mystruct { void Update(float Delta); } typedef std::map<int, Mystruct*> TheMap; typedef TheMap::iterator TheMapIt; TheMap Container; and wants to do: for(TheMapIt It = Container.begin(), Ite = Container.end(); It != Ite; ++It) { It->second->Update(Delta); } using std::for_each , how to do this? I think I can declare function like: void Do(const std::pair<int, Mystruct*> Elem) { Elem->Update(/*problem!*/); ---> How to pass Delta in? } Or make another struct: struct Doer { Doer

Mongo Database save data from Map

别等时光非礼了梦想. 提交于 2020-01-24 05:13:06
问题 I have the below code which works: if (aDBCursor.hasNext()) { DBObject aDbObject = aDBCursor.next(); aDbObject.put("title", "Test Title"); ArrayList<DBObject> department = new ArrayList<DBObject>(); DBObject nested1 = new BasicDBObject(); nested1.put("name", "Department A"); nested1.put("id", 1); department.add(nested1); DBObject nested2 = new BasicDBObject(); nested2.put("name", "Department B"); nested2.put("id", 2); department.add(nested2); aDbObject.put("department", department);

How can I map class types to instances of that class in C++?

半腔热情 提交于 2020-01-23 18:48:50
问题 I wish to have a map from classes to instances of each class. The goal is to have a container of components for a component-based game engine where an object can have at most one of each component type. In Java, I could just use class objects as the key. How can I do something similar in C++? My initial research suggests something like using typeid(component_instance).name() as the key. Is there a better way to do this? 回答1: Unlike in more dynamic languages like Python or Java, classes in C++

How to render a List with Groovy's MarkupBuilder

三世轮回 提交于 2020-01-23 10:47:07
问题 I am converting a Map to XML using the Groovy MarkupBuilder. This Map can contain simple key/value pairs, other Maps, or Lists of Maps. I am piggybacking from the code here. import groovy.xml.MarkupBuilder def map = [ key1:'value1', key2:'value2', nestedMap : [ key1:'bar1', key2:'bar2' ], select : [ [option:'foo1'], [option:'foo2'] ] ] Closure renderMap( Map map ){ return { for ( entry in map ){ switch( entry.value.getClass() ){ case Map : "${entry.key}" renderMap( entry.value ) break case

Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>();

南楼画角 提交于 2020-01-23 08:36:05
问题 Why doesn't that work in java, but this does Map<String, Map<String, Boolean>> myMap = new HashMap<String,Map<String,Boolean>>(); Just to clarify the below alteration of the nested HashMap shows a compiler error, whereas the above does not not; with a Map (not hashmap) Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>(); 回答1: This is because generics in Java are invariant , i.e. even if class B is an A, a Collection<B> is not a Collection<A> . And this is

Sorted maps in groovy

醉酒当歌 提交于 2020-01-20 17:08:25
问题 I am interested in using a sorted map in groovy (with gremlin which is a DSL for graph databases). I have looked at this blog post on sorted maps here, but I am still a bit confused. How are sorted maps declared? Is it any different from the standard way for maps y = [:] ? When using a sorted map, are items inserted into the list going to be in the order they are inserted? Or will I have to run sort{} before the items in the sorted map are sorted? 回答1: If you just declare a map like so: def m

Sorted maps in groovy

橙三吉。 提交于 2020-01-20 17:04:04
问题 I am interested in using a sorted map in groovy (with gremlin which is a DSL for graph databases). I have looked at this blog post on sorted maps here, but I am still a bit confused. How are sorted maps declared? Is it any different from the standard way for maps y = [:] ? When using a sorted map, are items inserted into the list going to be in the order they are inserted? Or will I have to run sort{} before the items in the sorted map are sorted? 回答1: If you just declare a map like so: def m

Sorted maps in groovy

烂漫一生 提交于 2020-01-20 17:03:24
问题 I am interested in using a sorted map in groovy (with gremlin which is a DSL for graph databases). I have looked at this blog post on sorted maps here, but I am still a bit confused. How are sorted maps declared? Is it any different from the standard way for maps y = [:] ? When using a sorted map, are items inserted into the list going to be in the order they are inserted? Or will I have to run sort{} before the items in the sorted map are sorted? 回答1: If you just declare a map like so: def m

Why is java.util.Map.get(…) not generic? [duplicate]

北城余情 提交于 2020-01-20 07:53:48
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What are the reasons why Map.get(Object key) is not (fully) generic This method and a number of other methods in the Map interface are not generic. Almost anywhere a key value is expected as a parameter, it accepts Object instead, namely remove, get and containsKey. Any idea as to why they made this decision. My assumption is that it was done to support legacy code, but to me, I think that is a weak position.