Either there is something wrong with my C++ understanding, or there’s a hidden typo somewhere… I wasted hours on those few LOCs.
First, I defined a start()
method as such:
template <typename FunctionResult, typename ...FunctionArgs>
inline std::shared_ptr<StoppableThread> start(
std::function<FunctionResult(const bool&, FunctionArgs...)> function, FunctionArgs... args)
{ ... }
And also, some threadedSearch()
lambda function:
std::function<void(const bool&,
const Source&, Population&,
const std::vector<Parameter>&,
const size_t&, const size_t&)> threadedSearch = ... ;
But when I attempt to perform this:
Source source = { ... };
Population population = { ... };
const std::vector<Parameter> variationsParameters = { ... };
const size_t randomCandidatesCount = ..., lineageCount = ...;
auto searchThread = start(
threadedSearch,
source, population,
variationsParameters,
randomCandidatesCount, lineageCount);
The compiler disagrees with the latter call to starŧ()
, and tells me:
# with g++
error: no matching function for call to
‘start(std::function<void(const bool&, const Source&, Population&, const std::vector<Parameter>&, const long unsigned int&, const long unsigned int&)>&,
Source&, Population&, const std::vector<Parameter>&, const size_t&, const size_t&)’
[...]
note: candidate: ‘template<class FunctionResult, class ... FunctionArgs> std::shared_ptr<StoppableThread>
start(std::function<FunctionResult(const bool&, FunctionArgs ...)>, FunctionArgs ...)
note: template argument deduction/substitution failed:
note: inconsistent parameter pack deduction with ‘const Source&’ and ‘Source’
# with clang++
error: no matching member function for call to 'start'
note: candidate template ignored: deduced conflicting types for parameter 'FunctionArgs'
(<const Source&, Population&, const std::vector<Parameter>&, const unsigned long&, const unsigned long&>
vs.
<Source, Population, std::vector<Parameter>, size_t, size_t>)
My question is: WTF?