containers

c++ template class; function with arbitrary container type, how to define it?

╄→гoц情女王★ 提交于 2019-11-27 18:34:55
Okay, simple template question. Say I define my template class something like this: template<typename T> class foo { public: foo(T const& first, T const& second) : first(first), second(second) {} template<typename C> void bar(C& container, T const& baz) { //... } private: T first; T second; } The question is about my bar function... I need it to be able to use a standard container of some sort, which is why I included the template/typename C part, to define that container type. But apparently that's not the right way to do it, since my test class then complains that: error: 'bar' was not

To STL or !STL, that is the question [closed]

本秂侑毒 提交于 2019-11-27 17:31:07
Unquestionably, I would choose to use the STL for most C++ programming projects. The question was presented to me recently however, "Are there any cases where you wouldn't use the STL?"... The more I thought about it, the more I realized that perhaps there SHOULD be cases where I choose not to use the STL... For example, a really large, long term project whose codebase is expected to last years... Perhaps a custom container solution that precisely fits the projects needs is worth the initial overhead? What do you think, are there any cases where you would choose NOT to STL? Projects with

Can end() be a costly operation for stl containers

情到浓时终转凉″ 提交于 2019-11-27 17:24:20
问题 On https://doc-snapshots.qt.io/qtcreator-extending/coding-style.html it is recommended to write for loops like the following: Container::iterator end = large.end(); for (Container::iterator it = large.begin(); it != end; ++it) { //...; } instead of for (Container::iterator it = large.begin(); it != large.end(); ++it) { //...; } Since I have rarely seen this style in any code, I would like to know whether the consecutive call of end() really adds a noticeable run-time overhead for large loops

c++ deque vs queue vs stack

本小妞迷上赌 提交于 2019-11-27 17:19:39
Queue and Stack are a structures widely mentioned. However, in C++, for queue you can do it in two ways: #include <queue> #include <deque> but for stack you can only do it like this #include <stack> My question is, what's the difference between queue and deque, why two structures proposed? For stack, any other structure could be included? 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,

How to get the list of dependent child images in Docker?

孤人 提交于 2019-11-27 17:09:19
I'm trying to remove an image and I get: # docker rmi f50f9524513f Failed to remove image (f50f9524513f): Error response from daemon: conflict: unable to delete f50f9524513f (cannot be forced) - image has dependent child images This is the docker version: # docker version Client: Version: 1.10.3 API version: 1.22 Go version: go1.5.3 Git commit: 20f81dd Built: Thu Mar 10 21:49:11 2016 OS/Arch: linux/amd64 Server: Version: 1.10.3 API version: 1.22 Go version: go1.5.3 Git commit: 20f81dd Built: Thu Mar 10 21:49:11 2016 OS/Arch: linux/amd64 but there is no extra information: # docker images -

Container of fixed dynamic size

吃可爱长大的小学妹 提交于 2019-11-27 15:34:04
问题 Is there a standard container for a sequence of fixed length, where that length is determined at runtime. Preferrably, I'd like to pass an argument to the constructor of each sequence element, and use that argument to initialize a const member (or a reference). I'd also like to obtain the sequence element at a given index in O(1). It seems to me that all of my requirements cannot be met at the same time. I know std::array has fixed length, but that length has to be known at compile-time. std:

What is an iterator's default value?

蹲街弑〆低调 提交于 2019-11-27 14:55:56
For any STL container that I'm using, if I declare an iterator (of this particular container type) using the iterator's default constructor, what will the iterator be initialised to? For example, I have: std::list<void*> address_list; std::list<void*>::iterator iter; What will iter be initialised to? 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,

Get fragment's container view id

北城余情 提交于 2019-11-27 13:40:57
问题 I have a fragment added using transaction.add(R.id.content, fragment, null); and I need to start new fragment from this one. But to do this I need to know first fragment's container view id (R.id.content in my case). How can I get this? I can just use this id directly but I suppose fragment shouldn't know such kind of details about parent activity. For example it will be impossible to use this fragment in another activity in this case. May be "starting" fragment from another one is a bad

stop and delete docker container if its running

血红的双手。 提交于 2019-11-27 12:55:09
问题 I am looking to pragmatically stop and delete a docker container if it is running. This is for a build script. Take the following example. How would I stop and delete the docker container "rabbitmq" as seen under the NAMES column in a bash script. docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9909a5e2856f rabbitmq-image "/docker-entrypoint.s" 11 minutes ago Up 11 minutes 0.0.0.0:5672->5672/tcp, rabbitmq 8990dd1fe503 redis-image "/entrypoint.sh redis" 6 weeks ago Up 4 days 0

What are the containers in Java

雨燕双飞 提交于 2019-11-27 12:30:36
问题 Could anyone please give me a brief full list of containers in Java? Some of the ones I know are Array, Arraylist, Hashtable, HashMap, HashSet, Node, NodeList, TreeNode, and TreeMap. 回答1: essentially, all the docs about java "containers", or better known as collections, is here, with the most useful page being this one, brief list here. There are other implementations of the collections framework, like the fastutils framework that gives better performance if you knew the type you were going