How can I use an array as map value?

You can’t copy arrays by value like that. Here are several solutions, but I recommend #4 for your needs: Use an std::vector instead of an array. Use a map of pointers to arrays of 3 elements: int red[3] = {1,0,0}; int green[3] = {0,1,0}; int blue[3] = {0,0,1}; std::map<int,int(*)[3]> colours; colours.insert(std::pair<int,int(*)[3]>(GLUT_LEFT_BUTTON,&red)); colours.insert(std::pair<int,int(*)[3]>(GLUT_MIDDLE_BUTTON,&blue)); colours.insert(std::pair<int,int(*)[3]>(GLUT_RIGHT_BUTTON,&green)); // Watch … Read more

Template class with template container

You should use template template parameters: template<typename T, template <typename, typename> class Container> // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ class MyMultibyteString { Container<T, std::allocator<T>> buffer; // … }; This would allow you to write: MyMultibyteString<int, std::vector> mbs; Here is a compiling live example. An alternative way of writing the above could be: template<typename T, template <typename, typename = std::allocator<T>> … Read more

Is the behaviour of Python’s list += iterable documented anywhere?

From Guido van Rossum: It works the same way as .extend() except that it also returns self. I can’t find docs explaining this. ๐Ÿ™ Here is the relevant source code taken from listobject.c: list_inplace_concat(PyListObject *self, PyObject *other) { PyObject *result; result = listextend(self, other); if (result == NULL) return result; Py_DECREF(result); Py_INCREF(self); return (PyObject *)self; … Read more

What is an iterator’s default value?

By convention a “NULL iterator” for containers, which is used to indicate no result, compares equal to the result of container.end(). std::vector<X>::iterator iter = std::find(my_vec.begin(), my_vec.end(), x); if (iter == my_vec.end()) { //no result found; iter points to “nothing” } However, since a default-constructed container iterator is not associated with any particular container, there is … 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

ItemContainerGenerator.ContainerFromItem() returns null?

I found something that worked better for my case in this StackOverflow question: Get row in datagrid By putting in UpdateLayout and a ScrollIntoView calls before calling ContainerFromItem or ContainerFromIndex, you cause that part of the DataGrid to be realized which makes it possible for it return a value for ContainerFromItem/ContainerFromIndex: dataGrid.UpdateLayout(); dataGrid.ScrollIntoView(dataGrid.Items[index]); var row … Read more

What is the best practice of docker + ufw under Ubuntu

Problem This problem has been around for a long time. Disable iptables in Docker will take other problems. Rollback changes first If you have modified your server according to the current solution that we find on the internet, please rollback these changes first, including: Enable Docker’s iptables feature. Remove all changes like –iptables=false , including … Read more