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

How to insert a pair of elements as single elements in a set container?

My simple code is like this : #include #include using namespace std; void main() { set myset; myset.insert(pair("abc","def")); cout<
Biswajit
  • 339
  • 1
  • 4
  • 9
0
votes
2 answers

Subclassing std::pair and std::map in C++

#include #include #include #include using namespace std; class MyPair: public pair { int _ref; public: MyPair(): pair(), _ref(0) {} …
Andy Autida
  • 449
  • 1
  • 5
  • 5
0
votes
1 answer

Unpacking std::pair>> to tuple

So I'm trying to come up with a function which converts a; std::pair> data type, into a std::tuple; std::tuple It should work in the general case, with an arbitrary number of mixed type arguments, the format for the pairs…
Skeen
  • 4,614
  • 5
  • 41
  • 67
0
votes
1 answer

How to fill and access to std::map, funcPtr>?

I would like to know how to fill this type of map and mainly the way to access to the function pointer. The map : enum enum1 { val11, val12, val13 }; enum enum2 { val21, val22, val23 }; typedef…
Elfayer
  • 4,411
  • 9
  • 46
  • 76
0
votes
1 answer

How to populate a mapped multimap?

I have the following mapped multimap : map>> modCreAlt; I am trying to insert a line in it : int priority = ... ; string alertInv = ... ; string upperAlertInv = ... ; modCreAlt.insert(make_pair(42,…
Pierre Espenan
  • 3,996
  • 5
  • 33
  • 51
0
votes
3 answers

std::make_pair: "cannot convert ‘int*’ to ‘std::pair*’ in initialization"

In below listed function, I am trying create a pointer to an std::pair object where I get a compilation error shown at the bottom of this message (The related line number has been marked in the code snippet below). Could you please tell me what's…
F. Aydemir
  • 2,665
  • 5
  • 40
  • 60
0
votes
2 answers

'std::pair' : use of class template requires template argument list

I'm trying to create an unordered_map whose key would be a member of the Gdiplus::Color class and a float but i can't figure why i can't do this. This is my declaration std::unordered_map
0
votes
2 answers

Is there any performance loss for tuple with only 2 elements?

Compared with pair, is there any performance loss for tuple with only 2 elements?
user1899020
  • 13,167
  • 21
  • 79
  • 154
0
votes
3 answers

How to change pair (> and <) operators behavior?

I'm trying to sort a vector< pair > but i want to change the behavior of the comparison operators of the pair type , so that if the first values equal and it'a comparing with (>) operator, i want it to compare the second value with (<)…
Ali Essam
  • 502
  • 1
  • 7
  • 17
0
votes
4 answers

How can you pass a vector > into a function?

If I try to declare the function as void some_function(vector > theVector), I get an error (presumably from the comma after "pair #include…
Bob John
  • 3,688
  • 14
  • 43
  • 57
0
votes
2 answers

Accessing a nested pair

To take apart a pair, the following can be done boost::bind(&std::pair::second, _1); // returns the value of a pair What about using combinations of different containers, how can a nested pair be accessed? For example when I wanted to partition a…
Peter Nimmo
  • 1,045
  • 2
  • 12
  • 25
0
votes
2 answers

Using Node in Map, C++

class MtmMap { public: class Pair { public: Pair(const KeyType& key, const ValueType& value) : first(key), second(value) { } const KeyType first; …
Christine
  • 113
  • 3
  • 9
0
votes
1 answer

Pointer in a pair in C++

I need to return an array and it's size: pair load(string path,int * memory){ ifstream handle; int container; int size = 0; if(!handle){ QMessageBox::warning(0, QString(""), "file cannot be loaded"); …
Ben
  • 3,989
  • 9
  • 48
  • 84
0
votes
2 answers

C++ heap sort of vector

I can not figure out where I'm having my problem with my heap sort. The program takes a filename from the command line, imports the words into a vector then that vector is turned into a vector pair of vector where string is the word and…
Ryan
  • 167
  • 1
  • 3
  • 12
0
votes
1 answer

Poor performance of GNU C++ compiler while sorting vector of pairs, compared with Intel

I have a vector of pairs in my program, which I need to sort. Something as: std::vector > temp; ... std::sort(temp.begin(), temp.end()); I performed some measurements and found out that for vector of size something over…
Daniel Langr
  • 22,196
  • 3
  • 50
  • 93