dimanche 5 juin 2022

Retrun object from lambda

ALL,

I have a following structure:

struct Foo
{
    string name;
    long position, originalPosition;
};

I also have a vector of those structs.

And here is what I an trying to do:

Foo fieldToRemove;
m_groupByFields.erase( std::remove_if( m_groupByFields.begin(), m_groupByFields.end(), 
                      [fieldName, fieldToRemove](Foo field) mutable
{
    if( field.fieldName == fieldName )
        fieldToRemove = field;
    return field.fieldName == fieldName;
}), m_groupByFields.end() );

Unfortunately after executing the fieldToRemove does not contain the proper data.

What am I missing? Is it even possible?

TIA!!

Aucun commentaire:

Enregistrer un commentaire