diff --git a/cpp/exports.hpp b/cpp/exports.hpp index c6128061badfc045b382378814af6b0c2921cf88..58a682ccb6d467bfddd064669fd7f762dbffb095 100644 --- a/cpp/exports.hpp +++ b/cpp/exports.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include "graph.hpp" std::ostream &operator<<(std::ostream &s, const Edge &e) { @@ -22,3 +23,36 @@ std::ostream &operator<<(std::ostream &s, const Graph &g) { return s; } +template +std::ostream& operator<<(std::ostream& s, const std::vector& v) { + if (v.empty()) { + s << '{' << '}'; + return s; + } + auto iter = v.begin(); + s << '{' << *iter++; + for (; iter != v.end(); ++iter) { + s << ',' << *iter; + } + s << '}'; + return s; +} + +// Mathematica style export for 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::value, T>::type> +std::ostream& operator<<(std::ostream& s, const T (&v)[N]) { + if (N == 0) { + s << '{' << '}'; + return s; + } + s << '{' << v[0]; + for (size_t i = 1; i < N; ++i) + s << ',' << v[i]; + s << '}'; + return s; +} +