When writing generic functions for \"iterator\" ranges I usually do:
template auto func(Iter &first, Iter &last)
{
using IterTy
The second is the most idiomatic one.
None of these are quite idiomatic; you should be passing iterators by value, not by reference. Here's the signature for for_each in gcc 4.9:
template<typename _InputIterator, typename _Function>
_Function
for_each(_InputIterator __first, _InputIterator __last, _Function __f)
As you can see, it's passed by value. Your functions will not work in the idiomatic usage:
func(v.begin(), v.end()); // error, binding non-const ref to rvalue!
Also, going through iterator_traits is more than just idiomatic, it's basically required. Insofar as the STL is concerned, such typedefs are defined solely through iterator_traits: http://en.cppreference.com/w/cpp/concept/ForwardIterator. iterator_traits provides reasonable defaults for the generic case, but it can be specialized (as it is for pointers) to do different things. Not going through iterator_traits basically means someone could write a compliant iterator that worked with the STL but not your code.