containers

Are pointers allowed as keys in ordered STL containers?

*爱你&永不变心* 提交于 2019-11-29 10:47:33
There's this other question asking about how comparing pointers is supposed to be interpreted wrt the C++ Std. So I was wondering what the C++ Std has to say about using pointers as keys in ordered standard library (STL) containers -- i.e. is one allowed to have std::map<T1*, T2> and is this due to the specification of std::less or builtin operator < ? Yes, because it uses std::less , which is required to result in a total order even if < doesn't. ( < would be allowed to treat different pointers from distinct sequences as equal, which would result in an odd behaviour of map etc if you insert

should std::vector honour alignof(value_type)?

≡放荡痞女 提交于 2019-11-29 10:46:43
If I define a simple type with a certain alignment requirement, shouldn't a std::vector<t> of said type honour the alignment for every single element ? Consider the following example typedef std::array<double,3> alignas(32) avx_point; std::vector<avx_point> x(10); assert(!(std::ptrdiff_t(&(x[0]))&31) && // assert that x[0] is 32-byte aligned !(std::ptrdiff_t(&(x[1]))&31)); // assert that x[1] is 32-byte aligned I found that the alignment requirement is silently (without any warning) violated by clang 3.2 (with or without -stdlib=libc++ ), while gcc 4.8.0 issues a warning that it ignores the

Generic function to flatten a container of containers

风流意气都作罢 提交于 2019-11-29 10:46:41
I am trying to get a better hold on iterators and generic functions. I thought it would be a useful exercise to write a function that converts container1 < container2 <type> > to container3 <type> . For example, it should be able to convert vector< deque<int> > to list<int> . I figured all the container access should be through iterators, like the functions in <algorithm> . Here is my code: #include <iterator> #include <algorithm> // COCiter == Container of Containers Iterator // Oiter == Output Iterator template <class COCiter, class Oiter> void flatten (COCiter start, COCiter end, Oiter dest

What is the reason of QVector's requirement for default constructor?

旧城冷巷雨未停 提交于 2019-11-29 10:31:48
I can see that that classes are treated as complex objects which are required for calling default constructor: void QVector<T>::defaultConstruct(T *from, T *to) { if (QTypeInfo<T>::isComplex) { while (from != to) { new (from++) T(); } ... } But it's not clear why is it needed to construct objects in the 'hidden' area of QVector. I mean these objects are not accessible at all, so why not just to reserve the memory instead of the real object creation? And as a bonus question, I would like to ask, if I want to have an array of non-default-constractible objects, can I safely replace QVector<T>

Appending to PATH in a Windows Docker container

拈花ヽ惹草 提交于 2019-11-29 10:14:28
I need to append to the PATH within a Windows Docker container, and I've tried many permutations. ENV PATH=%PATH%;C:\\Foo\\bin ENV PATH=$PATH;C:\\Foo\\bin ENV PATH="%PATH%;C:\Foo\bin" ENV PATH="$PATH;C:\Foo\bin" RUN "set PATH=%PATH%;C:\Foo\bin" None of these work: they don't evaluate the preexisting PATH variable. What is the right syntax to append to the PATH? Can I even append to the PATH inside Docker? (I can on similar Linux containers) Unfortunately ENV won't work, because windows environment variable work a little differently than linux. more info As of now the only way to do this is

Could multiple proxy classes make up a STL-proof bitvector?

你。 提交于 2019-11-29 09:36:20
It's well known that std::vector<bool> does not satisfy the Standard's container requirements, mainly because the packed representation prevents T* x = &v[i] from returning a pointer to a bool. My question is: can this be remedied/mitigated when the reference_proxy overloads the address-of operator& to return a pointer_proxy? The pointer-proxy could contain the same data as the reference_proxy in most implementations, namely a pointer into the packed data and a mask to isolate the particular bit inside the block pointed to. Indirection of the pointer_proxy would then yield the reference_proxy.

How to increase the size of the /dev/shm in docker container

五迷三道 提交于 2019-11-29 09:10:13
Currently When I create new docker container the size of the shared memory directory is limited to 64MB. But, I need to increase this size since my application depend on this shared memory. Is there any way to increase the size of /dev/shm in docker container? I heard that the 64MB is hard coded in the docker code, How to install docker from source and change the value of the /dev/shm? Lijo Jacob You can modify shm size by passing the optional parameter --shm-size to docker run command. The default is 64MB. eg: docker run -it --shm-size=256m oracle11g /bin/bash If you use docker-compose to set

Is there a sorted container in the STL?

不想你离开。 提交于 2019-11-29 09:06:47
Is there a sorted container in the STL? What I mean is following: I have an std::vector<Foo> , where Foo is a custom made class. I also have a comparator of some sort which will compare the fields of the class Foo . Now, somewhere in my code I am doing: std::sort( myvec.begin(), myvec.end(), comparator ); which will sort the vector according to the rules I defined in the comparator. Now I want to insert an element of class Foo into that vector. If I could, I would like to just write: mysortedvector.push_back( Foo() ); and what would happen is that the vector will put this new element according

How can I shift elements inside STL container

余生颓废 提交于 2019-11-29 07:13:50
I want to shift elements inside container on any positions to the left or right. The shifting elements are not contiguous. e.g I have a vector {1,2,3,4,5,6,7,8} and I want to shift {4,5,7} to the left on 2 positions, the expected result will be {1,4,5,2,7,3,6,8} Is there an elegant way to solve it ? You can write your own shifting function. Here's a simple one: #include <iterator> #include <algorithm> template <typename Container, typename ValueType, typename Distance> void shift(Container &c, const ValueType &value, Distance shifting) { typedef typename Container::iterator Iter; // Here I

Spark on YARN resource manager: Relation between YARN Containers and Spark Executors

只愿长相守 提交于 2019-11-29 06:50:08
问题 I'm new to Spark on YARN and don't understand the relation between the YARN Containers and the Spark Executors . I tried out the following configuration, based on the results of the yarn-utils.py script, that can be used to find optimal cluster configuration. The Hadoop cluster (HDP 2.4) I'm working on: 1 Master Node: CPU: 2 CPUs with 6 cores each = 12 cores RAM: 64 GB SSD: 2 x 512 GB 5 Slave Nodes: CPU: 2 CPUs with 6 cores each = 12 cores RAM: 64 GB HDD: 4 x 3 TB = 12 TB HBase is installed