Using pair as key in a map (C++ / STL)

std::map::insert takes a single argument: the key-value pair, so you would need to use: mapa.insert(std::make_pair(p1, “Manzana”)); You should use std::string instead of C strings in your types. As it is now, you will likely not get the results you expect because looking up values in the map will be done by comparing pointers, not by … Read more

What is std::pair?

compressed_pair uses some template trickery to save space. In C++, an object (small o) can not have the same address as a different object. So even if you have struct A { }; A‘s size will not be 0, because then: A a1; A a2; &a1 == &a2; would hold, which is not allowed. But … Read more

What is the difference between std::list and std::map in C++ STL?

std::map<X, Y>: is an ordered structure with respect to keys (that is, when you iterate over it, keys will be always increasing). supports unique keys (Xs) only offers fast find() method (O(log n)) which finds the Key-Value pair by Key offers an indexing operator map[key], which is also fast std::list<std::pair<X, Y> >: is a simple … Read more

converting a variable name to a string in C++

You can use the preprocessor “stringify” # to do what you want: #include <stdio.h> #define PRINTER(name) printer(#name, (name)) void printer(char *name, int value) { printf(“name: %s\tvalue: %d\n”, name, value); } int main (int argc, char* argv[]) { int foo = 0; int bar = 1; PRINTER(foo); PRINTER(bar); return 0; } name: foo value: 0 name: … Read more

Why was pair range access removed from C++11?

I think the 2009 paper “Pairs do not make good ranges” by Alisdair Meredith is at least part of the answer. Basically, many algorithms return pairs of iterators that are actually not guaranteed to be valid ranges. It seems they removed the support for pair<iterator,iterator> from the for-range loop for this reason. However, the proposed … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)