我想将 的值转换std::variant
为std::string
,但此代码不起作用:
using AnyType = std::variant <bool, char, integer, double, std::string, std::vector <AnyType>/*, Object, Extern, InFile*/>;
struct AnyGet {
AnyGet() {}
std::string operator()(std::string& result, const bool& _ctx) { return _ctx ? "true" : "false"; }
std::string operator()(std::string& result, const char& _ctx) { return std::string(1, _ctx); }
std::string operator()(std::string& result, const integer& _ctx) { return std::to_string(_ctx); }
std::string operator()(std::string& result, const double& _ctx) { return std::to_string(_ctx); }
std::string operator()(std::string& result, const std::string& _ctx) { return _ctx; } …
Run Code Online (Sandbox Code Playgroud)