C++ copy_if lambda capturing std::string

Viewed 4967

This is a follow up question from here: C++ - Developing own version of std::count_if?

I have the following function:

// vector for storing the file names that contains sound 
std::vector<std::string> FilesContainingSound; 

void ContainsSound(const std::unique_ptr<Signal>& s)
{
    // Open the Wav file 
    Wav waveFile = Wav("Samples/" + s->filename_); 

    // Copy the signal that contains the sufficient energy 

    std::copy_if(waveFile.Signal().begin(), waveFile.Signal().end(), 
                 FilesContainingSound.begin(), [] (const Signal& s) {

                     // If the energy bin > threshold then store the 
                     // file name inside FilesContaining
                 }
}

But to me, I only need to capture the string "filename" inside of the lambda expression, because I'll only be working with this. I just need access to the waveFile.Signal() in order to do the analysis.

Anyone have any suggestions?

EDIT:

std::vector<std::string> FilesContainingSound;
std::copy_if(w.Signal().begin(), w.Signal().end(), 
             FilesContainingSound.begin(), [&] (const std::unique_ptr<Signal>& file) {

                 // If the energy bin > threshold then store the 
                 // file name inside FilesContaining
             });
1 Answers
Related