[C++-sig] returning vector arrays and multiple values

Stefan Seefeld seefeld at sympatico.ca
Thu Oct 23 16:03:03 CEST 2008


Leonard Ritter wrote:
> i have a function which i wish to wrap, which returns a float buffer 
> and an integer:
>
> std::vector<float> get_recording_buffer(/* out */ size_t &write_ptr);
>
> alternatively, the function could also just return a pointer to a 
> float array:
>
> const float *get_recording_buffer(/* out */ size_t &size, /* out */ 
> size_t &write_ptr);
>
> the signature doesn't matter as much as the intention here.
>
> using boost.python, how can i export the method so its appropriate 
> python counterpart would be something like:
>
> def get_recording_buffer():
>     return (<float list or tuple>, <int>)
object get_recording_buffer_wrapper()
{
  size_t write_ptr;
  std::vector<float> buffer = get_recording_buffer(write_ptr);
  list l;
  for (std::vector::iterator i = buffer.begin(); i != buffer.end(); ++i)
    l.append(*i);
  return make_tuple(l, write_ptr);
}


HTH,
       Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list