template<typename T,typename function>
void for_each_ty(T first, T last, function f)
{
for (; first != last;first++)
{
f(*first);
}
}
void main()
{
std::vector<int> m_vc{ 1, 2, 3, 4, 5, 6 };
for_each_ty(m_vc.begin(), m_vc.end(), [](int x){cout << x << " "; });
cout << endl;
system("pause");
}
结果: