std-pair Questions
5
Solved
Let's say that I've got a :
#include <utility>
using namespace std;
typedef pair<int, int> my_pair;
how do I initialize a const my_pair ?
8
Solved
What is the purpose of std::make_pair?
Why not just do std::pair<int, char>(0, 'a')?
Is there any difference between the two methods?
37
Solved
Is there a good reason why there is no Pair<L,R> in Java? What would be the equivalent of this C++ construct? I would rather avoid reimplementing my own.
It seems that 1.6 is providing somet...
1
Solved
Why the C++ code below can't be compiled?
#include <utility>
int main() {
int x[6];
int y[6];
std::pair<int[6], int[6]> a(x, y);
return 0;
}
For example MSVC gives the follo...
2
Solved
Consider the following code:
#include <utility>
#include <vector>
using V = std::vector<int>;
int main() {
std::pair<int, V> p1{1, 2}; // p1.second has 2 elements
std::p...
Wilcox asked 15/3, 2023 at 14:54
3
Solved
I am creating a Map with key and value. The values have to have two separate entries.
Now the first two options that come to my mind is
either go with
Map< int,array[2] >
or
Map < in...
10
Solved
The following program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set and its member functions be used on user-defined types, and how can I defin...
Funchal asked 1/3, 2013 at 15:11
1
Solved
I have already seen Is there a one-liner to unpack tuple/pair into references? and know how the unpack values from tuple/pairs in a single line like following
auto [validity, table] = isFieldPresen...
5
Solved
I have a map like this:
map<string, pair<string, string>> myMap;
And I've inserted some data into my map using:
myMap.insert(make_pair(first_name, make_pair(middle_name, last_name)));
...
Scotty asked 28/12, 2012 at 14:24
5
Solved
I have a single even-sized vector that I want to transform into a vector of pairs where each pair contains always two elements. I know that I can do this using simple loops but I was wondering if t...
2
Solved
When compiling the following piece of code (gcc-4.8, --std=c++11):
#include <atomic>
#include <utility>
#include <cstdint>
struct X {
std::atomic<std::pair<uint32_t, uint...
5
Solved
1
Solved
I have a function f(), that returns a std::pair<A, B> with some types A and B. And I have another function g(), that calls f() twice and returns a std::tuple<A, B, A, B>. Is there a way...
3
Solved
I have
vector< pair<int, int>> myVec (N);
I want to have all pairs initialized to -1,-1.
6
Solved
I want to use a pair from STL as a key of a map.
#include <iostream>
#include <map>
using namespace std;
int main() {
typedef pair<char*, int> Key;
typedef map< Key , char*...
Byplay asked 18/7, 2010 at 20:38
6
Solved
Is there a difference between an std::pair and an std::tuple with only two members? (Besides the obvious that std::pair requires two and only two members and tuple may have more or less...)
Quadrisect asked 14/7, 2011 at 0:9
4
I know we need to include some compare function in order to achieve this.
But not able to write for this one.
For example:
Elements of vector={(2,4),(4,2),(5,1),(5,3)}
to find=5
lower_bound() ...
Hiedihiemal asked 1/6, 2014 at 15:19
8
Solved
I'd like to output some data to a file. For example assume I have two vectors of doubles:
vector<double> data1(10);
vector<double> data2(10);
is there an easy way to output this to...
Mesics asked 2/8, 2010 at 10:25
1
Solved
I tried to make std::pair with this style:
#include <iostream>
struct A {
A() noexcept {
std::cout << "Created\n";
}
A(const A&) noexcept {
std::cout << "...
5
Solved
So I have a smart iterator that emulates a map const_iterator, and it needs to build the return type internally. Obviously, I'd like to store a pair<Key, Value> in my iterator class (since I ...
Collect asked 29/11, 2011 at 4:18
4
A function needs to return two values to the caller. What is the best way to implement?
Option 1:
pair<U,V> myfunc()
{
...
return make_pair(getU(),getV());
}
pair<U,V> mypair = myfun...
6
Solved
I have C++11 program which needs to pick a value from a range of values. Each of the ranges have an assigned value to pick a value from.
Following is my range of values with assigned values for eac...
Telegu asked 31/7, 2020 at 15:40
3
Sorry for the inability to explain the primary Q in the title itself due to complexity of the problem.
Need to pass various types of std::pairs to a method like below:
foo({1, 1} , {2, 2.2}, {3, "...
Orme asked 14/7, 2016 at 9:51
10
Solved
I have a vector of pair like such:
vector<pair<string,double>> revenue;
I want to add a string and a double from a map like this:
revenue[i].first = "string";
revenue[i].second = ma...
3
Solved
Does std::map store elements as std::pair? Iterating over map looks like this:
#include <map>
int main() {
std::map<int, char> m;
m[1] = 'A';
m[2] = 'B';
m[3] = 'C';
std::map<...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.