I would like to make a function that can take a function as a parameter, so that I can call the function with a specified lambda in the client code. Currently my code is this:
void Execute(float threshold,
void (*behaviour)(std::shared_ptr<cv::Mat>& image_i,
pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud_i,
const int* position, int index))
However this will not compile. using :
template <typename func>
void Execute(float threshold, func behaviour)
Will compile and work fine but I would like to constrain the client code to adhere to the function signature at compile time. I am using C++17.
Example client code:
caster.Execute(thresh,
[&](std::shared_ptr<cv::Mat>& image,
pcl::PointCloud<pcl::PointXYZ>::Ptr& cloud,
const int* position, int index) -> void {
pcl::PointXYZ origin(0, 0, 0);
float d = beam::distance(cloud->points[index], origin);
if (d > max_depth_) { max_depth_ = d; }
if (d < min_depth_) { min_depth_ = d; }
image->at<float>(position[0], position[1]) = d;
num_extracted++;
});
As you can see I would like to access variables num_extracted, min_depth_ and max_depth_ which are declared outside the scope of the lambda.