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

Dereference the first part of the pair object for an unordered map

I have a C++ 03 compliant compiler. I am using a pair object when inserting the element into an unordered map using the following code: unordered_map mymap; pair::iterator,bool> ret; ret =…
user1593881
0
votes
1 answer

Extending std::vector> with own functionality

My C++11 is too weak to find a solution. I have lot of std::vector> variables in my project and therefore the code to check if an entry does exist repeats: std::vector>…
Peter VARGA
  • 4,780
  • 3
  • 39
  • 75
0
votes
1 answer

Using arrays in std::pair to extend the amount of data

I'm trying to extend someone else's code which is using std::queue and std::pair types pretty frequently. For the following code, I need to extend the number of variables in std::pair.second and prefer it to be more flexible for number of variables…
0
votes
2 answers

c++ Sorting a vector based on values of other vector, or what's faster?

There are a couple of other posts about sorting a vector A based on values in another vector B. Most of the other answers tell to create a struct or a class to combine the values into one object and use std::sort. Though I'm curious about the…
pollux
  • 779
  • 2
  • 14
  • 30
0
votes
1 answer

A vector of pairs: first pair values are non-sorted and second pair values are sorted: how to find a sorted value when having the non-sorted one

I have a vector of pairs, as shown below. First pair values are non-sorted and second pair values are sorted (starting from zero). I might want to store data by implementing std::vector and std::pair. When I have a first pair value (non-sorted),…
Megidd
  • 7,089
  • 6
  • 65
  • 142
0
votes
1 answer

C++ Using a lambda in find_if to find pair variables

So I'm having trouble understanding lambdas and how they work, specifically if i have a std::vector> storage; and want to write a function that looks like bool VNS::remove(const std::string& host) { auto end =…
enrm
  • 645
  • 1
  • 8
  • 22
0
votes
1 answer

C++ adding std::pair to template base class

I have a weird behavior in C++ code. I have an abstract base class Symbolic: template class Symbolic { protected: vector > monomials; public: virtual ~Symbolic() {} virtual ostream &print(ostream &o) const…
0
votes
1 answer

Can not Create pair - constructor

I can not create a pair when one of the classes in the pair in a class Edge I know it is because of the constructors in Edge, but I do not know what is wrong. The Edge constructor has a Token because I wanted to make sure that only an Object of type…
Bojack
  • 459
  • 1
  • 5
  • 18
0
votes
1 answer

Map, pair-vector or two vectors...?

I read through some posts and "wikis" but still cannot decide what approach is suitable for my problem. I create a class called Sample which contains a certain number of compounds (lets say this is another class Nuclide) at a certain relative…
LCsa
  • 607
  • 9
  • 30
0
votes
1 answer

#include in dev c++ header file

i am trying to create a header file in c++ with the following code #ifndef dictionary_h #define dictionary_h #include using namespace std; template class dictionary { virtual bool empty() const=0; virtual int…
Pradeep
  • 1,193
  • 6
  • 27
  • 44
0
votes
1 answer

Multiset of pair, find

I need to find and erase a value in mutliset of pair sorted by my own function. Apparently, .find always returns the iterator to the end, not to the searched value. Any tips? This is the function : struct cmp { bool operator() (const para &a,…
Muco
  • 27
  • 9
0
votes
1 answer

Read file (containing int, string) to vector of pairs using ifstream

I'm trying to read a text file into a vector of pairs. The text file contains the following: The first line tells, how many strings there are. The second line is an int, telling how many characters there are in the (first) string. And then, the…
Elska
  • 1
  • 4
0
votes
3 answers

Confused of declaring this kind of array

I was reading this code there is a line : pair approach[1 << 18][17] I don't know what is the meaning of this declaration : approach[ 1<<18 ][17]; Can anyone help?
Kadaj13
  • 1,423
  • 3
  • 17
  • 41
0
votes
1 answer

Run length encoding a vector

I have been reading on the forum many times before but today I cannot figure out why I am having an error in my code so if anyone can point out to why I am getting these errors I would be thankful. I am new to template and do not understand why…
Rooth
  • 5
  • 2
0
votes
2 answers

Compiler error when constructing a vector of pairs

Please can someone help explain why I get an error when compiling the following code using Xcode 5.1 on OS X. Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn). I want construct X below, passing it a vector of pairs. #include…
ksl
  • 4,519
  • 11
  • 65
  • 106