Files
@ 530154e12814
Branch filter:
Location: AENC/switchchain/cpp/exports.hpp - annotation
530154e12814
1.9 KiB
text/x-c++hdr
Add Histogram class
0f3a4ccb62ea 44016ac335ea 530154e12814 44016ac335ea f8cbbd135cc1 bfca8e3039c5 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 0f3a4ccb62ea 634d9c963986 634d9c963986 634d9c963986 634d9c963986 634d9c963986 634d9c963986 44016ac335ea 44016ac335ea 44016ac335ea 44016ac335ea bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 44016ac335ea 44016ac335ea 44016ac335ea bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 44016ac335ea 44016ac335ea 44016ac335ea 44016ac335ea 44016ac335ea 44016ac335ea bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 bfca8e3039c5 44016ac335ea bfca8e3039c5 44016ac335ea bfca8e3039c5 bfca8e3039c5 44016ac335ea 44016ac335ea 44016ac335ea 44016ac335ea 530154e12814 530154e12814 530154e12814 530154e12814 530154e12814 530154e12814 | #pragma once
#include "graph.hpp"
#include "histogram.hpp"
#include <array>
#include <iostream>
#include <vector>
std::ostream &operator<<(std::ostream &s, const Edge &e) {
s << '{' << e.u << ',' << e.v << '}';
return s;
}
// Mathematica style export
std::ostream &operator<<(std::ostream &s, const Graph &g) {
if (g.edgeCount() == 0) {
s << '{' << '}';
return s;
}
s << '{' << g.getEdge(0).u << '<' << '-' << '>' << g.getEdge(0).v;
for (unsigned int i = 1; i < g.edgeCount(); ++i) {
const Edge &e = g.getEdge(i);
s << ',' << e.u << '<' << '-' << '>' << e.v;
}
s << '}';
return s;
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2>& p) {
s << '{' << p.first << ',' << p.second << '}';
return s;
}
template <typename FwdIterator>
std::ostream& output_array(std::ostream& s, FwdIterator begin,
FwdIterator end) {
if (begin == end) {
s << '{' << '}';
return s;
}
s << '{' << *begin++;
for (; begin != end; ++begin) {
s << ',' << *begin;
}
s << '}';
return s;
}
template <typename T>
std::ostream& operator<<(std::ostream& s, const std::vector<T>& v) {
return output_array(s, std::begin(v), std::end(v));
}
// Mathematica style export for normal arrays
// SFINAE to disable char arrays since it will mess up
// things of the form s << "some string";
template <
typename T, std::size_t N,
typename = typename std::enable_if<!std::is_same<T, char>::value>::type>
std::ostream& operator<<(std::ostream& s, const T (&v)[N]) {
return output_array(s, std::begin(v), std::end(v));
}
template <typename T, std::size_t N>
std::ostream& operator<<(std::ostream& s, const std::array<T, N>& v) {
return output_array(s, std::begin(v), std::end(v));
}
std::ostream &operator<<(std::ostream &s, const Histogram &h) {
s << h.getHistogram();
return s;
}
|