#ifndef __x_to_string_h__ #define __x_to_string_h__ #include #include #include #include #include #include "ranges/dynamic_meta.h" namespace CNORXZInternal { 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 CNORXZ::DynamicMetaT; template <> inline std::string xToString(const DynamicMetaT& x); template inline std::string xToString(const 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) { std::string out = std::to_string(x); std::replace(out.begin(), out.end(), ',', '.'); return out; } 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 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