#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
void Print(int v)
{
cout << v << endl;
}
void Print(double v)
{
cout << v << endl;
}
template<typename FnT>
void Function(int v, FnT&& fn)
{
fn(v);
}
int main() {
Function(1, Print);
vector<int> v = { 1,2,3 };
for_each(v.begin(), v.end(), Print);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdm9pZCBQcmludChpbnQgdikKewogICAgY291dCA8PCB2IDw8IGVuZGw7Cn0KCnZvaWQgUHJpbnQoZG91YmxlIHYpCnsKICAgIGNvdXQgPDwgdiA8PCBlbmRsOwp9Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBGblQ+CnZvaWQgRnVuY3Rpb24oaW50IHYsIEZuVCYmIGZuKQp7CiAgICBmbih2KTsKfQoKaW50IG1haW4oKSB7CgogICAgRnVuY3Rpb24oMSwgUHJpbnQpOwoKCXZlY3RvcjxpbnQ+IHYgPSB7IDEsMiwzIH07CiAgICBmb3JfZWFjaCh2LmJlZ2luKCksIHYuZW5kKCksIFByaW50KTsKCglyZXR1cm4gMDsKfQ==
prog.cpp: In function ‘int main()’:
prog.cpp:24:22: error: no matching function for call to ‘Function(int, <unresolved overloaded function type>)’
Function(1, Print);
^
prog.cpp:17:6: note: candidate: template<class FnT> void Function(int, FnT&&)
void Function(int v, FnT&& fn)
^~~~~~~~
prog.cpp:17:6: note: template argument deduction/substitution failed:
prog.cpp:24:22: note: couldn't deduce template parameter ‘FnT’
Function(1, Print);
^
prog.cpp:27:39: error: no matching function for call to ‘for_each(std::vector<int>::iterator, std::vector<int>::iterator, <unresolved overloaded function type>)’
for_each(v.begin(), v.end(), Print);
^
In file included from /usr/include/c++/6/algorithm:62:0,
from prog.cpp:2:
/usr/include/c++/6/bits/stl_algo.h:3763:5: note: candidate: template<class _IIter, class _Funct> _Funct std::for_each(_IIter, _IIter, _Funct)
for_each(_InputIterator __first, _InputIterator __last, _Function __f)
^~~~~~~~
/usr/include/c++/6/bits/stl_algo.h:3763:5: note: template argument deduction/substitution failed:
prog.cpp:27:39: note: couldn't deduce template parameter ‘_Funct’
for_each(v.begin(), v.end(), Print);
^