Questions tagged [containers]

A container is a class, a data structure, or an abstract data type whose instances are collections of other objects. Containers typically make use of generics or templates so that a wide variety of objects can be added.

Containers are available in most programming languages, allowing programmers to store, transfer, and read back data within a program. Common containers include arrays, lists, queues, stacks, sets, and maps, each providing different levels of efficiency for tasks such as adding or removing elements, searching for elements, or iterating through elements.

11206 questions
18
votes
2 answers

Visual Studio 2015: is a set of const pointers allowed?

We will be upgrading to VS2015 soon, and I found this in the breaking changes list: const elements The C++ standard has always forbidden containers of const elements (such as vector or set). Visual C++ 2013 and earlier accepted such containers.…
Houbie
  • 1,406
  • 1
  • 13
  • 25
18
votes
3 answers

Checking if a sequence container is contiguous in memory

Is there a way to check if a sequence container is contiguous in memory? Something like: #include #include #include #include int main() { std::cout << std::boolalpha; std::cout <<…
Daniel
  • 8,179
  • 6
  • 31
  • 56
18
votes
4 answers

WPF: How to autosize Path to its container?

I have a Path that must resize to its StackPanel container. I think…
742
  • 3,009
  • 3
  • 23
  • 18
18
votes
8 answers

check type of element in stl container - c++

how can i get the type of the elements that are held by a STL container?
Patrick Oscity
  • 53,604
  • 17
  • 144
  • 168
18
votes
3 answers

std::array instantiation error

Embarrassingly simple problem here. I am trying to use std::array and am tripping at the first hurdle with the error ... implicit instantiation of undefined template 'std::__1::array' The code that gives the error is shown below. I can…
learnvst
  • 15,455
  • 16
  • 74
  • 121
18
votes
1 answer

Difference between container and wrapper

In a programming language (e.g. Java), what's the difference between container and wrapper (or is there a difference). I've heard both the terms used vaguely.
Ank
  • 6,040
  • 22
  • 67
  • 100
18
votes
7 answers

C++ algorithm like python's 'groupby'

Are there any C++ transformations which are similar to itertools.groupby()? Of course I could easily write my own, but I'd prefer to leverage the idiomatic behavior or compose one from the features provided by the STL or boost. #include…
Brian Cain
  • 14,403
  • 3
  • 50
  • 88
17
votes
3 answers

Why don't the push_back in vector<> and list<> containers return the reference to the inserted element?

I realize I can get the iterator reference by calling back() but why not return it with push_back() as well? Is it for performance reasons? Or is it due to exception safety (similar to why pop_back() doesn't return the popped value)? In either case,…
Samaursa
  • 16,527
  • 21
  • 89
  • 160
17
votes
3 answers

What is the difference between Docker Daemon and Docker Engine?

Can some one explain the difference between the two, which contains the docker runtime?
ag07
  • 369
  • 1
  • 4
  • 9
17
votes
3 answers

Why are there no capacity argument in the constructors for the containers?

If I want to set the capacity to a std::vector I have to call .reserve(...), are there any reason why there is not a capacity argument in the constructor for the containers in stl, std::string, std::vector?
hidayat
  • 9,493
  • 13
  • 51
  • 66
17
votes
3 answers

How to fill a C++ container using a (lambda) function?

I want to initialize a container with pointers to objects. I currently have a loop like this: for(int i=0;i < n;i++) { container.push_back(new Object()); } Which C++ operation (i.e. similar to std::transform) is the right to replace this loop…
allo
  • 3,955
  • 8
  • 40
  • 71
17
votes
3 answers

How to set a time limit for a Kubernetes job?

I'd like to launch a Kubernetes job and give it a fixed deadline to finish. If the pod is still running when the deadline comes, I'd like the job to automatically be killed. Does something like this exist? (At first I thought that the Job spec's…
Bosh
  • 8,138
  • 11
  • 51
  • 77
17
votes
2 answers

How to yank to host clipboard from inside a Docker container?

I have Vim installed inside a docker container. I want to yank some text and somehow magically make it available on my host (macOS) clipboard. Is that even possible? UPDATE So to clarify, this is my full use case... docker run ... some container…
Integralist
  • 5,899
  • 5
  • 25
  • 42
17
votes
2 answers

Should I use boost::ptr_vector or vector >?

I need a container of pointers. Would you recommend boost::ptr_vector or std::vector >? (Or something else?) If that's of interest, my actual data structure is relatively complicated (see here) and currently stores objects,…
Frank
  • 64,140
  • 93
  • 237
  • 324
17
votes
1 answer

Is there a way to restrict untrusted container scheduler?

I have an application which I'd like to give the privilege to launch short-lived tasks and schedule these as docker containers. I was thinking of doing this simply via docker run. As I want to make the attack surface as small as possible, I treat…
Radek Simko
  • 15,886
  • 17
  • 69
  • 107