[C++-sig] Converting std::vector<T> to Python tuple

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Nov 21 21:22:10 CET 2002


--- "Paul F. Kunz" <Paul_Kunz at SLAC.Stanford.EDU> wrote:
>   to_python_converter < 
>     const std::vector < double >,
>     to_tuple < const std::vector < double > >  > ();
> 
>   to_python_converter <
>     const std::vector < std::string >,
>     to_tuple < const std::vector < std::string > >  > ();
> 
> Is this correct?   Suggestion for improvements?

It looks great. I don't think you need the "const" but maybe it doesn't do any
harm. There isn't much to improve. If you need more std::vector<> tuple
mappings you could create your own little helper struct to cut down on the
redundancy, along the lines of (untested)

template <typename T>
std_vector_to_tuple
{
  std_vector_to_tuple()
  {
    to_python_converter <
      std::vector<T>,
      to_tuple<std::vector<T> > >();
  }
};

Then:

  std_vector_to_tuple<double>();
  std_vector_to_tuple<std::string>();
 
> If this is correct, may I suggest that something like it go into the
> tutorial and/or FAQ.

Contributions from the community are highly appreciated.

Ralf


__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com




More information about the Cplusplus-sig mailing list