Questions tagged [std-pair]

A std::pair is an ordered, heterogeneous sequence of exactly two objects (it is a special case of std::tuple).

std::pair is a part of the C++ Standard Library, defined in the header <utility>.

Reference: https://en.cppreference.com/w/cpp/utility/pair

776 questions
0
votes
1 answer

C++ error declaring std::pair inside template class

I want to avoid using the std::pair() constructor or std::make_pair() functions while inserting into a map. I also want to know the success status of the insert operation, so I cannot use operator[]. I tried the following code but it produces a…
Dinesh
  • 1,825
  • 5
  • 31
  • 40
0
votes
2 answers

Syntax to insert elements into multimap>>

My question is how to insert some element into multimap of the form multimap>> someMap; //std skipped to simplify I tried different syntaxes and i think the closest one may be this…
0
votes
1 answer

Strange memory leak while passing std::pair as argument

A constructor for my object: Visited(/*...*/, unsigned d) : /*...*/, node(new Node(make_pair(d,this))) {} Valgrind claims that: ==15806== 112 (56 direct, 56 indirect) bytes in 1 blocks are definitely lost in loss record 8 of 14 ==15806== at…
pkubik
  • 780
  • 6
  • 19
0
votes
2 answers

Push back to a static vector< pair > myVector;

I want to store an amount of information which will contain 1 string, and 9 doubles. This info will belong to one "item" so I want to sort by the name, and thus I have decided to put this into a vector of pairs, with the first section of the pair…
user3483187
  • 33
  • 1
  • 7
0
votes
1 answer

Identifier Unidentified in Default Constructor

I've been searching online a lot for how to fix this. Also tried making everything public, but I don't think that's the problem. Here's my header code: #ifndef DEALER_HPP #define DEALER_HPP #include class Dealer{ private: …
ch-pub
  • 1,664
  • 6
  • 29
  • 52
0
votes
3 answers

How to provide a default value for the first of a pair?

I'm using a pair type: typedef std::pair Nomnom; Example places it's used: void DoIt(const Nomnom &toNom) { ... } void DoItAgain(const Nomnom &toNomAgain) { ... } In my case it makes sense to offer a default value for…
Claudiu
  • 224,032
  • 165
  • 485
  • 680
0
votes
1 answer

Accesing an element in vector of pair of integer and vector

In the following code, I receive segfault at the last line: int MAX_ITER = 4, n = 5; vector< pair > > InputVector(MAX_ITER); srand((unsigned)time(NULL)); for (int i = 0; i < MAX_ITER; i++) InputVector[i].second.resize(n); for…
kamalbanga
  • 1,881
  • 5
  • 27
  • 46
0
votes
1 answer

Reading pairs of doubles from file (C++)

For a clustering program I am writing, I need to read information from a file. I am trying to read coordinates from a file with a specific format: 1.90, 2 0.0, 4.01 6, 1.00 Unfortunately, I have not been able to do this, because of the newlines and…
Knaapje
  • 165
  • 1
  • 1
  • 10
0
votes
2 answers

How can I make a vector of pairs work like a hash table?

I'm working on a 1-bit bimodal branch prediction simulator for a class project. I was thinking of using an unordered_map for the table but I need to be able to set the size, so I was thinking using a vector of pairs and table.reserve(tableSize) may…
Riptyde4
  • 5,134
  • 8
  • 30
  • 57
0
votes
1 answer

Manipulating one of the values of a vector of pairs in C++

If I have a vector of doubles PMF I can divide all elements of the vector by a double count by using the transform command as follows: transform(PMF.begin(),PMF.end(),PMF.begin(),bind2nd(divides(),count)); Now however, I have a vector of…
0
votes
1 answer

Detecting cyclic pairs

Assume a std::set< std::pair >, can somebody suggest an algorithm or approach to check whether there are cyclic pairs? e.g. std::set< std::pair > cyclic = { {'A', 'B'}, {'B', 'C'}, {'C', 'A'} }; std::set< std::pair
user2804578
  • 32
  • 1
  • 4
0
votes
3 answers

Deallocating memory of object inside a pair of a vector

I would like to know how to de-allocate memory of an object inside a pair of a vector. vector< pair > vectorObject; I did try using an iterator to iterate through all the elements, but I am unsure of how to delete an object that is…
Todd
  • 27
  • 1
  • 6
0
votes
2 answers

Get a value in a 2D Vector given a key

I have a 2D vector in which i want to use a character key to find a value. For example, Here is my vector type: vector> characters: a b c d double: 1.1 2.1 7.1 1.3 each double coorelates with a character value. I want search the…
user977154
  • 1,045
  • 4
  • 19
  • 39
0
votes
2 answers

Default specification of a C++ vector of pairs of strings as function parameter invalid on gcc-4.1.2?

This builds fine as a parameter to a function declaration on x64 VS100 (MSVC++ 2010) but fails on RHEL5 (gcc 4.1.2): const std::vector >& = std::vector >() The whole function…
0
votes
3 answers

std::set containing pair with custom comparator

I have a vector < pair >, where double represents weight of a person and int represents the id of that person. Now I need to convert it to set < pair < double, int > > to remove the duplicates based on the id of that person, but inside…
Jaydeep Solanki
  • 2,895
  • 5
  • 36
  • 50