I would like to understand how to use the Lambda functions in C++.
I'm using a custom types, as follows:
struct my_toy_t {
uint32_t id;
cv::Rect box;
cv::Mat data;
}
typedef std::map<uint32_t, my_toy_t*> my_toy_map_t;
And:
int main() {
my_toy_map_t input_map;
my_toy_map_t output_map;
// Some insertions in input_map...
my_toy_map_t::iterator it;
for (it = input_map.begin(); it != input_map.end(); ++it)
{
if (check_cond(it->second->box)) {
output_map.insert(std::make_pair(it->first, it->second));
input_map.erase(it->first);
}
}
return 0;
}
bool check_cond(cv::Rect box) {
if (box.area > 100)
return true;
else
return false;
}
It may be noted that my_toy_map_t
is just a std::map<uint32_t, my_toy_t*>
, and check_cond
function checks a simple condition.
Is it possible to translate this code (insertion in output map
and remotion from input_map
if check_cond
returns true
) using a Lamba function?