I would like to have two template structs for converting any Variant type to std::strings
;
While the first one compiles, the second one will not compile, at the vector<Variant>::iterator statement
. The compiler says:
error: expected ';' after expression
vector<Variant>::iterator i = data.begin();
Any idea what am I doing wrong? Is there a better way for what I am trying to do here?
template <typename Variant>
struct to_string
{
private:
Variant data;
public:
to_string(Variant &d) : data(d) {}
operator std::string() const
{
try
{
return boost::lexical_cast<std::string>(data);
}
catch (const boost::bad_lexical_cast &)
{
return std::string();
}
}
};
template <typename Variant>
struct to_string_vector
{
private:
vector<Variant> data;
public:
to_string_vector(vector<Variant> &d) : data(d) {}
operator vector<std::string> () const
{
vector<string> ret;
vector<Variant>::iterator i = data.begin();
to_string t_s<Variant> s = to_string<Variant>(*i);
ret.push_back((string)s);
return ret;
}
};