#include <set>
#include <map>
+#include <algorithm> // std::copy
+#include <iterator> // std::ostream_iterator
+
typedef unsigned int spin_t;
typedef std::set<spin_t> mutset_t; // virus is defined by set of mutations
typedef std::map<mutset_t,int> pop_t; // number of each virus species
+/*
+ * print a set of mutations to stream as a CSV-like string
+ */
+std::ostream& operator<<(std::ostream& os, mutset_t v)
+{
+ mutset_t::iterator i = v.begin(), end = v.end();
+ os << *i; // print first element
+ for (++i; i != end; ++i) // then with comma as prefix
+ os << ',' << *i;
+ return os;
+}
+
int main(int argc, char **argv)
{
Pop[s] = 100;
Pop[s] += 50;
- std::cout << *Pop.begin()->first.begin() << ' ' << Pop.begin()->second << std::endl;
+ for(pop_t::iterator vi = Pop.begin(); vi != Pop.end(); ++vi) {
+ mutset_t v = vi->first;
+
+ /*
+ // appends "," to each element
+ std::ostream_iterator<int> output(std::cout, ",");
+ std::copy(v.begin(),v.end(), output);
+ */
+ /*
+ // appends "," to each element
+ for(mutset_t::iterator i = v.begin(); i != v.end(); ++i) {
+ std::cout << (*i) << ",";
+ }
+ */
+ /*
+ // prefix every element (except the first) with ","
+ mutset_t::iterator i = v.begin(), end = v.end();
+ std::cout << *i;
+ for (++i; i != end; ++i)
+ std::cout << ',' << *i;
+ std::cout << ' ';
+ */
+ ///*
+ // proper printing function
+ std::cout << v << ' ';
+ //*/
+
+ std::cout << vi->second << std::endl;
+ }
return 0;
}