#ifndef __x_to_string_h__ #define __x_to_string_h__ #include #include #include #include #include "ranges/dynamic_meta.h" namespace MultiArrayHelper { template inline std::string xToString(const T& x); template <> inline std::string xToString(const char& x); template <> inline std::string xToString(const std::string& x); using MultiArrayTools::DynamicMetaT; template <> inline std::string xToString(const DynamicMetaT& x); template inline std::string xToString(const std::vector& x); template inline std::string xToString(const std::array& x); template inline std::string xToString(const std::tuple& tp); // TEMPLATE CODE template inline std::string xToString(const T& x) { return std::to_string(x); } template struct TupleToString { template static inline std::string mk(const std::tuple& tp) { return TupleToString::mk(tp) + "," + xToString(std::get(tp)); } }; template <> struct TupleToString<0> { template static inline std::string mk(const std::tuple& tp) { return xToString(std::get<0>(tp)); } }; template <> inline std::string xToString(const char& x) { std::string out = ""; return out += x; } template <> inline std::string xToString(const std::string& x) { return x; } template <> inline std::string xToString(const DynamicMetaT& x) { std::string out = "["; for(size_t i = 0; i != x.size(); ++i){ out += x[i].first; out += ","; } //out.pop_back(); out.back() = ']'; return out; } template inline std::string xToString(const std::vector& x) { std::string out = "["; for(auto& y: x){ out += xToString(y) + ","; } //out.pop_back(); out.back() = ']'; return out; } template inline std::string xToString(const std::array& x) { std::string out = "["; for(auto& y: x){ out += xToString(y) + ","; } //out.pop_back(); out.back() = ']'; return out; } template inline std::string xToString(const std::tuple& tp) { return "{" + TupleToString::mk(tp) + "}"; } } #endif