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
34
votes
9 answers

How can I store objects of differing types in a C++ container?

Is there a C++ container that I could use or build that can contain, say, int and string and double types? The problem I'm facing is that whenever I try to populate, say, a map, vector or list with, say, the following: int x; string y; double…
Ramsey
  • 375
  • 1
  • 3
  • 5
34
votes
3 answers

Do STL iterators guarantee validity after collection was changed?

Let's say I have some kind of collection and I obtained an iterator for the beginning of it. Now let's say I modified the collection. Can I still use the iterator safely, regardless of the type of the collection or the iterator? To avoid confusion,…
user88637
  • 11,790
  • 9
  • 37
  • 36
34
votes
4 answers

Container of fixed dynamic size

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…
MvG
  • 57,380
  • 22
  • 148
  • 276
33
votes
3 answers

Generic iterator

I am trying to find a generic way of accessing a set of containers. I have a standard vector and list in addition to another custom list. The custom list defines an iterator; class Iterator: public std::iterator { …
Mark
  • 456
  • 1
  • 6
  • 8
33
votes
2 answers

How to run AWS ECS Task overriding environment variables

To override environment variables via CLI we may use --overrides (structure) according to AWS ECS Commandline Reference. How to pass name value pairs (structure or JSON) in command line? [ { "name" : "NAME", "value" : "123" }, { "name" :…
sithumc
  • 3,254
  • 8
  • 27
  • 46
33
votes
2 answers

How to remove a specific pair from a C++ multimap?

#include ... multimap mymap; mymap.insert(pair('a',10)); mymap.insert(pair('b',15)); mymap.insert(pair('b',20)); mymap.insert(pair('c',25)); Say I now want to remove one of the pairs I have…
Jim Blackler
  • 22,946
  • 12
  • 85
  • 101
33
votes
2 answers

Copy std::vector into std::array

How do I copy or move the first n elements of a std::vector into a C++11 std::array?
LocalToast
  • 397
  • 1
  • 5
  • 13
32
votes
5 answers

Partial match for the key of a std::map

I have an std::map and I want to search for a key using a substring. For example, I have the following code: #include #include #include using namespace std; typedef std::map TStrStrMap; typedef…
cateof
  • 6,608
  • 25
  • 79
  • 153
32
votes
6 answers

What is the major difference between a vector and a stack?

Both act like a stack. Both have push and pop operations. Is the difference in some memory layouts?
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
32
votes
2 answers

Best string container: StringCollection, Collection, List, ArrayList, ..?

What is the most suitable container just for strings holding in some array with non-predetermined upper boundary, which length is unknown on it's creation. For simple code like: var list = new SomeContainer(); // size is…
abatishchev
  • 98,240
  • 88
  • 296
  • 433
32
votes
8 answers

Adding Shadows at the bottom of a container in flutter?

I have a simple screen with a container about 100 in height and with blue color. I want to add a shadow or elevation at the bottom of the container. This is my code below import 'package:flutter/material.dart'; import…
yoohoo
  • 1,147
  • 4
  • 22
  • 39
32
votes
2 answers

Monitor custom kubernetes pod metrics using Prometheus

I am using Prometheus to monitor my Kubernetes cluster. I have set up Prometheus in a separate namespace. I have multiple namespaces and multiple pods are running. Each pod container exposes a custom metrics at this end point, :80/data/metrics . I…
32
votes
6 answers

How to get Task ID from within ECS container?

Hello I am interested in retrieving the Task ID from within inside a running container which lives inside of a EC2 host machine. AWS ECS documentation states there is an environment variable ECS_CONTAINER_METADATA_FILE with the location of this data…
code
  • 5,294
  • 16
  • 62
  • 113
31
votes
19 answers

Docker daemon is not running

Newbie in this area. I have installed the new version of Docker in my windows PC. I am using windows 10 Pro. I have tried the very basic docker command but it is not working. I have also run the docker as administrator. Getting the below error…
TAMIM HAIDER
  • 641
  • 1
  • 10
  • 19
31
votes
5 answers

Docker can't connect to Container exposed port

SCENARIO: Hey there,I'm running a docker compose with containers. This compose file works like charm on ma local docker desktop on windows 10. I configured my own network with network driver bridge. Now I want to run the docker compose on an…
FishingIsLife
  • 1,972
  • 3
  • 28
  • 51