I'm fighting with the compiler and its ability to use automatic template deduction. The following does not compile, with a template automatic deduction failure:
template<typename Configuration, typename ConfigAlloc = std::allocator<Configuration>>
std::vector<Configuration, ConfigAlloc> ResamplePath(
const std::vector<Configuration, ConfigAlloc>& path,
const double resampled_state_distance,
const std::function<double(const Configuration&, const Configuration&)>& state_distance_fn,
const std::function<Configuration(const Configuration&, const Configuration&, const double)>& state_interpolation_fn)
{
...
}
void foo()
{
std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>> path;
...
const auto interpolation_fn = [&] (
const Eigen::Vector3d& prev,
const Eigen::Vector3d& curr,
const double ratio)
{
Eigen::Vector3d interpolated;
...
return interpolated;
};
auto resample_result = ResamplePath(path, ..., interpolation_fn);
}
If I change either the lambda declaration to
const std::function<Eigen::Vector3d(const Eigen::Vector3d&, const Eigen::Vector3d&, const double)> interpolation_fn = [&] (
const Eigen::Vector3d& prev,
const Eigen::Vector3d& curr,
const double ratio)
{
Eigen::Vector3d interpolated;
...
return interpolated;
};
or I change the function call to explicitly define the types
auto resample_result = ResamplePath<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d>>(
path, ..., interpolation_fn);
then everything compiles without any issues.
Is there something I'm missing that might allow autodeduction to work without explicitly defining the lambda type?
Edit: exact compile error
virtual_rubber_band.cpp: In member function ‘void smmap::VirtualRubberBand::resampleBand(bool)’:
virtual_rubber_band.cpp:279:111: error: no matching function for call to ‘ResamplePath(EigenHelpers::VectorVector3d&, const double&, const smmap::VirtualRubberBand::resampleBand(bool)::<lambda(const Vector3d&, const Vector3d&)>&, const smmap::VirtualRubberBand::resampleBand(bool)::<lambda(const Vector3d&, const Vector3d&, double)>&)’
band_, max_distance_between_rubber_band_points_, state_distance_fn, state_interpolation_fn);
In file included from virtual_rubber_band.cpp:3:0:
shortcut_smoothing.hpp:191:52: note: candidate: template<class Configuration, class ConfigAlloc> std::vector<_Tp, _Alloc> shortcut_smoothing::ResamplePath(const std::vector<_Tp, _Alloc>&, double, const std::function<double(const Datatype&, const Datatype&)>&, const std::function<Configuration(const Configuration&, const Configuration&, double)>&)
inline std::vector<Configuration, ConfigAlloc> ResamplePath(
^
shortcut_smoothing.hpp:191:52: note: template argument deduction/substitution failed:
virtual_rubber_band.cpp:279:111: note: ‘const smmap::VirtualRubberBand::resampleBand(bool)::<lambda(const Vector3d&, const Vector3d&)>’ is not derived from ‘const std::function<double(const Datatype&, const Datatype&)>’
band_, max_distance_between_rubber_band_points_, state_distance_fn, state_interpolation_fn);