audio - lambda function c++ 11 -


any idea how rewrite lambda function pre c++11?

    if (maxvol != 0)        std::transform(&spec[0], &spec[samplesize], &spec[0]                      , [maxvol] (float db) -> float {   return db / maxvol; }); 

the code http://katyscode.wordpress.com/2013/01/16/cutting-your-teeth-on-fmod-part-4-frequency-analysis-graphic-equalizer-beat-detection-and-bpm-estimation

thanks

origional code:

if (maxvol != 0)        std::transform(&spec[0], &spec[samplesize], &spec[0], [maxvol] (float db) -> float {   return db / maxvol; }); 

lambda:

[maxvol] (float db) -> float {   return db / maxvol; } 

replacement lambda:

struct percent_of {     //that lambda captures maxvol copy when constructed     percent_of(float maxvol) : maxvol(maxvol) {}      //the lambda takes "float db" , returns float     float operator()(float db) const { return db / maxvol; } private:     float maxvol; }; 

replacement full code:

if (maxvol != 0)        std::transform(&spec[0], &spec[samplesize], &spec[0], percent_of(maxvol)); 

however, lambda simple, built standard library. pre-c++11 had these exact same bits in boost.

if (maxvol != 0) {     using std::placeholders::_1;     auto percent_of = std::bind(std::divides<float>(), _1, maxvol);     std::transform(&spec[0], &spec[samplesize], &spec[0], percent_of); } 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -