map

Why is the [] operator of C++ Map calling default constructor of mapped-value? [duplicate]

有些话、适合烂在心里 提交于 2020-01-11 12:49:49
问题 This question already has answers here : Why does the C++ map type argument require an empty constructor when using []? (5 answers) Closed 2 years ago . I compiled the following code with g++, the construct function A() will be called when executing the line: m["1"] Why is this happening? I don't see any necessarily of calling the constructor here. struct A { int mem; A(int arg){} A(){} }; int main() { unordered_map<string, A> m; m["1"]; // will call A(), but why? m.find("1")->second; // will

Does find() also return the last element of a map in C++?

谁说我不能喝 提交于 2020-01-11 10:38:27
问题 I'd like to use the find() method, to catch a particular element of my std::map() Now the return value is either the element I was looking for, or it it points to the end of the map if the element hasn't been found (C.f.: http://www.cplusplus.com/reference/map/map/find/ ). So I'm using these two information whether to decide if an element is in the map or not. But what happens if the element is already inside but at the very end ? My if-query would then decide that it's not existing and

Does find() also return the last element of a map in C++?

爷,独闯天下 提交于 2020-01-11 10:37:19
问题 I'd like to use the find() method, to catch a particular element of my std::map() Now the return value is either the element I was looking for, or it it points to the end of the map if the element hasn't been found (C.f.: http://www.cplusplus.com/reference/map/map/find/ ). So I'm using these two information whether to decide if an element is in the map or not. But what happens if the element is already inside but at the very end ? My if-query would then decide that it's not existing and

Java: how to convert a List<?> to a Map<String,?> [duplicate]

ぃ、小莉子 提交于 2020-01-11 02:07:21
问题 This question already has answers here : Java: How to convert List to Map (17 answers) Closed 4 years ago . I would like to find a way to take the object specific routine below and abstract it into a method that you can pass a class, list, and fieldname to get back a Map. If I could get a general pointer on the pattern used or , etc that could get me started in the right direction. Map<String,Role> mapped_roles = new HashMap<String,Role>(); List<Role> p_roles = (List<Role>) c.list(); for

How change image map area element style

泪湿孤枕 提交于 2020-01-10 16:16:46
问题 I'm using image map on my web page and iPad app. Each area on the image map is a clickable element to make sound, which I can do easily with jQuery. But I haven't been able to change the style, like either showing the border, or change the fill color just to indicate that the area is clicked. If anybody has done this, please let me know; it seems simple, but I'm really stumped. 回答1: I got it to work thanks to James Treworgy's awesome ImageMaster Jquery plugin. $('area').mousedown(function(e)

Enumeration and mapping with Scala 2.10

好久不见. 提交于 2020-01-10 05:13:33
问题 I'm trying to port my application to Scala 2.10.0-M2. I'm seeing some nice improvements with better warnings from compiler. But I also got bunch of errors, all related to me mapping from Enumeration.values . I'll give you a simple example. I'd like to have an enumeration and then pre-create bunch of objects and build a map that uses enumeration values as keys and then some matching objects as values. For example: object Phrase extends Enumeration { type Phrase = Value val PHRASE1 = Value("My

Error trying to find const char* key from std::map

痴心易碎 提交于 2020-01-10 04:18:08
问题 I have a map declared like this: std::map<const char*, const char*> map2D; The map is filled by the output from an API function, which returns const char* : map2D.insert(std::pair<const char*, const char*>(TempA, TempB)); Now there are 50 TempA values and 50 TempB values, and there is one key with the name of "months". When I am searching for this key, I am getting "not found". E.g.: std::map<const char*, const char*>::iterator it; it = map2D.find("months"); if (it != map2D.end()) { std::cout

How to set a Map value in h:inputText

笑着哭i 提交于 2020-01-10 04:12:23
问题 I'm struggling to implement a fairly trivial functionality with JSF which involves dynamically displaying the content of a nested map on a page and editing capabilities for its values. But it has turned out that the MappedValueExpression$Entry that you get when iterating over a map with c:forEach is not writable! <c:forEach items='#{inflectionBean.word.inflectionalForms}' var="number" > <p:fieldset legend="#{number.key}"> <c:forEach items="#{number.value}" var="case" > <p:panel header="#{case

golang map prints out of order

谁说胖子不能爱 提交于 2020-01-10 02:49:13
问题 Why is the map printing out of order, and how do I get it in to order? package main import ( "fmt" ) type monthsType struct { no int text string } var months = map[int]string{ 1:"January", 2:"Fabruary", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"Novenber", 12:"December", } func main(){ for no, month := range months { fmt.Print(no) fmt.Println("-" + month) } } Prints out: 10-October 7-July 1-January 9-September 4-April 5-May 2-Fabruary 12

C++ unordered_map with char* as key

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-09 10:25:10
问题 I feel exhausted when trying to use the container unordered_map with char* as the key (on Windows, I am using VS 2010). I know that I have to define my own compare function for char* , which inherits from binary_function . The following is a sample program. #include<unordered_map> #include <iostream> #include <string> using namespace std; template <class _Tp> struct my_equal_to : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return strcmp( _