containers
How can I use std::maps with user-defined types as key?
You don’t have to define operator< for your class, actually. You can also make a comparator function object class for it, and use that to specialize std::map. To extend your example: struct Class1Compare { bool operator() (const Class1& lhs, const Class1& rhs) const { return lhs.id < rhs.id; } }; std::map<Class1, int, Class1Compare> c2int; It … Read more
How to change the size of the font of a JLabel to take the maximum size
label = new JLabel(“A label”); label.setFont(new Font(“Serif”, Font.PLAIN, 14)); taken from How to Use HTML in Swing Components
Docker in Docker cannot mount volume
A Docker container in a Docker container uses the parent HOST’s Docker daemon and hence, any volumes that are mounted in the “docker-in-docker” case is still referenced from the HOST, and not from the Container. Therefore, the actual path mounted from the Jenkins container “does not exist” in the HOST. Due to this, a new … Read more
Docker filling up storage on macOS
WARNING: By default, volumes are not removed to prevent important data from being deleted if there is currently no container using the volume. Use the –volumes flag when running the command to prune volumes as well: Docker now has a single command to do that: docker system prune -a –volumes See the Docker system prune … Read more
Copy map values to vector in STL [duplicate]
You could probably use std::transform for that purpose. I would maybe prefer Neils version though, depending on what is more readable. Example by xtofl (see comments): #include <map> #include <vector> #include <algorithm> #include <iostream> template< typename tPair > struct second_t { typename tPair::second_type operator()( const tPair& p ) const { return p.second; } }; template< … Read more
c++ deque vs queue vs stack
Moron/Aryabhatta is correct, but a little more detail may be helpful. Queue and stack are higher level containers than deque, vector, or list. By this, I mean that you can build a queue or stack out of the lower level containers. For example: std::stack<int, std::deque<int> > s; std::queue<double, std::list<double> > q; Will build a stack … Read more
What’s the difference between std::multimap and std::map
A std::map is an associative container, that allows you to have a unique key associated with your type value. For example, void someFunction() { typedef std::map<std::string, int> MapType; MapType myMap; // insertion myMap.insert(MapType::value_type(“test”, 42)); myMap.insert(MapType::value_type(“other-test”, 0)); // search auto it = myMap.find(“test”); if (it != myMap.end()) std::cout << “value for ” << it->first << ” … Read more
Why does std::stack use std::deque by default?
As the container grows, a reallocation for a vector requires copying all the elements into the new block of memory. Growing a deque allocates a new block and links it to the list of blocks – no copies are required. Of course you can specify that a different backing container be used if you like. … Read more