stdpair

Safe To Modify std::pair<U, V>::first in vector of pairs?

I'm currently working on a DNA database class and I currently associate each row in the database with both a match score (based on edit distance) and the actual DNA sequence itself, is it safe to modify first this way within an iteration loop? typedef std::pair<int, DnaDatabaseRow> DnaPairT; typedef std::vector<DnaPairT> DnaDat...

std::pair<int, int> vs struct with two int's

In an ACM example, I had to build a big table for dynamic programming. I had to store two integers in each cell, so I decided to go for a std::pair<int, int>. However, allocating a huge array of them took 1.5 seconds: std::pair<int, int> table[1001][1001]; Afterwards, I have changed this code to struct Cell { int first; int s...

union members may not have constructors, but `std::pair` okay?

union members may not have destructors or constructors. So I can't template the following class Foo on my own MyClass if MyClass has a constructor: template<class T> struct Foo { T val; Foo(T val_) : val(val_) {} size_t hash() const { union {T f; size_t s;} u = { val }; return u.s; } }; struct MyClass { bool a; doubl...

converting an integer to a std::string accepted by an std::pair

I have this function that converts an integer to a std::string: std::string intToStr(const int n) { stringstream ss; ss << n; return ss.str(); } It's worked well so far, but now I'm trying to construct a string to put into a std::pair, and I'm having some trouble. Given an integer variable hp and a function that returns a...

How to convert a sorted std::list of std::pair to a std::map

Hello! I have got a std::list< std::pair<std::string,double> >, which I know is sorted according to the std::string element. Since I would like to do a lot of std::find_if based on the std::string element, I believe a std::map<string,double,MyOwnBinaryPredicate> with lower_bound and upper_bound would be more adequate. The fact is tha...