[linux-audio-dev] C++ wrapper for libsndfile

Erik de Castro Lopo mle+la at mega-nerd.com
Sat Jul 29 13:14:44 UTC 2006

Lars Luthman wrote:

> The 4 different overloaded versions of the read, readf, write, and
> writef functions will cause ambiguities that will force you to cast them
> to their respective types in order to use pointers to them, for example
> in functors (e.g. a sigc++ slot), like this:
>   mem_fun(sndobj, (sf_count_t (Sndfile::*)(float*,
> sf_count_t))&Sndfile::read);
> If they were specialisations of the same template functions instead,
> with the sample type as template parameter, you'd only have to write
> this:
>   mem_fun(sndobj, &Sndfile::read<float>);
> which is a lot nicer and easier to read.

Interesting use case.

I'm not even close to being an expert in C++ templates, but
I suppose that read function would then be defined as something

    template <T> sf_count_t read (T *ptr, sf_count_t items) ;

SO how do I ensure that <T> only gets specialised as short,
int, float and double?

  Erik de Castro Lopo
The difference between genius and stupidity is that
  genius has its limits.

More information about the Linux-audio-dev mailing list