c++ - Convert a std::vector of a boost::variant type -


How do I apply the function below to convert the container to Value Can I? ? I want to claim that if all the members of value are of the same type, that is, the vector contains a mixture of strings and inti. The reason for this is that the return value of the function is either std :: vector & lt; Int & gt; or std :: vector & lt; Std :: string & gt; .

  typedef boost :: version & lt; Int, std :: string & gt; value; Typedef boost :: version & lt; Std :: vector & lt; Int & gt; Std :: vector & lt; Std :: string & gt; & Gt; Container; Container Value to Container (Constant Stroke :: Vector & lt; Value & gt; and Values) {Return Container (); }    

  outline converter_visitor: public boost: static_visitor & lt; Container & gt; {Const. Std :: vector & lt; Value & gt; & Amp; _cont; Converter_visitor (Constant Stroke :: Vector & lt; Value & gt; & amp; r): _Cont (r) {} Template & lt; Class T & gt; Container Operator () (Const T & amp) const {std :: vector & lt; T & gt; Ans; Ans.reserve (_cont.size ()); For (int i = 0; i & lt; _cont.size (); ++ i) ans.push_back (boost: get & lt; t & gt; (_ cont [i])); Answer to return; }}; Container ValuContainer (Constant Stroke :: Vector & lt; Value & gt; and Values)! Values.empty () Return Boost :: apply_visitor (converter_visitor (value), values.front ()); }   

This throws a bad_get , if all the elements of value are not of the same type.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -