pair

Generating Random Paired Images in C#

im trying create cards matching game. normally these type of games they match paired cards together (with the same file name "A.jpg with A.jpg") but in my case, im matching cards with different names "B.jpg with A.jpg" (correct), "C.jpg with D.jpg" (correct) but with "B.jpg with C.jpg" (incorrect answer). A.jpg-B.jpg <--correct C.jpg-...

regex to check string is certain length

Hi, I am trying to write a regex to match pairs of cards (AA, KK, QQ ... 22) and I have the regex ([AKQJT2-9])\1. The problem I have is that this regex will match AA as well as AAbc etc. Is there a way to write the regex such that I can specify I want to match ([AKQJT2-9])\1 and only that (i.e. no more characters after). Thanks ...

Problem with std::map and std::pair

Hi everyone. I have a small program I want to execute to test something #include <map> #include <iostream> using namespace std; struct _pos{ float xi; float xf; bool operator<(_pos& other){ return this->xi < other.xi; } }; struct _val{ float f; }; int main() { map<_po...

Is it a good idea to index an STL map with a pair?

Hi Everyone, I'm just wondering if it is a good idea to make a data structure like std::map< std::pair<int,int>,std::string > Just wondering how the pairs would be ordered internally... :S Thanks! ...

Use of for_each on map elements

I have a map where I'd like to perform a call on every data type object member function. I yet know how to do this on any sequence but, is it possible to do it on an associative container? The closest answer I could find was this: Boost.Bind to access std::map elements in std::for_each. But I cannot use boost in my project so, is there ...

How do I create a set with std::pair thats sorted based on the ::second pair member using bind

I know I could use the following: template <typename Pair> struct ComparePairThroughSecond : public std::unary_function<Pair, bool> { bool operator ()(const Pair& p1, const Pair& p2) const { return p1.second < p2.second; } }; std::set<std::pair<int, long>, ComparePairThroughSecond> somevar; but wondered if i...

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

Hi, 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 performance of such solutions as I need to optimize code which implements bubble sort to ...

c++ pair template struct declaration ambiguity!

In definition of pair class in c++ there are two typedefs. what are they for? there are no use of them in the code! template <class T1, class T2> struct pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; pair() : first(T1()), second(T2()) {} pair(const T1& x, const T2& y) : first(x), second(y) {} t...

Using pair as key in a map (C++ / STL)

Hello, 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*> Mapa; Key p1 ("Apple", 45); Key p2 ("Berry", 20); Mapa mapa; mapa.insert(p1, "Manzana"); mapa.insert(p2, "Arandano"); return 0; } But the compiler...

converting a variable name to a string in C++

Hi, 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 a file so that the first row contains the headings 'data1' and 'data2' followed by the actual contents. The function which outputs the data will b...

python:[[1,2],[3,4],[5,6],[7,8]] transform into [[1],[2,3],[4,5],[6,7],[8]] and vice versa

my current solution-pointers would be ether via a iterator class which yields the new assembled inner lists or via a iter function which yields the new assembled inner lists is there another, better way to solve this challenge? Edit @Glenn: good objection. I wasn't thinking of that because I experienced lists not ordered in the ma...

Equivalent of C++ STL container "pair<T1, T2>" in Objective-C?

Hi guys, I'm new to Objective-C, so please don't judge me too much. I was wondering: Is there an equivalent of the C++ STL pair container I can use in Objective-C? I want to build an array that contains an NSInteger associated to an NSBool. I know I could use an array with each entry being a NSDictionary with a single key-value but I f...

struct with 2 cells vs std::pair ?

Possible Duplicate: What is the difference between using a struct with two fields and a pair? Dear all, I have a little question about pairs and struct. Is there any advantage to use a std::pair instead of a struct with two cells ? I have used pairs for a while but the main problem is readability : If you want to represent fo...

Is it possible to "constify" a field of `std::pair` without hacks?

In C++, the compiling the following code: std::pair <int, int> x; static_cast <std::pair <const int, int>*> (&x); gives an error: error: invalid static_cast from type ‘std::pair<int, int>*’ to type ‘std::pair<const int, int>*’ I more or less understand why it happens, as cv-qualifying a type in a template parameter list can, in pr...

Using PHP, randomly pair up group of items, not pairing any with itself, no direct pairings

Assume you have a set of items in an array. A, B, C, D, E, F, G, H Using PHP, how would you randomly pair the letters together without pairing them with a duplicate of themselves? Such as this: A->pairedLetter = G B->pairedLetter = C C->pairedLetter = E D->pairedLetter = A E->pairedLetter = B F->pairedLetter = D G->pairedLette...

Post-hoc pairwise fisher exact test

I used to have 2 factor by 2 level experiment that got made into a 3 factor by 2 level experiment. By using paste I could make 4 unique groups from my two factors and run a fisher test with the outcome being whether an organism lived or died. fisher.test(mortal$alv.dead,paste(mortal$Strain,mortal$capsule)) But then when I wanted to i...

Will this memory be freed properly ?

I have a pair pointer let us suppose std::pair< A*, B* >* pointerpair. I allocated it memory and after using the pair i call delete pointerpair. Will it also call delete A and delete B and will be freeing the memory completely ? if i only call delete A and delete B but no delete pointerpair then is it a memory leak ? ...

Java: How to write a `zip` function? What should be the return type?

What should be the return type of a zip function? (zip as in most other languages, e.g. read here) I thought about some Pair-type but that does not exist in Java. It is often states that this is because a specialized Pair-class is better than a general one (see this question). However, this is not possible in a general zip function. ...

C++ Storing copy of string in vector of pairs

I have a private attribute in a class that is defined as vector<pair<char *, int> > data;. I add data to this vector with data.push_back(make_pair(p, r));. Later when I go to get the data out of the vector I get bad data for the p value. The data returned is like ��U3. I think this is because a pointer to the char array is being stored. ...

What is an efficient algorithm for extracting bags from lists of pairs?

I have a list of pairs of objects. Objects can appear in the pair in either order. What is the most efficient algorithm (and implementation?) to find all bags (ie sets with duplicates permitted) of pairs between the same objects. For my purpose the object references can be assumed to be pointers, or names or some similar convenient, shor...